2

I'm trying to use Pulumi within a somewhat restricted AWS environment.

This sandbox requires that I use a specific VPC, and there is no default VPC.

I have tried the examples showing how to reference an existing VPC, but they all fail with some variant of "invoking aws:ec2/getVpc:getVpc: no matching VPC found"

@pulumi/awsx, using code referenced from: https://github.com/pulumi/pulumi-awsx/issues/522:

const vpc = awsx.ec2.Vpc.fromExistingIds('name', {
  vpcId: 'id',
  publicSubnetIds: ['a', 'b'],
  privateSubnetIds: ['a', 'b']
})

@pulumi/aws, using code referenced from https://www.pulumi.com/docs/reference/pkg/aws/ec2/getvpc/:

const vpc = aws.ec2.Vpc.get('vpc-1', 'vpc-1')

Question: what is the correct and complete syntax for referencing an existing VPC within a Pulumi stack?

Note that I would rather not "adopt" this resource as it is shared and the user running the pulumi up command does not have permission to delete VPC resources.

4

3 回答 3

1

这最终奏效了:

const vpc = aws.ec2.Vpc.get('vpc-123', 'vpc-123')

pulumi up在进行上述更改之后,我认为我没有正确保存我的文件。

请注意,我还必须手动将子网添加到我的 ALB 以使其正常工作,如下所示:

const vpc = aws.ec2.Vpc.get('vpc-123', 'vpc-123')

const clusterName = nameResource('graphQlServiceCluster')
const ecsCluster = new awsx.ecs.Cluster(clusterName, {
  name: clusterName,
  vpc
})

const PublicSubnet1a = 'subnet-123'
const PublicSubnet1b = 'subnet-123'

const alb = new awsx.lb.ApplicationLoadBalancer(nameResource('graphQlServiceElb'), {
  name: nameResource('graphQlServiceElb'),
  external: true,
  vpc,
  subnets: [
    PublicSubnet1a,
    PublicSubnet1b

  ]
})
const listener = alb.createListener(nameResource('graphqlServiceListener'), {
  name: nameResource('graphqlServiceListener'),
  port: 80,
  external: true,
  vpc
})
于 2020-07-01T20:25:24.347 回答
1

普鲁米有多种Vpc类型。您可能希望使用awsx更高级别的 VPC(并且需要使用其他 awsx 基础架构)。

有两种方法可以做到这一点:

创建新的 VPC

const vpc = new awsx.ec2.Vpc(config.vpcName, {
  cidrBlock: "10.0.0.0/16",
  subnets: [
    {
      name: "public",
      type: "public",
      location: {
        cidrBlock: "10.0.0.0/24",
        availabilityZone: "us-east-2a",
      },
    },
    {
      name: "private-a",
      type: "private",
      location: {
        cidrBlock: "10.0.1.0/24",
        availabilityZone: "us-east-2a",
      },
    },
    {
      name: "private-b",
      type: "private",
      location: {
        cidrBlock: "10.0.2.0/24",
        availabilityZone: "us-east-2b",
      },
    },
  ],
});

使用现有 VPC

从Pulumi CTO的这个GitHub 线程中借用产生了正确的结果:

  const vpc = awsx.ec2.Vpc.fromExistingIds("mycompany", {
    vpcId: "vpc-myvpcid",
  });

  // Create an ECS Fargate cluster.
  const ecsCluster = new awsx.ecs.Cluster("mycompany-pulumi-cluster", {
    vpc,
  });
于 2021-06-11T11:21:53.470 回答
1

getVpc()您链接到的和Vpc.get()您尝试使用的之间存在细微差别。你应该使用前者:

const vpc = aws.ec2.getVpc({ id: yourVpcId });
于 2020-06-29T05:51:48.210 回答