【问题标题】:Pulumi create instance in existing subnetPulumi 在现有子网中创建实例
【发布时间】:2021-06-07 09:50:13
【问题描述】:

我正在尝试从自定义 vpc 创建 EC2 实例。我有 vpc 作为输出。但我想分配给字符串。非常感谢您在这方面的帮助。

选项 1:

const vpcId = args.network.vpc.id.apply(id => id); //type Output<string>; network extends awsx:Vpc
const mySubnet = aws.ec2.gtSubnet({
  availabilityZone: 'ap-southeast-2a',
  filters: [
    { name: "tag:Name", values: ["*private-0"]}
  ],
  vpcId: vpcId; //Error: Type 'Output<string>' is not assignable to type 'string'
});
this.vm = new aws.ec2.Instance("ec2Instance", {
  ami: amiId,
  instanceType: instanceClass,
  networkInterfaces: [{
    networkInterfaceId: networkInterface.id,
    deviceIndex: 0,
  }]
});

选项 2:

const sg = new awsx.ec2.SecurityGroup("webserver-sg", { vpc }); //Here again I need vpcid string in the SecurityGroupArgs

【问题讨论】:

标签: pulumi


【解决方案1】:

Output&lt;T&gt;promise, also called a future。这是一个尚不可用的值。它将在 Pulumi 引擎开始执行时可用。您可以传递一个回调,该回调将在值可用时运行(并且您将立即为回调的新的、尚不可用的返回值获得一个新的承诺),或者您可以将它传递给将接受的方法承诺(这些通常需要Input&lt;T&gt;)。

很遗憾,getSubnet(目前)不接受InputPromise,所以选项#2 不可用。

你可以做的是:

const mySubnetId = args.network.vpc.id.apply(id => {
  const getSubnetResult = aws.ec2.getSubnet({
     vpcId: id;
  })
  return getSubnetResult.id
})

这会给你一个Output&lt;string&gt;,你可以将它传递给new Instance({subnetId: ...}),因为它接受Input&lt;string&gt;

【讨论】:

    猜你喜欢
    • 2020-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-29
    • 2020-11-30
    • 1970-01-01
    • 2016-08-18
    • 1970-01-01
    相关资源
    最近更新 更多