|
| 1 | +# Provision |
| 2 | +There's no way to do something like tofu.deploy() right now. |
| 3 | + |
| 4 | +This goes through two levels of abstractions?. JSII |
| 5 | + |
| 6 | +### CDKTF |
| 7 | +We write TerraformStack subclass and define our configration in init. It should something like this |
| 8 | +```python |
| 9 | +from cdktf import App, Fn, TerraformStack, TerraformVariable |
| 10 | +from cdktf_cdktf_provider_digitalocean.provider import DigitaloceanProvider |
| 11 | +from cdktf_cdktf_provider_digitalocean.vpc import Vpc |
| 12 | +from constructs import Construct |
| 13 | + |
| 14 | + |
| 15 | +class MyStack(TerraformStack): |
| 16 | + def __init__(self, scope: Construct, id: str): |
| 17 | + super().__init__(scope, id) |
| 18 | + do_token_variable = TerraformVariable(self,"do_token", type="string") |
| 19 | + DigitaloceanProvider(self, "digitalocean", token=do_token_variable.string_value) |
| 20 | + vpc = Vpc(self, "example_vpc", name="vpc-1", region="blr-1", ip_range="ip_range") |
| 21 | + |
| 22 | +``` |
| 23 | + |
| 24 | +Unfortunately, Pilot config isn't static. But good news is, this is actually implemented as following |
| 25 | + |
| 26 | +1. Define TerraformStack subclass, like we did before |
| 27 | +This is equivalent of writing a HCL file |
| 28 | + |
| 29 | +2. Define an app and call `synth` on it |
| 30 | + |
| 31 | +```python |
| 32 | +from cdktf import App, Fn, TerraformStack, TerraformVariable |
| 33 | + |
| 34 | + |
| 35 | +app = App() |
| 36 | +MyStack(app, "cdktf-demo") |
| 37 | +app.synth() |
| 38 | +``` |
| 39 | + |
| 40 | + |
| 41 | +3. Apply generated plan |
| 42 | +`cdktf deploy` |
| 43 | +We can open up the implemntation and see what happens underneath. |
| 44 | + |
| 45 | +1. If the implementation is complicated then we can run `cdktf deploy` ourselves |
| 46 | + |
| 47 | + |
| 48 | +--- |
| 49 | + |
| 50 | +We need to put some dynamic logic on Step 1. |
| 51 | +We can't write a class everytime. |
| 52 | +Generating Python code is basically the same as writing HCL |
| 53 | +What we can do is build a class implementation and app implementation on the fly |
0 commit comments