broad-holiday-50009
01/25/2023, 10:20 PMminiature-musician-31262
01/25/2023, 10:22 PMfor
loop? Like given some value like 3
obtained from somewhere, like stack configuration, generate 3 subnets?import pulumi
from pulumi_aws import s3
config = pulumi.Config()
buckets = config.get_int("buckets", 3)
for i in range(0, buckets):
bucket = s3.Bucket(f"bucket-{i}")
broad-holiday-50009
01/25/2023, 10:32 PMminiature-musician-31262
01/25/2023, 10:33 PMsubnets aren’t an s3 thing thoughYes, was just for illustration. Subnets would be defined similarly — lemme see.
import pulumi
from pulumi_aws import ec2
config = pulumi.Config()
subnets = config.get_int("subnets", 3)
vpc = ec2.Vpc("vpc", cidr_block="10.0.0.0/16")
for i in range(0, subnets):
subnet = ec2.Subnet(f"subnet-{i}",
vpc_id=vpc.id,
cidr_block=f"10.0.{i + 1}.0/24")
Updating (dev)
Type Name Status
+ pulumi:pulumi:Stack 2021-01-25-python-loop-dev created (0.25s)
+ ├─ aws:ec2:Vpc vpc created (2s)
+ ├─ aws:ec2:Subnet subnet-0 created (1s)
+ ├─ aws:ec2:Subnet subnet-1 created (1s)
+ └─ aws:ec2:Subnet subnet-2 created (1s)
Resources:
+ 5 created
broad-holiday-50009
01/25/2023, 10:46 PMminiature-musician-31262
01/25/2023, 10:47 PMcount
property or something defined on the resource itself. Pulumi is different in that you use the language to define those kinds of constructs — if
conditionals, loops, things like that.broad-holiday-50009
01/25/2023, 10:50 PMminiature-musician-31262
01/25/2023, 10:54 PMbroad-holiday-50009
01/25/2023, 10:55 PMminiature-musician-31262
01/25/2023, 10:56 PMbroad-holiday-50009
01/25/2023, 10:57 PMminiature-musician-31262
01/25/2023, 10:58 PMPulumi.yaml
, do you have
runtime:
name: python
options:
virtualenv: venv
?pulumi new aws-python
, if that helps.broad-holiday-50009
01/25/2023, 10:59 PMstrong-helmet-83704
01/25/2023, 11:30 PMbroad-holiday-50009
01/25/2023, 11:35 PMmany-telephone-49025
01/26/2023, 3:44 PMUntil a year ago I was the average sysadmin and I had no reason to code now I want to start making real money and not see my job die out👆 This! Great statement and I try to encourage and help people to move learning development and development principals to solve the new Ops-challanges! If I can help you, let me know @broad-holiday-50009!
broad-holiday-50009
01/26/2023, 4:26 PMstrong-helmet-83704
01/26/2023, 7:13 PMgreat-sunset-355
01/30/2023, 5:24 PMif
statement for conditional resources in the same was as terraform count
(hack).
With terraform count
you can make 1 resource dependent on the existence of another resource. This is not possible with pulumi and simple if
because the resources are executed asynchronously.