<@U07RLUFFH7W> we tried to use atmos terraform cle...
# atmos-dev
e
@Haitham we tried to use atmos terraform clean yesterday and discovered it doesn’t support components in subfolders. We should probably change our approach to use all configured components since component paths can be customized. In other words using the fully deepmerged stack configuration.
👀 1
h
should we list and clean all components, ensuring it handles subfolder structures
how I can test that issue ?
e
If you have components/terraform/folder/vpc, it won’t find it
Instead of we traversed all components in the stack configuration, that would be more accurate
@Andriy Knysh (Cloud Posse) can you point him in the right direction?
h
yes sure
is @Andriy Knysh (Cloud Posse) will work on it or me
e
No, he is too busy
h
ok I will review the right direction with him
do you know how I can produce the issue ? how I can create components/terraform/folder/vpc
a
i’ll describe the issue and the solution
✅ 1
the current (updated)
terraform clean
code works OK in this case: •
atmos terraform clean <component> -s <stack>
finds the component path (in
components/terraform
) and deletes the related files
atmos terraform clean
should find all component paths and delete the relevant files. But it works only on the first sub-folder level, e.g.
Copy code
repo
  components
    terraform
      component-1
but it does not work on the components in the next level of subfolders, e.g. https://github.com/cloudposse/terraform-aws-components/tree/main/modules/eks - all components under the
eks
folder will not be processed
to solve this, we can do the following:
• Create a test case with 2 level of subfolders, e.g.
Copy code
repo
  tests
    fixtures
      scenarios
        terraform-sub-components
          stacks
          components
            terraform
            component-1
              main.tf
              component-2
                main.tf
• if the commands is executed w/o a component and a stack (to clean everything),
atmos terraform clean
, execute
ExecuteDescribeStacks
Go function to find all stacks and all components • Process the result of the command to find ALL unique Atmos components from all stacks • For each unique Atmos component, find the
component
attribute from the output - the
component
attribute points to the corresponding terraform component path
👀 1
for example, for the example above, you will get the following
Copy code
component-1: 
`component` will be `component-1`

component-2: 
`component` will be `component-1/component-2`
to summarize:
• find all Atmos components • find the
component
attribute for each Atmos component - it points to the TF component path • join the base path (e.g.
components/terraform
) with the
component
attribute to find the Terraform path for each component • delete the relevant files from the path
by doing it this way, you always have a list the correct Atmos components and the correct paths to the TF components
👀 1
h
is that correct create for test case ? 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: false

stacks:
  base_path: "stacks"
  included_paths:
    - "deploy/**/*"
  excluded_paths:
    - "**/_defaults.yaml"
  name_pattern: "{stage}"
/stacks/deploy/staging.yaml
Copy code
vars:
  stage: staging
components:
  terraform:
    component-1:
      vars:
        location: Los Angeles
        lang: en
a
component-2 should be inside component-1 folder, similar to the eks example
h
yes component-2 its under component-1 tests/fixtures/scenarios/terraform-sub-components/components/terraform/component-1/component-2
but how it can be on stack
should I add component-2 to stack file as sub component-1
image.png
a
Atmos stacks are not (directly) related to the folder structure. Atmos component names can be different from the corresponding Terraform component names - Atmos component name can be anything (e.g.
apple
) and point to a Terraform component
components/terraform/cherry
)
Copy code
components:
  terraform:
    component-1
      metadata:
        component: component-1 # Point to the Terraform component inside `components/terraform`

   component-2:
     metadata:
       component: component-1/component-2  # Point to the Terraform component inside `components/terraform`
h