1

TL;博士。我想通过本地 Pulumi 堆栈保存将先前堆栈的输出准备在较新的堆栈中。例如,在之前创建的 VPC/子网中创建 AWS Fargate ECS 集群。如何在 Python 中做到这一点?

我创建了devPulumi 堆栈,应用代码:

$ mkdir pulumi-infra-az
$ pulumi login --local
$ pulumi stack init dev

得到了这样的Outputs

...
Outputs:
    pulumi-private-subnet-ids: [
        [0]: "subnet-0dcbaabe273db8feb"
        [1]: "subnet-08c63207611c6bae2"
        [2]: "subnet-00fa346a71a323551"
    ]
    pulumi-public-subnet-ids : [
        [0]: "subnet-02c50846690f2cd70"
        [1]: "subnet-06282506863db7ac1"
        [2]: "subnet-0cfae8a4f5e4fc03c"
    ]
    pulumi-vpc-id            : "vpc-0767f0d49e3a59d42"

Resources:
    ~ 3 updated
    22 unchanged

Duration: 10s

Permalink: file:///root/.pulumi/stacks/dev.json
...

正如您在此处看到的,我正在使用本地堆栈放置/root/.pulumi/stacks/dev.json。到目前为止,一切都很好。现在在其他目录中,我想创建 fargate 集群描述:

$ mkdir pulumi-ecs-fargate
$ pulumi stack init dev-ecs # by the way can I use the same `dev` stack name here?

在这里我需要阅读以前创建pulumi-private-subnet-ids的 , pulumi-public-subnet-ids,pulumi-vpc-id输出值?如何正确地做到这一点?

我只找到了https://app.pulumi.com后端示例:
https
://www.pulumi.com/docs/intro/concepts/organizing-stacks-projects/#inter-stack-dependencies https://www .pulumi.com/docs/intro/concepts/programming-model/#stack-references
https://www.pulumi.com/docs/tutorials/aws/aws-py-stackreference/

任何人都可以提供本地或 AWS s3 示例如何读取其他堆栈/目录中的输出吗?

4

1 回答 1

1

好的,也可以读取本地状态输出。登录并创建第一个堆栈:

$ pulumi logout
$ pulumi login --local

$ mkdrir pulumi-infra-az
$ cd pulumi-infra-az

$ pulumi stack init pulumi-infra-az-dev

应用它:

$ pulumi up
...
Outputs:
    pulumi-private-subnet-ids: [
        [0]: "subnet-0e8eb4cd276720a51"
        [1]: "subnet-0447d96727f6fdf62"
        [2]: "subnet-02e0e1d44183f7733"
    ]
    pulumi-public-subnet-ids : [
        [0]: "subnet-00b1c052633b93f73"
        [1]: "subnet-0333dd2abc409acb7"
        [2]: "subnet-006e949371228f8bd"
    ]
    pulumi-vpc-id            : "vpc-0e59fc2d7df06bac0"

Resources:
    + 25 created
...

现在创建新的目录和堆栈:

$ mkdir pulumi-ecs-fargate
$ cd pulumi-ecs-fargate

$ pulumi stack init pulumi-ecs-fargate-dev

堆栈名称应该不同。而不是读取新的输出:

...
# Reading local state
infra = pulumi.StackReference(f"pulumi-infra-az-dev")

# Read back the default VPC and public subnets, which we will use.
pulumi_vpc = infra.get_output("pulumi-vpc-id")
pulumi_private_subnets = infra.get_output("pulumi-private-subnet-ids")
pulumi_public_subnets = infra.get_output("pulumi-public-subnet-ids")
...

很遗憾 Pulumi 没有好的手册/示例。

于 2020-04-25T17:34:51.600 回答