https://pulumi.com logo
#python
Title
# python
g

great-sunset-355

12/22/2021, 9:37 AM
Is the only option to create VPC endpoints within
apply()
when using this code?
Copy code
# vpc endpoints
        vpc_endpoints = ["s3", "ecr.dkr", "ecr.api", "logs"]
        region_output = self._config.aws_provider.region
        for endpoint in vpc_endpoints:
        
            service_name = region_output.apply(
                        lambda region: f"com.amazonaws.{region}.{endpoint}"  # endpoint here does not update from the loop variable
                    )
            pulumi_aws.ec2.VpcEndpoint(
                f"{self._config.name}-{endpoint}-vpc-endpoint",
                args=pulumi_aws.ec2.VpcEndpointArgs(
                    service_name=service_name,
                    vpc_id=self.vpc.id,
                    tags=self._config.tags,
                ),
                opts=self._opts,
            )
b

billowy-army-68599

12/22/2021, 9:40 AM
you shouldn't need to use an apply because you're passing outputs (vpc.id) from the vpc object
the apply you have there looks to be resolving the region, how are you populating that?
g

great-sunset-355

12/22/2021, 9:41 AM
vpc.id
is not a problem, the problem comes from the
region
assigned in
svc = ...
I edited the code, hopefully makes it more readable
The problem is that the service name is always the last item from the
vpc_endpoints
list
serviceName: "com.amazonaws.eu-central-1.s3" => "com.amazonaws.eu-central-1.logs"
okay, cool I solved it using
Outpu.concat
instead of the
apply
it is way less readable but it works
Thank you @billowy-army-68599 you are a legend!
3 Views