1

TL;DR. I would like to ready output from previous stack in newer one with local Pulumi stack saving. For example to create a AWS Fargate ECS cluster in previously created VPC/Subnets. How to do that in Python?

I've created dev Pulumi stack, applied code:

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

And got such 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
...

As you can see here I am using local stack placement /root/.pulumi/stacks/dev.json. So far so good. Now in other dir I would like to create fargate cluster description:

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

And here I need to read previously created pulumi-private-subnet-ids, pulumi-public-subnet-ids, pulumi-vpc-id output values? How to do that correct?

I've found only https://app.pulumi.com backend examples:
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/

Could anybody provide local or AWS s3 example how to read output in other stack/dir?

ipeacocks
  • 2,187
  • 3
  • 32
  • 47

1 Answers1

1

Ok, reading local state outputs is also possible. Login and create first stack:

$ pulumi logout
$ pulumi login --local

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

$ pulumi stack init pulumi-infra-az-dev

Apply it:

$ 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
...

Now create new dir and stack:

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

$ pulumi stack init pulumi-ecs-fargate-dev

Stacks name should be diffent. And than read outputs in new one:

...
# 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")
...

Very sad that Pulumi doesn't have good manuals/examples.

ipeacocks
  • 2,187
  • 3
  • 32
  • 47
  • 1
    Maybe it's been newly added to the docs https://www.pulumi.com/docs/intro/concepts/organizing-stacks-projects/#inter-stack-dependencies – Can Rau Jun 08 '20 at 02:09
  • 1
    Uh and you could mark your answers as solved for others to easier find unanswered questions – Can Rau Jun 08 '20 at 02:11
  • Unfortunately there is only example with their own backend app.pulumi.com. It's quite hard to understand which path needs to be for local/s3 stack. For example with pulumi backend your full stack name is with slashes like `this/is/my/stack` but you can't use slashes with s3/local/etc stacks. – ipeacocks Jun 08 '20 at 21:01
  • I see yea that's true. This works quite good so far https://github.com/pulumi/pulumi/issues/2522#issuecomment-593088942 I have 1 infra and 1 service project which gets stuff via `const infra = new pulumi.StackReference(`infra.${env}`)` following the example from the issue comment using `file://../`. I'm actually planning to make a video about how I manage a contact form api with Pulumi, not sure how long it'll take though^^ – Can Rau Jun 09 '20 at 22:19