Hello, I am currently configuring an aws network w...
# general
b
Hello, I am currently configuring an aws network with pulumi. I have a question. I already have a subnet created. cidr crash when resource_name is changed. Is there any way to solve this?
Copy code
# example code
from pulumi import ResourceOptions
import pulumi_aws as aws

aws_vpc = aws.ec2.Vpc(
    'my-vpc',
    cidr_block    = '10.0.0.0/16',
    tags          = default_tags
    )

aws_public_subnet = aws.ec2.Subnet(
        resource_name     = 'public-subnet-change', # <= Originally a "public-subnet"
        vpc_id            = aws_vpc.id,
        cidr_block        = '10.0.1.0/24',
        availability_zone = 'ap-northeast-2a',
        tags              = default_tags,
        opts              = ResourceOptions(delete_before_replace=True)
    )
Do you want to perform this update? yes Updating (dev): Type Name Status Info pulumipulumiStack pulumi-demo-dev failed 1 error + └─ awsec2Subnet public-subnet-change creating failed 1 error Diagnostics: pulumipulumiStack (pulumi-demo-dev): error: update failed awsec2Subnet (public-subnet-change): error: 1 error occurred: * error creating EC2 Subnet: InvalidSubnet.Conflict: The CIDR ‘10.0.1.0/24’ conflicts with another subnet status code: 400, request id: *
b
yes, pick another subnet 🙂 you can't have two subnets with the same cidr
b
@billowy-army-68599 After creating a VPC and subnet through
pulumi up
with the code above, In the existing code, if the “resource_name” of the subnet is changed and then
pulumi up
is performed again, there seems to be a conflict.
b
you need to add a
deleteBeforeReplace
resource option: https://www.pulumi.com/docs/intro/concepts/resources/options/deletebeforereplace/