You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since this was a Python project, Pulumi generated a Python SDK for the modules, making those available to use as `pulumi_vpcmod` and `pulumi_rdsmod` respectively. We can now use the Terraform modules directly in our code:
216
+
217
+
```python
218
+
import pulumi
219
+
import pulumi_aws as aws
220
+
import pulumi_vpcmod as vpcmod
221
+
import pulumi_rdsmod as rdsmod
222
+
import pulumi_std as std
223
+
224
+
# Get available availability zones
225
+
azs = aws.get_availability_zones_output(
226
+
filters=[{
227
+
"name": "opt-in-status",
228
+
"values": ["opt-in-not-required"],
229
+
}]
230
+
).names.apply(lambdanames: names[:3])
231
+
232
+
cidr ="10.0.0.0/16"
233
+
234
+
cfg = pulumi.Config()
235
+
prefix = cfg.get("prefix") or pulumi.get_stack()
236
+
237
+
# Utility function to calculate subnet CIDRs
238
+
defget_cidr_subnet(cidr, netnum):
239
+
return std.cidrsubnet_output(
240
+
input=cidr,
241
+
newbits=8,
242
+
netnum=netnum
243
+
).result
244
+
245
+
# Create a VPC using the terraform-aws-modules/vpc module
246
+
vpc = vpcmod.Module("test-vpc",
247
+
azs=azs,
248
+
name=f"test-vpc-{prefix}",
249
+
cidr=cidr,
250
+
public_subnets=azs.apply(lambdaazs: [get_cidr_subnet(cidr, i+1) for i inrange(len(azs))]),
251
+
private_subnets=azs.apply(lambdaazs: [get_cidr_subnet(cidr, i+1+4) for i inrange(len(azs))]),
252
+
database_subnets=azs.apply(lambdaazs: [get_cidr_subnet(cidr, i+1+8) for i inrange(len(azs))]),
When authoring in YAML, there's no need for Pulumi to generate a SDK. In the YAML you can reference the Terraform module by its schema token, which takes the format `<module-name>:index:Module`:
0 commit comments