使用 Pulumi 获取私有子网 ID

问题描述

我正在尝试使用 Pulumi 创建一个新的 EKS 集群。在其中一个步骤中,我需要使用私有子网 ID。 当我尝试使用 VPCID 获取 ID 时,出现错误

TSError: ⨯ Unable to compile TypeScript:
index.ts(9,2): error TS2322: Type 'Output<string>' is not assignable to type 'string'.

这就是我想要做

import * as pulumi from "@pulumi/pulumi";
import * as awsx from "@pulumi/awsx";
import * as eks from "@pulumi/eks";
import * as k8s from "@pulumi/kubernetes";
import * as aws from "@pulumi/aws";

const vpc = aws.ec2.Vpc.get('ais-name','vpc-er33332');
const privatesubnet = aws.ec2.getsubnetIds({
    vpcId: vpc.id,});

是我做错了,还是有其他方法可以做到这一点? 提前非常感谢

解决方法

您可以使用 vpc.id 上的 apply 来实现:

const vpc = aws.ec2.Vpc.get('ais-name','vpc-er33332');

const privateSubnet = vpc.id.apply(
    vpcId => aws.ec2.getSubnetIds({
        vpcId: vpcId,})
);