Skip to content

Commit

Permalink
Update atmos describe affected command. Update docs (#590)
Browse files Browse the repository at this point in the history
* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* updates

* Apply suggestions from code review

address comments

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

* Add Google Tag Manager

---------

Co-authored-by: Erik Osterman (CEO @ Cloud Posse) <[email protected]>
  • Loading branch information
aknysh and osterman authored Apr 30, 2024
1 parent 7eb0a88 commit 2b85f6f
Show file tree
Hide file tree
Showing 39 changed files with 671 additions and 343 deletions.
6 changes: 6 additions & 0 deletions cmd/atlantis_generate_repo_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,11 @@ func init() {
atlantisGenerateRepoConfigCmd.PersistentFlags().String("ssh-key", "", "Path to PEM-encoded private key to clone private repos using SSH: atmos atlantis generate repo-config --affected-only=true --ssh-key <path_to_ssh_key>")
atlantisGenerateRepoConfigCmd.PersistentFlags().String("ssh-key-password", "", "Encryption password for the PEM-encoded private key if the key contains a password-encrypted PEM block: atmos atlantis generate repo-config --affected-only=true --ssh-key <path_to_ssh_key> --ssh-key-password <password>")

atlantisGenerateCmd.PersistentFlags().Bool("clone-target-ref", false, "Clone the target reference with which to compare the current branch: "+
"atmos atlantis generate repo-config --affected-only=true --clone-target-ref=true\n"+
"The flag is only used when '--affected-only=true'\n"+
"If set to 'false' (default), the target reference will be checked out instead\n"+
"This requires that the target reference is already cloned by Git, and the information about it exists in the '.git' directory")

atlantisGenerateCmd.AddCommand(atlantisGenerateRepoConfigCmd)
}
5 changes: 4 additions & 1 deletion cmd/describe_affected.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ func init() {
describeAffectedCmd.PersistentFlags().String("repo-path", "", "Filesystem path to the already cloned target repository with which to compare the current branch: atmos describe affected --repo-path <path_to_already_cloned_repo>")
describeAffectedCmd.PersistentFlags().String("ref", "", "Git reference with which to compare the current branch: atmos describe affected --ref refs/heads/main. Refer to https://git-scm.com/book/en/v2/Git-Internals-Git-References for more details")
describeAffectedCmd.PersistentFlags().String("sha", "", "Git commit SHA with which to compare the current branch: atmos describe affected --sha 3a5eafeab90426bd82bf5899896b28cc0bab3073")
describeAffectedCmd.PersistentFlags().String("file", "", "Write the result to the file: atmos describe affected --ref refs/tags/v1.16.0 --file affected.json")
describeAffectedCmd.PersistentFlags().String("file", "", "Write the result to the file: atmos describe affected --ref refs/tags/v1.71.0 --file affected.json")
describeAffectedCmd.PersistentFlags().String("format", "json", "The output format: atmos describe affected --format=json|yaml ('json' is default)")
describeAffectedCmd.PersistentFlags().Bool("verbose", false, "Print more detailed output when cloning and checking out the Git repository: atmos describe affected --verbose=true")
describeAffectedCmd.PersistentFlags().String("ssh-key", "", "Path to PEM-encoded private key to clone private repos using SSH: atmos describe affected --ssh-key <path_to_ssh_key>")
describeAffectedCmd.PersistentFlags().String("ssh-key-password", "", "Encryption password for the PEM-encoded private key if the key contains a password-encrypted PEM block: atmos describe affected --ssh-key <path_to_ssh_key> --ssh-key-password <password>")
describeAffectedCmd.PersistentFlags().Bool("include-spacelift-admin-stacks", false, "Include the Spacelift admin stack of any stack that is affected by config changes: atmos describe affected --include-spacelift-admin-stacks=true")
describeAffectedCmd.PersistentFlags().Bool("clone-target-ref", false, "Clone the target reference with which to compare the current branch: atmos describe affected --clone-target-ref=true\n"+
"If set to 'false' (default), the target reference will be checked out instead\n"+
"This requires that the target reference is already cloned by Git, and the information about it exists in the '.git' directory")

describeCmd.AddCommand(describeAffectedCmd)
}
4 changes: 2 additions & 2 deletions examples/quick-start/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ ARG GEODESIC_OS=debian
# https://atmos.tools/
# https://github.com/cloudposse/atmos
# https://github.com/cloudposse/atmos/releases
ARG ATMOS_VERSION=1.70.0
ARG ATMOS_VERSION=1.71.0

# Terraform: https://github.com/hashicorp/terraform/releases
ARG TF_VERSION=1.8.0
ARG TF_VERSION=1.8.1

FROM cloudposse/geodesic:${GEODESIC_VERSION}-${GEODESIC_OS}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@
"backend_type": {
"type": "string",
"enum": [
"local",
"s3",
"remote",
"vault",
Expand All @@ -455,6 +456,7 @@
"remote_state_backend_type": {
"type": "string",
"enum": [
"local",
"s3",
"remote",
"vault",
Expand Down
18 changes: 0 additions & 18 deletions examples/tests/atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,24 +125,6 @@ commands:
steps:
- atmos terraform plan $ATMOS_COMPONENT -s $ATMOS_STACK
- atmos terraform apply $ATMOS_COMPONENT -s $ATMOS_STACK
- name: play
description: This command plays games
steps:
- echo Playing...
# subcommands
commands:
- name: hello
description: This command says Hello world
steps:
- echo Hello world
- name: ping
description: This command plays ping-pong
# If 'verbose' is set to 'true', atmos will output some info messages to the console before executing the command's steps
# If 'verbose' is not defined, it implicitly defaults to 'false'
verbose: true
steps:
- echo Playing ping-pong...
- echo pong
- name: show
description: Execute 'show' commands
# subcommands
Expand Down
18 changes: 0 additions & 18 deletions examples/tests/rootfs/usr/local/etc/atmos/atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,24 +118,6 @@ commands:
steps:
- atmos terraform plan $ATMOS_COMPONENT -s $ATMOS_STACK
- atmos terraform apply $ATMOS_COMPONENT -s $ATMOS_STACK
- name: play
description: This command plays games
steps:
- echo Playing...
# subcommands
commands:
- name: hello
description: This command says Hello world
steps:
- echo Hello world
- name: ping
description: This command plays ping-pong
# If 'verbose' is set to 'true', atmos will output some info messages to the console before executing the command's steps
# If 'verbose' is not defined, it implicitly defaults to 'false'
verbose: true
steps:
- echo Playing ping-pong...
- echo pong
- name: show
description: Execute 'show' commands
# subcommands
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ settings:
terraform:
vars: {}

backend_type: s3 # s3, remote, vault, static, azurerm, gcs, cloud
backend_type: s3 # s3, remote, vault, azurerm, gcs, cloud
backend:
s3:
encrypt: true
Expand Down
2 changes: 1 addition & 1 deletion examples/tests/stacks/orgs/cp/_defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ terraform:
region: "{{ .vars.region }}"
terraform_workspace: "{{ .workspace }}"

backend_type: s3 # s3, remote, vault, static, azurerm, gcs, cloud
backend_type: s3 # s3, remote, vault, azurerm, gcs, cloud

# https://developer.hashicorp.com/terraform/language/settings/backends/configuration
backend:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/google/go-github/v59 v59.0.0
github.com/google/uuid v1.6.0
github.com/hairyhenderson/gomplate/v3 v3.11.7
github.com/hashicorp/go-getter v1.7.3
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-20231204233900-a34142ec2a72
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -726,8 +726,8 @@ github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtng
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/hashicorp/go-getter v1.7.3 h1:bN2+Fw9XPFvOCjB0UOevFIMICZ7G2XSQHzfvLUyOM5E=
github.com/hashicorp/go-getter v1.7.3/go.mod h1:W7TalhMmbPmsSMdNjD0ZskARur/9GJ17cfHTRtXV744=
github.com/hashicorp/go-getter v1.7.4 h1:3yQjWuxICvSpYwqSayAdKRFcvBl1y/vogCxczWSmix0=
github.com/hashicorp/go-getter v1.7.4/go.mod h1:W7TalhMmbPmsSMdNjD0ZskARur/9GJ17cfHTRtXV744=
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
github.com/hashicorp/go-hclog v0.14.1/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ=
github.com/hashicorp/go-hclog v0.16.2/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ=
Expand Down
25 changes: 17 additions & 8 deletions internal/exec/atlantis_generate_repo_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ func ExecuteAtlantisGenerateRepoConfigCmd(cmd *cobra.Command, args []string) err

// If the flag `--affected-only=true` is passed, find the affected components and stacks
if affectedOnly {
cloneTargetRef, err := flags.GetBool("clone-target-ref")
if err != nil {
return err
}

return ExecuteAtlantisGenerateRepoConfigAffectedOnly(
cliConfig,
outputPath,
Expand All @@ -113,6 +118,7 @@ func ExecuteAtlantisGenerateRepoConfigCmd(cmd *cobra.Command, args []string) err
sshKeyPath,
sshKeyPassword,
verbose,
cloneTargetRef,
)
}

Expand All @@ -138,6 +144,7 @@ func ExecuteAtlantisGenerateRepoConfigAffectedOnly(
sshKeyPath string,
sshKeyPassword string,
verbose bool,
cloneTargetRef bool,
) error {
if repoPath != "" && (ref != "" || sha != "" || sshKeyPath != "" || sshKeyPassword != "") {
return errors.New("if the '--repo-path' flag is specified, the '--ref', '--sha', '--ssh-key' and '--ssh-key-password' flags can't be used")
Expand All @@ -146,10 +153,12 @@ func ExecuteAtlantisGenerateRepoConfigAffectedOnly(
var affected []schema.Affected
var err error

if repoPath == "" {
affected, err = ExecuteDescribeAffectedWithTargetRepoClone(cliConfig, ref, sha, sshKeyPath, sshKeyPassword, verbose, false)
} else {
if repoPath != "" {
affected, err = ExecuteDescribeAffectedWithTargetRepoPath(cliConfig, repoPath, verbose, false)
} else if cloneTargetRef {
affected, err = ExecuteDescribeAffectedWithTargetRefClone(cliConfig, ref, sha, sshKeyPath, sshKeyPassword, verbose, false)
} else {
affected, err = ExecuteDescribeAffectedWithTargetRefCheckout(cliConfig, ref, sha, verbose, false)
}

if err != nil {
Expand Down Expand Up @@ -319,6 +328,11 @@ func ExecuteAtlantisGenerateRepoConfig(
return err
}

// Base component is required to calculate terraform workspace for derived components
if terraformComponent != componentName {
context.BaseComponent = terraformComponent
}

configAndStacksInfo := schema.ConfigAndStacksInfo{
ComponentFromArg: componentName,
Stack: stackConfigFileName,
Expand All @@ -334,11 +348,6 @@ func ExecuteAtlantisGenerateRepoConfig(
}

// Calculate terraform workspace
// Base component is required to calculate terraform workspace for derived components
if terraformComponent != componentName {
context.BaseComponent = terraformComponent
}

workspace, err := BuildTerraformWorkspace(cliConfig, configAndStacksInfo)
if err != nil {
return err
Expand Down
14 changes: 11 additions & 3 deletions internal/exec/describe_affected.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,23 @@ func ExecuteDescribeAffectedCmd(cmd *cobra.Command, args []string) error {
return err
}

cloneTargetRef, err := flags.GetBool("clone-target-ref")
if err != nil {
return err
}

if repoPath != "" && (ref != "" || sha != "" || sshKeyPath != "" || sshKeyPassword != "") {
return errors.New("if the '--repo-path' flag is specified, the '--ref', '--sha', '--ssh-key' and '--ssh-key-password' flags can't be used")
}

var affected []schema.Affected
if repoPath == "" {
affected, err = ExecuteDescribeAffectedWithTargetRepoClone(cliConfig, ref, sha, sshKeyPath, sshKeyPassword, verbose, includeSpaceliftAdminStacks)
} else {

if repoPath != "" {
affected, err = ExecuteDescribeAffectedWithTargetRepoPath(cliConfig, repoPath, verbose, includeSpaceliftAdminStacks)
} else if cloneTargetRef {
affected, err = ExecuteDescribeAffectedWithTargetRefClone(cliConfig, ref, sha, sshKeyPath, sshKeyPassword, verbose, includeSpaceliftAdminStacks)
} else {
affected, err = ExecuteDescribeAffectedWithTargetRefCheckout(cliConfig, ref, sha, verbose, includeSpaceliftAdminStacks)
}

if err != nil {
Expand Down
Loading

0 comments on commit 2b85f6f

Please sign in to comment.