pulumi / pulumi-yaml

YAML language provider for Pulumi
Apache License 2.0
38 stars 11 forks source link

Getting existing VPC does not work as expected #457

Open catmeme opened 1 year ago

catmeme commented 1 year ago

What happened?

When attempting to get an existing VPC, either a new VPC gets created or types mismatch.

Expected Behavior

I should be able to get an existing VPC and use it in the plan as if it were created in that plan.

Steps to reproduce

name: catmeme-yaml
runtime: yaml
description: A reproducible test case

config:
  sharedInfrastructureStackName:
    type: string

variables:
  vpcId: ${shared-infrastructure.outputs["vpcId"]} 

resources:
  shared-infrastructure:
    type: pulumi:pulumi:StackReference
    properties:
      name: ${sharedInfrastructureStackName}

  shared-vpc:
    type: aws:ec2/vpc:Vpc
    get:
      # This fails as a stack reference
      id: ${vpcId}
      # id: vpc-07b89b6ab4bf305d1 # this "works" but creates a new VPC

  appSecurityGroup:
    type: aws:ec2/securityGroup:SecurityGroup
    properties:
      egress:
        - fromPort: 0
          toPort: 0
          protocol: "-1"
          cidrBlocks:
            - "0.0.0.0/0"
      vpcId: ${shared-vpc.id}
    error: get.id must be a prompt string, instead got type pulumi.AnyOutput

      on Pulumi.yaml line 41:
      41:       id: ${vpcId}
    error: Error registering resource [shared-vpc]: no diagnostics

If I run pulumi convert, it shows re-declarations, and the id isn't used.

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const config = new pulumi.Config();
const sharedInfrastructureStackName = config.require("sharedInfrastructureStackName");
const sharedInfrastructure = new pulumi.StackReference("shared-infrastructure", {name: sharedInfrastructureStackName});
const vpcId = sharedInfrastructure.outputs.vpcId;
const sharedVpc = new aws.ec2.Vpc("shared-vpc", {});
const appSecurityGroup = new aws.ec2.SecurityGroup("appSecurityGroup", {
    egress: [{
        fromPort: 0,
        toPort: 0,
        protocol: "-1",
        cidrBlocks: ["0.0.0.0/0"],
    }],
    vpcId: sharedVpc.id,
});

I have attempted to use the getVpc function as well, but I'm not sure how to integrate it with the other resources:

variables:
 vpc:
    fn::invoke:
      function: aws:ec2/getVpc:getVpc
      arguments:
        id: ${vpcId}

Output of pulumi about

CLI          
Version      3.66.0
Go Version   go1.20.4
Go Compiler  gc

Plugins
NAME  VERSION
yaml  unknown

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

justinvp commented 1 year ago

Thanks for opening the issue and sorry for the trouble!