Hey guys, I'm looking for some basic understanding...
# atmos
n
Hey guys, I'm looking for some basic understanding on creating stacks I have started creating resources in aws using components vpc, ec2, eks, etc If i want to create a component and use vpc how can i use the component id's directly instead of hard coding it (which i am doing). I know it can be done in a better way but i'm currently un-aware my stack yaml vpc:
Copy code
vpc:
      # Backend configuration for environment-based key structure
      backend:
        s3:
          workspace_key_prefix: "dev/terraform/vpc"
      vars:
        # CloudPosse label configuration
        enabled: true
        environment: "dev"         # ← Environment
        name: "vpc"               # ← Component name

        vpc:
          name: "vpc-dev" # ← User-defined VPC name (used directly)
          cidr_block: "172.22.0.0/21"
          availability_zones:
            - "us-west-2a"
            - "us-west-2b"
            - "us-west-2c"

          # Subnet Configuration
          subnets:
            private:
              - "172.22.0.0/24"
              - "172.22.1.0/24"
              - "172.22.2.0/24"
            public:
              - "172.22.3.0/24"
              - "172.22.4.0/24"
              - "172.22.5.0/24"
eks:
Copy code
eks-cluster:
      # Backend configuration for environment-based key structure
      backend:
        s3:
          workspace_key_prefix: "dev/terraform/eks-cluster"
      metadata:
        component: "eks-cluster"
      settings:
        depends_on:
          vpc:
            component: "vpc"
      vars:
        # CloudPosse Context Configuration
        eks_cluster_name: "eks-cluster-dev"
        # Development environment specific overrides
        cluster_version: "1.33"

        #VPC Configuration
        vpc_name: "vpc-dev"
        vpc_id: "vpc-3jd78hh83"
vpc_name here in eks cluster i have hard-coded it can i use something like {component.vpc.vpc_id}
a
Atmos supports many ways to Share Data Between Components, please see https://atmos.tools/core-concepts/share-data/ We recommend
!terraform.state
YAML function since it's the fastest https://atmos.tools/functions/yaml/terraform.state
n
as part of my infra creation, i have a different backend for each component will this work with my structuring or do i have to pull the state first and then use it?
a
YAML functions
!terraform.state
and
!terraform.output
should work "across" backends (https://atmos.tools/core-concepts/components/terraform/backends/).
!terraform.state
reads the backend config from the component (check the backend config with
atmos describe component
), and will use the configured s3 bucket to read the state from, including assuming the backend IAM role (if configured in the backend).
!terraform.output
generates the backend file (from the Atmos component backend config) and executes
terraform output
command. Terraform itself reads the backend file, and if it has all the permissions, will get the output and return it to Atmos Please test it and let us know if you see any issues
n
can i use the terraform shell to see these outputs to figure out what are the id's and such
a
atmos describe component
will evaluate the YAML functions and show the final values in the output