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

Cross Stack References #651

Closed
skorfmann opened this issue Apr 20, 2021 · 8 comments · Fixed by #1416
Closed

Cross Stack References #651

skorfmann opened this issue Apr 20, 2021 · 8 comments · Fixed by #1416
Assignees
Labels
enhancement New feature or request feature/multi-stack priority/important-longterm Medium priority, to be worked on within the following 1-2 business quarters. size/large estimated < 1 month
Milestone

Comments

@skorfmann
Copy link
Contributor

skorfmann commented Apr 20, 2021

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

With #636 we've introduced multiple stacks. We should enable referencing resources across stacks.

References

@skorfmann skorfmann added the enhancement New feature or request label Apr 20, 2021
This was referenced Apr 22, 2021
@kwalsh-tr
Copy link

Does anyone know of a temporary alternative method of passing references between stacks?

@DanielMSchmidt
Copy link
Contributor

I think the nicest solution currently would be using DataSources to get a reference to an object into another stack. For this you need to have the name and type of the element you want to transfer. The name can be a global constant so that it can be used by the resource and data source.

const clusterName = "my-cluster"
class InfrastructureLayer extends TerraformStack {  
  constructor(scope: Construct, name: string) {    
    super(scope, name);

    new GKECluster(this, "doesNotMatter", {
      name: clusterName,
      // ...
    })
  }
}

class ApplicationLayer extends TerraformStack {  
  constructor(scope: Construct, name: string) {    
    super(scope, name);

    // This will fail if the cluster does not exist already
    new DataGKECluster(this, "doesNotMatter", {
      name: clusterName,
      // ...
    })
  }
}

const app = new App();
new InfrastructureLayer(app, "infrastructure");
new ApplicationLayer(app, "development");

@ansgarm
Copy link
Member

ansgarm commented Jun 22, 2021

Another option is to write the value you want to refer to into an output and read that value from a remote state in the other stack.
Edit: also described in the guide.

@danieldreier danieldreier added the priority/important-longterm Medium priority, to be worked on within the following 1-2 business quarters. label Jul 2, 2021
@ZacharyATanenbaum
Copy link

I think the nicest solution currently would be using DataSources to get a reference to an object into another stack. For this you need to have the name and type of the element you want to transfer. The name can be a global constant so that it can be used by the resource and data source.

Is this work-around supported within Python? I'm getting the following error when attempting to use a "Data Source" for a Python Lambda Layer Version.

ImportError: cannot import name 'DataLambdaLayerVersion' from 'imports.aws'

@jsteinich
Copy link
Collaborator

Is this work-around supported within Python? I'm getting the following error when attempting to use a "Data Source" for a Python Lambda Layer Version.

ImportError: cannot import name 'DataLambdaLayerVersion' from 'imports.aws'

You want DataAwsLambdaLayerVersion. Data source names are currently a bit more verbose than resource names.

@DanielMSchmidt
Copy link
Contributor

Here is a POC around this topic I did, for those interested: #1179

@phinze
Copy link
Contributor

phinze commented Nov 19, 2021

From discussion, this can be broken down into two separate issues:

  1. Getting cross-stack references working in code - this issue can continue to track that part
  2. Determining and implementing the CLI workflows associated with cross-stack references - this is captured at a high level with Deploy Multiple Stacks at Once  #650

We plan to tackle this part first, then we'll circle around to the CLI workflows once the core functionality is in place.

@github-actions
Copy link
Contributor

I'm going to lock this issue because it has been closed for 30 days. This helps our maintainers find and focus on the active issues. If you've found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request feature/multi-stack priority/important-longterm Medium priority, to be worked on within the following 1-2 business quarters. size/large estimated < 1 month
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants