Hi everyone, I am trying to get a string represent...
# general
r
Hi everyone, I am trying to get a string representation of the object for an resource that I am generating. For example, I am creating a VPC here
Copy code
resource_vpc = aws.ec2.Vpc(
    resource_name=vars['vpc_name'],
    cidr_block=vars['cidr'],
    enable_classiclink_dns_support=True,
    enable_dns_hostnames=True,
    assign_generated_ipv6_cidr_block=True,
    tags={
        "Name": vars['vpc_name'],
    }
)
and then would like to use the
resource_vpc.ipv6_cidr_block
attribute to assign IPv6 CIDRs to subnets. However, the representation of this attribute is required as string to the network IPNetwork function I am using to create IPv6 Subnets… Any idea how I can obtain the string value? Thanks in advance
b
you would need to do it inside an apply. This is a good example of doing something similar: https://github.com/jen20/pulumi-aws-vpc/tree/master/python/jen20_pulumi_aws_vpc
the difference here is you'll need to do the subnet distributor function inside an apply
r
thanks @billowy-army-68599 I just got it working this way…
Copy code
get_vpc = aws.ec2.get_vpc(id=resource_vpc.id)
ipv6_network = IPNetwork(get_vpc.ipv6_cidr_block)
ipv6_subnets = list(ipv6_network.subnet(64))
and then for subnets i am doing this
Copy code
for idx, name in enumerate(subnet_names):
    aws.ec2.Subnet(
    resource_name=name,
    vpc_id=resource_vpc.id,
    cidr_block=str(ipv4_subnets[idx]),
    availability_zone_id=az.zone_ids[idx],
    ipv6_cidr_block=str(ipv6_subnets[idx]),
    tags={
        "Name": name,
    })
looks like i am hitting a race condition in this case when I am deploying the whole stack from scratch… The get_vpc is failing to get the attributes of the vpc that is being created as part of the stack… when i run the code it in stages i.e. create the vpc first then the get_vpc and then subnets…it works fine however, the whole stack as one go isnt working… I have tried to use
depends_on
but no luck…
vpc_info = aws.ec2.get_vpc(id=resource_vpc.id, opts=ResourceOptions(depends_on=[resource_vpc]))
any suggestion?