Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update atmos describe affected command. Update docs #590

Merged
merged 39 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
cec81be
updates
aknysh Feb 16, 2024
1af26aa
Merge remote-tracking branch 'origin/master' into add-generate
aknysh Apr 15, 2024
58b324c
Merge remote-tracking branch 'origin/master' into add-generate
aknysh Apr 20, 2024
f293ef5
updates
aknysh Apr 21, 2024
abd0a22
updates
aknysh Apr 23, 2024
e75c388
Merge remote-tracking branch 'origin/master' into add-generate
aknysh Apr 24, 2024
0b7281b
updates
aknysh Apr 24, 2024
228fc52
updates
aknysh Apr 25, 2024
f81a289
updates
aknysh Apr 25, 2024
1a7db65
updates
aknysh Apr 25, 2024
d6f2121
updates
aknysh Apr 25, 2024
185aeee
updates
aknysh Apr 25, 2024
882e98f
updates
aknysh Apr 25, 2024
eaf64aa
updates
aknysh Apr 25, 2024
06ffa7f
updates
aknysh Apr 25, 2024
7125c88
updates
aknysh Apr 25, 2024
94c8db7
updates
aknysh Apr 25, 2024
5c369bd
updates
aknysh Apr 25, 2024
24fd13f
updates
aknysh Apr 25, 2024
0200ddc
updates
aknysh Apr 25, 2024
18b6564
updates
aknysh Apr 25, 2024
d289664
updates
aknysh Apr 25, 2024
f0ad83d
updates
aknysh Apr 25, 2024
f4c1142
updates
aknysh Apr 25, 2024
16b1ea2
updates
aknysh Apr 26, 2024
a12d879
updates
aknysh Apr 27, 2024
6f5cd70
updates
aknysh Apr 28, 2024
c07fbbf
updates
aknysh Apr 29, 2024
9902c1e
updates
aknysh Apr 29, 2024
f55db7a
updates
aknysh Apr 29, 2024
7115962
updates
aknysh Apr 29, 2024
d9bc1b9
updates
aknysh Apr 29, 2024
7b4cb8d
updates
aknysh Apr 29, 2024
014e976
updates
aknysh Apr 29, 2024
3fd55ce
updates
aknysh Apr 29, 2024
fa0301c
updates
aknysh Apr 29, 2024
ff5f70c
Apply suggestions from code review
aknysh Apr 30, 2024
2473cbd
Add Google Tag Manager
aknysh Apr 30, 2024
ed9b668
Merge remote-tracking branch 'origin/add-generate' into add-generate
aknysh Apr 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading