Thread
#general
    e

    echoing-postman-88590

    5 months ago
    Hi, are there best practices/example repositories on how to split the infrastructure (AWS EKS, GCP GKE, ...) and the applications (helm charts)? Thanks
    l

    limited-rainbow-51650

    5 months ago
    Hello @echoing-postman-88590, aside the tools at hand, I picked up a lot on how to structure "stacks" in general by reading the book "Infrastructure as Code" (2nd Ed).https://www.oreilly.com/library/view/infrastructure-as-code/9781098114664/
    One of the items in there is to group based on lifecycle of the resources. Things which have a different life span (e.g. service vs its database) should be put in different stacks.
    e

    echoing-postman-88590

    5 months ago
    Is there an example code on how to link multiple stacks?
    l

    limited-rainbow-51650

    5 months ago
    My approach usually is as follows: I have different Pulumi projects representing different layers of infrastructure, with clear dependencies. Layers are put on top of each other and may only depend on layers below it. This is the code part. Per environment, I have to set up, I create similarly named stacks in the projects I need for that environment. So my projects could be named: • network • databases • message brokers • service A • service B while my stacks could be named: • dev • staging • production Does my explanation make sense?
    In the layering, if I need info from a lower layer, I use
    StackReferences
    .
    e

    echoing-postman-88590

    5 months ago
    Yes, you named it right what I would like to have is having different layers (k8s cluster, apps, ...). But I am not sure how does the code may look like. Is there an example code for
    STackReferences
    ? Thank you very much
    Thanks
    @limited-rainbow-51650 I am following the repo above. I have the following files:
    $ tail */* 
    ==> company/Pulumi.yaml <==
    name: stackreference-company
    runtime: python
    description: company
    template:
      description: A minimal AWS TypeScript Pulumi program
      config:
        companyName:
          description: The company name to use
    
    ==> company/__main__.py <==
    
    import pulumi
    
    config = pulumi.Config()
    companyName = config.require("companyName")
    
    ==> department/Pulumi.yaml <==
    name: stackreference-department
    runtime: python
    description: department
    template:
      description: A minimal AWS TypeScript Pulumi program
      config:
        departmentName:
          description: The department name to use
    
    ==> department/__main__.py <==
    
    import pulumi
    
    config = pulumi.Config()
    companyName = config.require("departmentName")
    
    ==> team/Pulumi.yaml <==
    description: team
    template:
      description: A minimal AWS TypeScript Pulumi program
      config:
        companyStack:
          description: The stack to reference company properties from
        departmentStack:
          description: The stack to reference department properties from
        teamName:
          description: The team name to use
    
    ==> team/__main__.py <==
    
    import pulumi
    
    config = pulumi.Config()
    
    companyStack = pulumi.StackReference(config.require("companyStack"))
    departmentStack = pulumi.StackReference(config.require("departmentStack"))
    If I run:
    $ pulumi login --local
    $ pulumi stack init dev
    Created stack 'dev'
    $ pulumi config set companyName 'ACME Widget Company'
    $ pulumi up --yes
    Previewing update (dev):
         Type                 Name                        Plan       
     +   pulumi:pulumi:Stack  stackreference-company-dev  create     
     
    Resources:
        + 1 to create
    
    Updating (dev):
         Type                 Name                        Status      
     +   pulumi:pulumi:Stack  stackreference-company-dev  created     
     
    Resources:
        + 1 created
    
    Duration: 1s
    $ cd ../department
    $ pulumi stack init dev
    error: stack 'dev' already exists
    Am I missing something? Thanks
    l

    limited-rainbow-51650

    5 months ago
    @echoing-postman-88590 you are not missing something. However, you are using the local file system for state. There are a lot of shortcomings to the self-managed state backends still. One of these is that the project name is not part of the stack name in the state persistence. Which means, in your case, you can't have a stack named
    dev
    for more than 1 project. Getting a number of these issues resolved seems to be on the roadmap for Q2-2022: https://github.com/orgs/pulumi/projects/44/views/1 The issue you are most interested in is this one: https://github.com/pulumi/pulumi/issues/4605 To get around your problem, in
    ./department
    , you could name your stack
    dev-department
    to not have an overlap.