Skip to content

Commit

Permalink
Allow Go templates in metadata.component section. Add `components…
Browse files Browse the repository at this point in the history
….terraform.command` section to `atmos.yaml`. Document OpenTofu support (#604)

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* Update website/docs/integrations/terraform.md

* Update website/docs/cli/configuration.mdx

Co-authored-by: Erik Osterman (CEO @ Cloud Posse) <[email protected]>

* updates

---------

Co-authored-by: Erik Osterman (CEO @ Cloud Posse) <[email protected]>
  • Loading branch information
aknysh and osterman committed May 22, 2024
1 parent 774d30d commit f7aa382
Show file tree
Hide file tree
Showing 35 changed files with 535 additions and 160 deletions.
10 changes: 10 additions & 0 deletions atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ base_path: "./examples/quick-start"

components:
terraform:
# Optional `command` specifies the executable to be called by `atmos` when running Terraform commands
# If not defined, `terraform` is used
# Examples:
# command: terraform
# command: /usr/local/bin/terraform
# command: /usr/local/bin/terraform-1.8
# command: tofu
# command: /usr/local/bin/tofu-1.7.1
# Can also be set using 'ATMOS_COMPONENTS_TERRAFORM_COMMAND' ENV var, or '--terraform-command' command-line argument
command: terraform
# Can also be set using 'ATMOS_COMPONENTS_TERRAFORM_BASE_PATH' ENV var, or '--terraform-dir' command-line argument
# Supports both absolute and relative paths
base_path: "components/terraform"
Expand Down
4 changes: 2 additions & 2 deletions examples/quick-start/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Geodesic: https://github.com/cloudposse/geodesic/
ARG GEODESIC_VERSION=2.9.6
ARG GEODESIC_VERSION=2.11.2
ARG GEODESIC_OS=debian

# Atmos
# https://atmos.tools/
# https://github.com/cloudposse/atmos
# https://github.com/cloudposse/atmos/releases
ARG ATMOS_VERSION=1.72.0
ARG ATMOS_VERSION=1.73.0

# Terraform: https://github.com/hashicorp/terraform/releases
ARG TF_VERSION=1.8.1
Expand Down
10 changes: 10 additions & 0 deletions examples/quick-start/atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ base_path: "."

components:
terraform:
# Optional `command` specifies the executable to be called by `atmos` when running Terraform commands
# If not defined, `terraform` is used
# Examples:
# command: terraform
# command: /usr/local/bin/terraform
# command: /usr/local/bin/terraform-1.8
# command: tofu
# command: /usr/local/bin/tofu-1.7.1
# Can also be set using 'ATMOS_COMPONENTS_TERRAFORM_COMMAND' ENV var, or '--terraform-command' command-line argument
command: terraform
# Can also be set using 'ATMOS_COMPONENTS_TERRAFORM_BASE_PATH' ENV var, or '--terraform-dir' command-line argument
# Supports both absolute and relative paths
base_path: "components/terraform"
Expand Down
10 changes: 10 additions & 0 deletions examples/quick-start/rootfs/usr/local/etc/atmos/atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ base_path: ""

components:
terraform:
# Optional `command` specifies the executable to be called by `atmos` when running Terraform commands
# If not defined, `terraform` is used
# Examples:
# command: terraform
# command: /usr/local/bin/terraform
# command: /usr/local/bin/terraform-1.8
# command: tofu
# command: /usr/local/bin/tofu-1.7.1
# Can also be set using 'ATMOS_COMPONENTS_TERRAFORM_COMMAND' ENV var, or '--terraform-command' command-line argument
command: terraform
# Can also be set using 'ATMOS_COMPONENTS_TERRAFORM_BASE_PATH' ENV var, or '--terraform-dir' command-line argument
# Supports both absolute and relative paths
base_path: "components/terraform"
Expand Down
1 change: 1 addition & 0 deletions examples/quick-start/stacks/orgs/acme/_defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ terraform:
atmos_stack: "{{ .atmos_stack }}"
atmos_manifest: "{{ .atmos_stack_file }}"
terraform_workspace: "{{ .workspace }}"
terraform_component: "{{ .component }}"
# Examples of using the Sprig and Gomplate functions
# https://masterminds.github.io/sprig/os.html
provisioned_by_user: '{{ env "USER" }}'
Expand Down
10 changes: 10 additions & 0 deletions examples/tests/atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ base_path: "."

components:
terraform:
# Optional `command` specifies the executable to be called by `atmos` when running Terraform commands
# If not defined, `terraform` is used
# Examples:
# command: terraform
# command: /usr/local/bin/terraform
# command: /usr/local/bin/terraform-1.8
# command: tofu
# command: /usr/local/bin/tofu-1.7.1
# Can also be set using 'ATMOS_COMPONENTS_TERRAFORM_COMMAND' ENV var, or '--terraform-command' command-line argument
command: terraform
# Can also be set using 'ATMOS_COMPONENTS_TERRAFORM_BASE_PATH' ENV var, or '--terraform-dir' command-line argument
# Supports both absolute and relative paths
base_path: "components/terraform"
Expand Down
10 changes: 10 additions & 0 deletions examples/tests/rootfs/usr/local/etc/atmos/atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ base_path: ""

components:
terraform:
# Optional `command` specifies the executable to be called by `atmos` when running Terraform commands
# If not defined, `terraform` is used
# Examples:
# command: terraform
# command: /usr/local/bin/terraform
# command: /usr/local/bin/terraform-1.8
# command: tofu
# command: /usr/local/bin/tofu-1.7.1
# Can also be set using 'ATMOS_COMPONENTS_TERRAFORM_COMMAND' ENV var, or '--terraform-command' command-line argument
command: terraform
# Can also be set using 'ATMOS_COMPONENTS_TERRAFORM_BASE_PATH' ENV var, or '--terraform-dir' command-line argument
# Supports both absolute and relative paths
base_path: "components/terraform"
Expand Down
1 change: 1 addition & 0 deletions examples/tests/stacks/orgs/cp/_defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ terraform:
atmos_stack: "{{ .atmos_stack }}"
atmos_manifest: "{{ .atmos_stack_file }}"
terraform_workspace: "{{ .workspace }}"
terraform_component: "{{ .component }}"
# Examples of using the Sprig and Gomplate functions
# https://masterminds.github.io/sprig/os.html
provisioned_by_user: '{{ env "USER" }}'
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/charmbracelet/bubbletea v0.26.2
github.com/charmbracelet/lipgloss v0.10.0
github.com/elewis787/boa v0.1.2
github.com/fatih/color v1.16.0
github.com/fatih/color v1.17.0
github.com/go-git/go-git/v5 v5.12.0
github.com/google/go-containerregistry v0.19.1
github.com/google/go-github/v59 v59.0.0
Expand All @@ -20,7 +20,7 @@ require (
github.com/hashicorp/go-getter v1.7.4
github.com/hashicorp/hcl v1.0.0
github.com/hashicorp/hcl/v2 v2.20.1
github.com/hashicorp/terraform-config-inspect v0.0.0-20240507135902-21dcc2942448
github.com/hashicorp/terraform-config-inspect v0.0.0-20240509232506-4708120f8f30
github.com/imdario/mergo v0.3.13
github.com/ivanpirog/coloredcobra v1.0.1
github.com/json-iterator/go v1.1.12
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,8 @@ github.com/evanphx/json-patch/v5 v5.5.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2Vvl
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
Expand Down Expand Up @@ -793,8 +793,8 @@ github.com/hashicorp/memberlist v0.5.0 h1:EtYPN8DpAURiapus508I4n9CzHs2W+8NZGbmmR
github.com/hashicorp/memberlist v0.5.0/go.mod h1:yvyXLpo0QaGE59Y7hDTsTzDD25JYBZ4mHgHUZ8lrOI0=
github.com/hashicorp/serf v0.10.1 h1:Z1H2J60yRKvfDYAOZLd2MU0ND4AH/WDz7xYHDWQsIPY=
github.com/hashicorp/serf v0.10.1/go.mod h1:yL2t6BqATOLGc5HF7qbFkTfXoPIY0WZdWHfEvMqbG+4=
github.com/hashicorp/terraform-config-inspect v0.0.0-20240507135902-21dcc2942448 h1:rrpMPsKdq+AO9+dMOQDzTO1IBHYEGcYwF1/roaSDy2Y=
github.com/hashicorp/terraform-config-inspect v0.0.0-20240507135902-21dcc2942448/go.mod h1:l8HcFPm9cQh6Q0KSWoYPiePqMvRFenybP1CH2MjKdlg=
github.com/hashicorp/terraform-config-inspect v0.0.0-20240509232506-4708120f8f30 h1:0qwr2oZy9mIIJMWh7W9NTHLWGMbEF5KEQ+QqM9hym34=
github.com/hashicorp/terraform-config-inspect v0.0.0-20240509232506-4708120f8f30/go.mod h1:Gz/z9Hbn+4KSp8A2FBtNszfLSdT2Tn/uAKGuVqqWmDI=
github.com/hashicorp/vault/api v1.6.0 h1:B8UUYod1y1OoiGHq9GtpiqSnGOUEWHaA26AY8RQEDY4=
github.com/hashicorp/vault/api v1.6.0/go.mod h1:h1K70EO2DgnBaTz5IsL6D5ERsNt5Pce93ueVS2+t0Xc=
github.com/hashicorp/vault/sdk v0.5.0 h1:EED7p0OCU3OY5SAqJwSANofY1YKMytm+jDHDQ2EzGVQ=
Expand Down
2 changes: 1 addition & 1 deletion internal/exec/atlantis_generate_repo_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func ExecuteAtlantisGenerateRepoConfig(
// If 'component' attribute is present, it's the terraform component
// Otherwise, the Atmos component name is the terraform component (by default)
terraformComponent := componentName
if componentAttribute, ok := componentSection["component"].(string); ok {
if componentAttribute, ok := componentSection[cfg.ComponentSectionName].(string); ok {
terraformComponent = componentAttribute
}

Expand Down
4 changes: 2 additions & 2 deletions internal/exec/describe_affected_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ func findAffected(
}

// Check the Terraform configuration of the component
if component, ok := componentSection["component"].(string); ok && component != "" {
if component, ok := componentSection[cfg.ComponentSectionName].(string); ok && component != "" {
// Check if the component uses some external modules (on the local filesystem) that have changed
changed, err := areTerraformComponentModulesChanged(component, cliConfig, changedFiles)
if err != nil {
Expand Down Expand Up @@ -805,7 +805,7 @@ func findAffected(
}

// Check the Helmfile configuration of the component
if component, ok := componentSection["component"].(string); ok && component != "" {
if component, ok := componentSection[cfg.ComponentSectionName].(string); ok && component != "" {
// Check if any files in the component's folder have changed
changed, err := isComponentFolderChanged(component, "helmfile", cliConfig, changedFiles)
if err != nil {
Expand Down
16 changes: 8 additions & 8 deletions internal/exec/describe_stacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ func ExecuteDescribeStacks(
return nil, fmt.Errorf("invalid 'components.terraform.%s' section in the file '%s'", componentName, stackFileName)
}

if comp, ok := componentSection["component"].(string); !ok || comp == "" {
componentSection["component"] = componentName
if comp, ok := componentSection[cfg.ComponentSectionName].(string); !ok || comp == "" {
componentSection[cfg.ComponentSectionName] = componentName
}

// Find all derived components of the provided components and include them in the output
Expand Down Expand Up @@ -200,8 +200,8 @@ func ExecuteDescribeStacks(
},
}

if comp, ok := configAndStacksInfo.ComponentSection["component"].(string); !ok || comp == "" {
configAndStacksInfo.ComponentSection["component"] = componentName
if comp, ok := configAndStacksInfo.ComponentSection[cfg.ComponentSectionName].(string); !ok || comp == "" {
configAndStacksInfo.ComponentSection[cfg.ComponentSectionName] = componentName
}

// Stack name
Expand Down Expand Up @@ -309,8 +309,8 @@ func ExecuteDescribeStacks(
return nil, fmt.Errorf("invalid 'components.helmfile.%s' section in the file '%s'", componentName, stackFileName)
}

if comp, ok := componentSection["component"].(string); !ok || comp == "" {
componentSection["component"] = componentName
if comp, ok := componentSection[cfg.ComponentSectionName].(string); !ok || comp == "" {
componentSection[cfg.ComponentSectionName] = componentName
}

// Find all derived components of the provided components and include them in the output
Expand Down Expand Up @@ -374,8 +374,8 @@ func ExecuteDescribeStacks(
},
}

if comp, ok := configAndStacksInfo.ComponentSection["component"].(string); !ok || comp == "" {
configAndStacksInfo.ComponentSection["component"] = componentName
if comp, ok := configAndStacksInfo.ComponentSection[cfg.ComponentSectionName].(string); !ok || comp == "" {
configAndStacksInfo.ComponentSection[cfg.ComponentSectionName] = componentName
}

// Stack name
Expand Down
6 changes: 3 additions & 3 deletions internal/exec/stack_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func ProcessComponentMetadata(
var componentMetadata map[any]any

// Find base component in the `component` attribute
if base, ok := componentSection["component"].(string); ok {
if base, ok := componentSection[cfg.ComponentSectionName].(string); ok {
baseComponentName = base
}

Expand All @@ -77,7 +77,7 @@ func ProcessComponentMetadata(
}
// Find base component in the `metadata.component` attribute
// `metadata.component` overrides `component`
if componentMetadataComponent, componentMetadataComponentExists := componentMetadata["component"].(string); componentMetadataComponentExists {
if componentMetadataComponent, componentMetadataComponentExists := componentMetadata[cfg.ComponentSectionName].(string); componentMetadataComponentExists {
baseComponentName = componentMetadataComponent
}
}
Expand Down Expand Up @@ -155,7 +155,7 @@ func BuildComponentPath(

var componentPath string

if stackComponentSection, ok := componentSectionMap["component"].(string); ok {
if stackComponentSection, ok := componentSectionMap[cfg.ComponentSectionName].(string); ok {
if componentType == "terraform" {
componentPath = path.Join(cliConfig.BasePath, cliConfig.Components.Terraform.BasePath, stackComponentSection)
} else if componentType == "helmfile" {
Expand Down
2 changes: 1 addition & 1 deletion internal/exec/terraform_generate_backends.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func ExecuteTerraformGenerateBackends(cliConfig schema.CliConfiguration, fileTem
// If `component` attribute is present, it's the terraform component.
// Otherwise, the YAML component name is the terraform component.
terraformComponent := componentName
if componentAttribute, ok := componentSection["component"].(string); ok {
if componentAttribute, ok := componentSection[cfg.ComponentSectionName].(string); ok {
terraformComponent = componentAttribute
}

Expand Down
2 changes: 1 addition & 1 deletion internal/exec/terraform_generate_varfiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func ExecuteTerraformGenerateVarfiles(cliConfig schema.CliConfiguration, fileTem
// If `component` attribute is present, it's the terraform component.
// Otherwise, the YAML component name is the terraform component.
terraformComponent := componentName
if componentAttribute, ok := componentSection["component"].(string); ok {
if componentAttribute, ok := componentSection[cfg.ComponentSectionName].(string); ok {
terraformComponent = componentAttribute
}

Expand Down
Loading

0 comments on commit f7aa382

Please sign in to comment.