Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Component children of component resources don't inherit their parents providers #10640

Closed
jaxxstorm opened this issue Jul 24, 2022 · 8 comments · Fixed by #10933
Closed

Component children of component resources don't inherit their parents providers #10640

jaxxstorm opened this issue Jul 24, 2022 · 8 comments · Fixed by #10933
Assignees
Labels
area/component-packages aka multi-language components kind/bug Some behavior is incorrect or out of spec resolution/fixed This issue was fixed
Milestone

Comments

@jaxxstorm
Copy link
Contributor

jaxxstorm commented Jul 24, 2022

What happened?

I defined a VPC inside a Component resource, and parented the VPC to the wrapping component.

The resource provider has a defined AWS account and allowed account id.

The VPC was created in the account I had set in my aws environment, not in the account I expected with the explicit resource provider.

Steps to reproduce

Create a Component Resource like so:

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

export interface MyVpcArgs {
  cidrBlock: string;
}

export class MyVpc extends pulumi.ComponentResource {
  vpc: awsx.ec2.Vpc;
  //classicVpc: classic.ec2.Vpc;

  constructor(
    name: string,
    args: MyVpcArgs,
    opts?: pulumi.ComponentResourceOptions
  ) {
    super("jaxxstorm:index:myvpc", name, {}, opts);

    this.vpc = new awsx.ec2.Vpc(
      name,
      {
        cidrBlock: args.cidrBlock,
        subnetSpecs: [
          {
            type: "Public",
            cidrMask: 26,
          },
          {
            type: "Isolated",
            cidrMask: 26,
          },
          {
            type: "Private",
            cidrMask: 24,
          },
        ],
        natGateways: {
          strategy: "OnePerAz",
        },
        tags: {
          Name: name,
        },
      },
      { parent: this } // note the parent here
    );
  }
}

Then instantiate it via a provider:

const provider = new aws.Provider("shared", {
    profile: "personal-shared_servces",
    allowedAccountIds: ["587571862190"],
})

const vpc = new myvpc.MyVpc("example", {
    cidrBlock: "172.20.0.0/20",
}, { provider: provider })

Note the allowedAccountIds and the profile I've selected.

Now, ensure your AWS credentials locally do not match the profile:

aws sts get-caller-identity
{
    "UserId": "AROAYHKMQGUTOXWO3QUHN:lee@brig.gs",
    "Account": "565485516070",
    "Arn": "arn:aws:sts::565485516070:assumed-role/AWSReservedSSO_AWSAdministratorAccess_ee5a9f50a5aa44de/lee@brig.gs"
}

Now provision your Pulumi program, see where the resources get created

Expected Behavior

The resources should be provisioned in the account defined by the resource provider

Actual Behavior

The resources are not provisioned in the correct account

Versions used

CLI          
Version      3.36.0
Go Version   go1.18.4
Go Compiler  gc

Plugins
NAME    VERSION
aws     5.10.0
awsx    1.0.0-beta.9
docker  3.2.0
nodejs  unknown

Host     
OS       darwin
Version  12.4
Arch     arm64

This project is written in nodejs: executable='/opt/homebrew/bin/node' version='v18.6.0'

Current Stack: dev

TYPE                                                 URN
pulumi:pulumi:Stack                                  urn:pulumi:dev::awsx_repro::pulumi:pulumi:Stack::awsx_repro-dev
jaxxstorm:index:myvpc                                urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc::example
pulumi:providers:aws                                 urn:pulumi:dev::awsx_repro::pulumi:providers:aws::shared
pulumi:providers:awsx                                urn:pulumi:dev::awsx_repro::pulumi:providers:awsx::default_1_0_0_beta_9
awsx:ec2:Vpc                                         urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc::example
pulumi:providers:aws                                 urn:pulumi:dev::awsx_repro::pulumi:providers:aws::default_5_4_0
aws:ec2/vpc:Vpc                                      urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc::example
aws:ec2/subnet:Subnet                                urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet::example-private-1
aws:ec2/subnet:Subnet                                urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet::example-isolated-3
aws:ec2/internetGateway:InternetGateway              urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/internetGateway:InternetGateway::example
aws:ec2/subnet:Subnet                                urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet::example-isolated-1
aws:ec2/subnet:Subnet                                urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet::example-isolated-2
aws:ec2/subnet:Subnet                                urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet::example-private-3
aws:ec2/subnet:Subnet                                urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet::example-private-2
aws:ec2/routeTable:RouteTable                        urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet$aws:ec2/routeTable:RouteTable::example-private-1
aws:ec2/routeTable:RouteTable                        urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet$aws:ec2/routeTable:RouteTable::example-isolated-3
aws:ec2/routeTable:RouteTable                        urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet$aws:ec2/routeTable:RouteTable::example-isolated-1
aws:ec2/routeTable:RouteTable                        urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet$aws:ec2/routeTable:RouteTable::example-isolated-2
aws:ec2/routeTable:RouteTable                        urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet$aws:ec2/routeTable:RouteTable::example-private-3
aws:ec2/routeTable:RouteTable                        urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet$aws:ec2/routeTable:RouteTable::example-private-2
aws:ec2/routeTableAssociation:RouteTableAssociation  urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet$aws:ec2/routeTable:RouteTable$aws:ec2/routeTableAssociation:RouteTableAssociation::example-private-1
aws:ec2/routeTableAssociation:RouteTableAssociation  urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet$aws:ec2/routeTable:RouteTable$aws:ec2/routeTableAssociation:RouteTableAssociation::example-isolated-1
aws:ec2/routeTableAssociation:RouteTableAssociation  urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet$aws:ec2/routeTable:RouteTable$aws:ec2/routeTableAssociation:RouteTableAssociation::example-isolated-3
aws:ec2/routeTableAssociation:RouteTableAssociation  urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet$aws:ec2/routeTable:RouteTable$aws:ec2/routeTableAssociation:RouteTableAssociation::example-isolated-2
aws:ec2/routeTableAssociation:RouteTableAssociation  urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet$aws:ec2/routeTable:RouteTable$aws:ec2/routeTableAssociation:RouteTableAssociation::example-private-3
aws:ec2/routeTableAssociation:RouteTableAssociation  urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet$aws:ec2/routeTable:RouteTable$aws:ec2/routeTableAssociation:RouteTableAssociation::example-private-2
aws:ec2/subnet:Subnet                                urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet::example-public-1
aws:ec2/subnet:Subnet                                urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet::example-public-2
aws:ec2/subnet:Subnet                                urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet::example-public-3
aws:ec2/routeTable:RouteTable                        urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet$aws:ec2/routeTable:RouteTable::example-public-1
aws:ec2/eip:Eip                                      urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet$aws:ec2/eip:Eip::example-1
aws:ec2/routeTable:RouteTable                        urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet$aws:ec2/routeTable:RouteTable::example-public-2
aws:ec2/eip:Eip                                      urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet$aws:ec2/eip:Eip::example-2
aws:ec2/eip:Eip                                      urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet$aws:ec2/eip:Eip::example-3
aws:ec2/routeTable:RouteTable                        urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet$aws:ec2/routeTable:RouteTable::example-public-3
aws:ec2/routeTableAssociation:RouteTableAssociation  urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet$aws:ec2/routeTable:RouteTable$aws:ec2/routeTableAssociation:RouteTableAssociation::example-public-1
aws:ec2/route:Route                                  urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet$aws:ec2/routeTable:RouteTable$aws:ec2/route:Route::example-public-1
aws:ec2/routeTableAssociation:RouteTableAssociation  urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet$aws:ec2/routeTable:RouteTable$aws:ec2/routeTableAssociation:RouteTableAssociation::example-public-2
aws:ec2/route:Route                                  urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet$aws:ec2/routeTable:RouteTable$aws:ec2/route:Route::example-public-2
aws:ec2/natGateway:NatGateway                        urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet$aws:ec2/natGateway:NatGateway::example-1
aws:ec2/routeTableAssociation:RouteTableAssociation  urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet$aws:ec2/routeTable:RouteTable$aws:ec2/routeTableAssociation:RouteTableAssociation::example-public-3
aws:ec2/natGateway:NatGateway                        urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet$aws:ec2/natGateway:NatGateway::example-3
aws:ec2/route:Route                                  urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet$aws:ec2/routeTable:RouteTable$aws:ec2/route:Route::example-private-3
aws:ec2/route:Route                                  urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet$aws:ec2/routeTable:RouteTable$aws:ec2/route:Route::example-public-3
aws:ec2/route:Route                                  urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet$aws:ec2/routeTable:RouteTable$aws:ec2/route:Route::example-private-1
aws:ec2/natGateway:NatGateway                        urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet$aws:ec2/natGateway:NatGateway::example-2
aws:ec2/route:Route                                  urn:pulumi:dev::awsx_repro::jaxxstorm:index:myvpc$awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet$aws:ec2/routeTable:RouteTable$aws:ec2/route:Route::example-private-2
pulumi:providers:pulumi                              urn:pulumi:dev::awsx_repro::pulumi:providers:pulumi::default


Found no pending operations associated with dev

Backend        
Name           pulumi.com
URL            https://app.pulumi.com/jaxxstorm
User           jaxxstorm
Organizations  jaxxstorm, lbrlabs, team-ce, demo, pulumi

Dependencies:
NAME            VERSION
@pulumi/aws     5.10.0
@pulumi/awsx    1.0.0-beta.9
@pulumi/pulumi  3.36.0
@types/node     14.18.22

Pulumi locates its logs in /var/folders/rk/2c715ngd14jc4c7d3659m7pm0000gn/T/ by default

Additional context

It is entirely possible I am misunderstanding something here

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

@jaxxstorm jaxxstorm added kind/bug Some behavior is incorrect or out of spec needs-triage Needs attention from the triage team labels Jul 24, 2022
@jaxxstorm
Copy link
Contributor Author

I tried this with awsx classic, and confirmed it worked as expected:

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

export interface MyVpcArgs {
  cidrBlock: string;
}

export class MyVpc extends pulumi.ComponentResource {
  vpc: awsx.ec2.Vpc;
  classicVpc: classic.ec2.Vpc;

  constructor(
    name: string,
    args: MyVpcArgs,
    opts?: pulumi.ComponentResourceOptions
  ) {
    super("jaxxstorm:index:myvpc", name, {}, opts);

    // gets created in the wrong account
    this.vpc = new awsx.ec2.Vpc(
      name,
      {
        cidrBlock: args.cidrBlock,
        subnetSpecs: [
          {
            type: "Public",
            cidrMask: 26,
          },
          {
            type: "Isolated",
            cidrMask: 26,
          },
          {
            type: "Private",
            cidrMask: 24,
          },
        ],
        natGateways: {
          strategy: "OnePerAz",
        },
        tags: {
          Name: name,
        },
      },
      { parent: this }
    );

    // gets created in the account I expect
    this.classicVpc = new classic.ec2.Vpc(
      name,
      {
        cidrBlock: args.cidrBlock,
      },
      { parent: this }
    );
  }
}

@jkodroff jkodroff self-assigned this Jul 25, 2022
@jkodroff jkodroff removed the needs-triage Needs attention from the triage team label Jul 25, 2022
@jkodroff jkodroff removed their assignment Aug 15, 2022
@jkodroff
Copy link
Member

jkodroff commented Sep 5, 2022

This issue also affects aws.cloudtrail.Trail, and so I'm suspicious that it may affect all MLCs. Note that using providers instead of provider seemingly has no effect:

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

export class MyComponent extends pulumi.ComponentResource {
  constructor(
    name: string,
    opts?: pulumi.ComponentResourceOptions
  ) {
    super("joshtest:index:mycomponent", name, {}, opts);

    const trail = new awsx.cloudtrail.Trail(
      `my-trail-${name}`,
      {
        name: `ComponentTrail-${name}`,
      },
      { parent: this });
  }
}

const usEast1Provider = new aws.Provider("us-east-1", {
  region: "us-east-1",
});

// Gets created in my default region, us-west-2:
new MyComponent("ProviderOption", {
  provider: usEast1Provider,
});

// Gets created in us-east-1:
new awsx.cloudtrail.Trail(
  "non-component-trail",
  {
    name: "NonComponentTrail",
  },
  {
    provider: usEast1Provider,
  }
);

// Gets created in my default region, us-west-2:
new MyComponent("ProvidersOption", {
  providers: [usEast1Provider],
});

@jkodroff
Copy link
Member

jkodroff commented Sep 6, 2022

Verified that the same behavior exhibits in Python.

@iwahbe iwahbe changed the title awsx vpc inside component doesn't appear to use defined resource provider Children of component resources don't inherit their parents provider Sep 7, 2022
@iwahbe iwahbe changed the title Children of component resources don't inherit their parents provider Component children of component resources don't inherit their parents provider Sep 7, 2022
@iwahbe
Copy link
Member

iwahbe commented Sep 7, 2022

You should be able to workaround this issue by passing opts directly:

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

export class MyComponent extends pulumi.ComponentResource {
  constructor(
    name: string,
    opts?: pulumi.ComponentResourceOptions
  ) {
    super("joshtest:index:mycomponent", name, {}, opts);

    const trail = new awsx.cloudtrail.Trail(
      `my-trail-${name}`,
      {
        name: `ComponentTrail-${name}`,
      },
      { ...opts, parent: this });
  }
}

@iwahbe iwahbe transferred this issue from pulumi/pulumi-awsx Sep 7, 2022
@danielrbradley danielrbradley added the area/component-packages aka multi-language components label Sep 20, 2022
@iwahbe iwahbe changed the title Component children of component resources don't inherit their parents provider Component children of component resources don't inherit their parents providers Oct 11, 2022
@iwahbe
Copy link
Member

iwahbe commented Oct 11, 2022

To clarify, the original behavior is correct for provider. It should be providers.

@pawelprazak
Copy link

FYI: #10961 might be a variant of this issue, that affects kubernetes.yaml.ConfigGroup specifically.

@danielrbradley
Copy link
Member

You should be able to workaround this issue by passing opts directly:

@iwahbe I don't think this is a reasonable fix as this would add quite a significant amount of code between all our components which would be very susceptible to breaking. This really needs to be fixed in the core platform.

@iwahbe
Copy link
Member

iwahbe commented Oct 20, 2022

You should be able to workaround this issue by passing opts directly:

@iwahbe I don't think this is a reasonable fix as this would add quite a significant amount of code between all our components which would be very susceptible to breaking. This really needs to be fixed in the core platform.

@danielrbradley I'm not saying this is the solution. I'm saying this is a short term workaround until the fix (#10933) lands and the problem is solved in the engine.

bors bot added a commit that referenced this issue Oct 20, 2022
10933: Allow component resources to inherit `providers` from component resources r=iwahbe a=iwahbe

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. -->

Fixes #10640 

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [x] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Ian Wahbe <ian@wahbe.com>
@bors bors bot closed this as completed in a5cac1d Oct 20, 2022
@pulumi-bot pulumi-bot added the resolution/fixed This issue was fixed label Oct 20, 2022
@mikhailshilkov mikhailshilkov added this to the 0.79 milestone Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/component-packages aka multi-language components kind/bug Some behavior is incorrect or out of spec resolution/fixed This issue was fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants