Hi All! This most likely me doing something stupid...
# atmos
s
Hi All! This most likely me doing something stupid since I'm new to atmos but I can not figure out how to set a default s3 backend config (in
stacks/environment/_defaults.yaml
) to be used in my
networking.yaml
stacks. I am using the auto generated backend file in my atmos.yaml this is my folder structure
Copy code
├── atmos.yaml
├── components
│   └── terraform
│       └── vpc
└── stacks
    ├── environment
    │   ├── _defaults.yaml
    │   ├── sandbox
    │   │   └── networking.yaml
    │   └── staging
    │       └── networking.yaml
    └── mixins
        └── environment
            ├── sandbox.yaml
            └── staging.yaml
and this is my atmos.yaml
Copy code
base_path: "./"

components:
  terraform:
    base_path: "components/terraform"
    apply_auto_approve: false
    deploy_run_init: true
    init_run_reconfigure: true
    auto_generate_backend_file: true

stacks:
  base_path: "stacks"
  included_paths:
    - "environment/**/*"
  excluded_paths:
    - "environment/_defaults.yaml"
  name_pattern: "{environment}"

logs:
  file: "/dev/stderr"
  level: Info
one of my networking stacks
Copy code
imports:
  - mixins/environment/sandbox
  - environment/_defaults

vars:
  environment: sandbox

components:
  terraform:
    vpc:
      backend:
        s3:
          workspace_key_prefix: sandbox
      vars:
        vpc_ipv4_cidr: "10.1.0.0/16"
I always get an error saying my backend.tf.json is empty since it looks like this
Copy code
{
  "terraform": {
    "backend": {
      "": {}
    }
  }
}
I would really appreciate any help since i've spent a few hours now trying to get this working to no avail.
a
you need to configure the backend in Atmos stack manifest (in your Org `_defaults.yaml for example)
Copy code
terraform:
  backend_type: s3
  backend:
    s3:
      acl: "bucket-owner-full-control"
      encrypt: true
      bucket: "your-s3-bucket-name"
      dynamodb_table: "your-dynamodb-table-name"
      key: "terraform.tfstate"
      region: "your-aws-region"
      role_arn: "arn:aws:iam::xxxxxxxx:role/IAM Role with permissions to access the Terraform backend"
Atmos get sthe values from
Copy code
backend:
    s3:
when auto-generating the backend file
s
Thanks for getting back to me Andriy, I don't understand your suggestion
you need to configure the backend in Atmos stack manifest (in your Org `_defaults.yaml for example)
Is having a directory called
orgs
in my stacks a hard requirement for this to work? Currently my _defaults.yaml is located in
stacks/environment/_defaults.yaml
As shown here
Copy code
├── atmos.yaml
├── components
│   └── terraform
│       └── vpc
└── stacks
    ├── environment
    │   ├── _defaults.yaml
    │   ├── sandbox
    │   │   └── networking.yaml
    │   └── staging
    │       └── networking.yaml
    └── mixins
        └── environment
            ├── sandbox.yaml
            └── staging.yaml
Do I need to make an
orgs
directory to put the
_defaults.yaml
in?
Something like this
Copy code
.
├── atmos.yaml
├── components
└── stacks
    ├── mixins
    └── orgs
        ├── _defaults.yaml
        └── environment
            ├── sandbox
            │   └── networking.yaml
            └── staging
                └── networking.yaml
I think the directory structure is what I am confused with. The documentation gives examples of a stack structure consisting of orgs/acme which I interpreted as an example like foo bar.
What I also don't understand is why only the first line in my import block is being imported
Copy code
imports:
  - mixins/environment/sandbox
  - environment/_defaults

vars:
  environment: sandbox

components:
  terraform:
    vpc:
The KV pairs in
Copy code
- mixins/environment/sandbox
are imported but the s3 configuration in
environment/_defaults
is not being imported
a
the directory structure is not "important" - this is the beauty of Atmos, it does not care about the file names and directory structure, they are for humans to better name and organize the stacks. Atmos only cares about how to find the stack files and the
context
(namespace, tenant, environment, stage) for how to define/name stacks To tell Atmos where to find the stack files, we have this config in
atmos.yaml
Copy code
stacks:
  # Can also be set using 'ATMOS_STACKS_BASE_PATH' ENV var, or '--config-dir' and '--stacks-dir' command-line arguments
  # Supports both absolute and relative paths
  base_path: "stacks"
  # Can also be set using 'ATMOS_STACKS_INCLUDED_PATHS' ENV var (comma-separated values string)
  included_paths:
    - "orgs/**/*"
  # Can also be set using 'ATMOS_STACKS_EXCLUDED_PATHS' ENV var (comma-separated values string)
  excluded_paths:
    - "**/_defaults.yaml"
  # Can also be set using 'ATMOS_STACKS_NAME_PATTERN' ENV var
  name_pattern: "{tenant}-{environment}-{stage}"
please review it
in your case, instead of
Copy code
included_paths:
    - "orgs/**/*"
you need to do
Copy code
included_paths:
    - "environment/**/*"
    - "mixins/**/*"
to tell Atmos to search for your stack files in the
environment
and
mixins
subfolders in the
stacks
folder
so while it's not required to have the
orgs
folder (it's up to you to use any folders, any subfolder, any names), it's required to tell Atmos where to find your stack files
the backend config
Copy code
backend:
    s3:
should be in the
environment/_defaults
file - if you want to use the same backend for the entire org (for all accounts and regions)
otherwise, you can configure different backends, for example, per account, in which case you put the backend configs
backend.s3
into
environment/sandbox/_defaults.yaml
and import it into the
sandbox
stack
s
Thank you for being so patient with me! I'm sorry I'm struggling so much with what appears to be very trivial. To your suggest I currently have the following s3 config in
stacks/environment/_defaults.yaml
Copy code
terraform:
  backend_type: s3
  backend:
    s3:
      acl: "bucket-owner-full-control"
      encrypt: true
      bucket: "terraform"
      key: "terraform.tfstate"
      region: "eu-west-2"
      role_arn: "arn:aws:iam::id:role/terraform"
and import it in the
stacks/environment/sandbox/networking.yaml
file
Copy code
imports:
  - mixins/environment/sandbox
  - environment/_defaults
But when I run
atmos terraform plan -s sandbox
I get
Copy code
DEBU Set logs-level=debug logs-file=/dev/stderr
DEBU ProcessTmplWithDatasources: not processing templates since templating is disabled in 'atmos.yaml' template=describe-stacks-all-sections
DEBU Executing command="atmos terraform plan vpc -s sandbox"
DEBU Found component 'vpc' in the stack 'sandbox' in the stack manifest 'environment/sandbox/networking'
DEBU ProcessTmplWithDatasources: not processing templates since templating is disabled in 'atmos.yaml' template=templates-all-atmos-sections
DEBU Variables for the component in the stack component=vpc stack=sandbox
DEBU PrintAsYAMLToFileDescriptor
  data=
  │ environment: sandbox
  │ vpc_ipv4_cidr: 10.1.0.0/16

DEBU Writing the variables file=components/terraform/vpc/sandbox-vpc.terraform.tfvars.json
DEBU Writing the backend config to file. file=components/terraform/vpc/backend.tf.json
DEBU Using ENV vars:
DEBU ATMOS_CLI_CONFIG_PATH=/
DEBU ATMOS_BASE_PATH=/
DEBU TF_IN_AUTOMATION=true
DEBU TF_APPEND_USER_AGENT=Atmos/1.188.0 (Cloud Posse; +https://atmos.tools)
DEBU Terraform environment file not found. No action needed. 
DEBU Executing command="/opt/homebrew/bin/terraform init -reconfigure"
Initializing the backend...
╷
│ Error: Unsupported backend type
│ 
│   on backend.tf.json line 4, in terraform.backend:
│    4:       "": {}
│ 
│ There is no backend type named "".
╵
 Error 

exit status 1
So atmos is definitely finding the stacks and the mixins but just not the s3 config in _defaults