faint-elephant-30784
07/10/2024, 11:47 AMimport pulumi
import pulumi_aws as aws
from typing import Mapping, Sequence
class ExistingVPC:
def __init__(self, vpc_id: str, opts: pulumi.ResourceOptions = None):
super().__init__("cority:aws:net", vpc_id, None, opts)
# Variable Names
vpc_id = vpc_id
# Get the VPC details
vpc = aws.ec2.get_vpc(id=vpc_id)
# Get the Subnet Details of the VPC
subnets = aws.ec2.get_subnets(
filters=[
{
"name": "vpc-id",
"values": [vpc_id],
}
]
)
# Export subnet details
subnet_ids = []
for idx, subnet in enumerate(subnets.ids):
export_name = f"subnet_{idx}_id"
pulumi.export(export_name, subnet)
subnet_ids.append(subnet)
def get_subnet_value(idx):
return pulumi.output(subnet_ids[idx])
For argument's sake, I want to programmatically access the subnet_ids
value, so I've tried returning that from this class, for which I am declaring something in Pulumi called a component.
Using this I'm trying to access that output:
cnetworking = networking
vpc_information = cnetworking.ExistingVPC("vpc-id")
subnet_one = cnetworking.get_subnet_value(0)
But that's not right, and I can't figure out how to programmatically, without referencing stacks, get the output from resources being made in the same pulumi-up
run.
Any help would be greatly appreciated as it is slowing me down on this project.sparse-gold-10561
07/10/2024, 2:25 PMself.public_subnet_ids: Output[Sequence[str]] = Output.all(*[subnet.id for subnet in public_subnets])
self.private_subnet_ids: Output[Sequence[str]] = Output.all(*[subnet.id for subnet in private_subnets])
self.isolated_subnet_ids: Output[Sequence[str]] = Output.all(*[subnet.id for subnet in isolated_subnets])
faint-elephant-30784
07/10/2024, 2:26 PMoutput.all
do more than just subnets?faint-elephant-30784
07/10/2024, 2:26 PMfaint-elephant-30784
07/10/2024, 2:26 PMpulumi.export("vpc_id", vpc.id)
pulumi.export("vpc_cidr_block", vpc.cidr_block)
pulumi.export("vpc_enable_dns_support", vpc.enable_dns_support)
pulumi.export("vpc_enable_dns_hostnames", vpc.enable_dns_hostnames)
pulumi.export("vpc_default_network_acl_id", vpc.default_network_acl_id)
pulumi.export("vpc_default_route_table_id", vpc.default_route_table_id)
pulumi.export("vpc_main_route_table_id", vpc.main_route_table_id)
pulumi.export("vpc_default_security_group_id", vpc.default_security_group_id)
sparse-gold-10561
07/10/2024, 2:27 PMsparse-gold-10561
07/10/2024, 2:28 PMsparse-gold-10561
07/10/2024, 2:30 PMfaint-elephant-30784
07/10/2024, 2:30 PMsparse-gold-10561
07/10/2024, 2:34 PMpulumi.Output.all(
public_subnets=vpc.public_subnet_ids,
private_sunets=vpc.private_subnet_ids,
).apply(
lambda args: share_prod_vpc_to_prod_accounts(
public_subnets=args['public_subnets'],
private_subnets=args['private_subnets'],
)
)
faint-elephant-30784
07/10/2024, 2:36 PMfaint-elephant-30784
07/10/2024, 2:37 PMsparse-gold-10561
07/10/2024, 2:38 PMfaint-elephant-30784
07/10/2024, 2:38 PMfaint-elephant-30784
07/10/2024, 2:38 PMfaint-elephant-30784
07/10/2024, 2:38 PMsparse-gold-10561
07/10/2024, 2:39 PMsparse-gold-10561
07/10/2024, 2:39 PMfaint-elephant-30784
07/10/2024, 2:40 PMfaint-elephant-30784
07/10/2024, 2:40 PMfaint-elephant-30784
07/10/2024, 2:41 PMsparse-gold-10561
07/10/2024, 2:43 PMemail_bucket = aws.s3.BucketV2(
f"{product_name}_emails_bucket",
bucket=f"{product_name}-emails".replace("_", "-"),
force_destroy=True,
)
email_bucket_policy = aws.s3.BucketPolicy(
f"{product_name}_email_bucket_policy",
bucket=email_bucket.id,
policy=pulumi.Output.all(email_bucket=email_bucket.arn).apply(
lambda args: json.dumps(
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {"Service": "ses.amazonaws.com"},
"Action": "s3:PutObject",
"Resource": [
f"{args['email_bucket']}/*",
],
"Condition": {"StringEquals": {"aws:Referer": aws_account_id}},
}
],
}
)
),
)
sparse-gold-10561
07/10/2024, 2:44 PM