Skip to content

Commit

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

* updates
  • Loading branch information
aknysh authored Jun 25, 2024
1 parent 2290855 commit ff192f3
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 16 deletions.
2 changes: 1 addition & 1 deletion examples/quick-start/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ARG GEODESIC_OS=debian
# https://atmos.tools/
# https://github.com/cloudposse/atmos
# https://github.com/cloudposse/atmos/releases
ARG ATMOS_VERSION=1.82.0
ARG ATMOS_VERSION=1.83.0

# Terraform: https://github.com/hashicorp/terraform/releases
ARG TF_VERSION=1.8.5
Expand Down
4 changes: 4 additions & 0 deletions examples/quick-start/stacks/catalog/vpc/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ components:
# Point to the Terraform component
component: vpc
settings:
# The `vpc` component depends on the `vpc-flow-logs-bucket` component in the same stack
depends_on:
1:
component: "vpc-flow-logs-bucket"
# Validation
# Supports JSON Schema and OPA policies
# All validation steps must succeed to allow the component to be provisioned
Expand Down
2 changes: 1 addition & 1 deletion internal/exec/atmos.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func ExecuteAtmosCmd() error {
}

if selectedCommand == "describe dependents" {
data, err := ExecuteDescribeDependents(cliConfig, selectedComponent, selectedStack)
data, err := ExecuteDescribeDependents(cliConfig, selectedComponent, selectedStack, false)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/exec/describe_affected.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func ExecuteDescribeAffectedCmd(cmd *cobra.Command, args []string) error {

// Add dependent components and stacks for each affected component
if len(affected) > 0 && includeDependents {
err = addDependentsToAffected(cliConfig, &affected)
err = addDependentsToAffected(cliConfig, &affected, includeSettings)
if err != nil {
return err
}
Expand Down
20 changes: 14 additions & 6 deletions internal/exec/describe_affected_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1491,18 +1491,22 @@ func addAffectedSpaceliftAdminStack(
}

// addDependentsToAffected adds dependent components and stacks to each affected component
func addDependentsToAffected(cliConfig schema.CliConfiguration, affected *[]schema.Affected) error {
func addDependentsToAffected(
cliConfig schema.CliConfiguration,
affected *[]schema.Affected,
includeSettings bool,
) error {
for i := 0; i < len(*affected); i++ {
a := &(*affected)[i]

deps, err := ExecuteDescribeDependents(cliConfig, a.Component, a.Stack)
deps, err := ExecuteDescribeDependents(cliConfig, a.Component, a.Stack, includeSettings)
if err != nil {
return err
}

if len(deps) > 0 {
a.Dependents = deps
err = addDependentsToDependents(cliConfig, &deps)
err = addDependentsToDependents(cliConfig, &deps, includeSettings)
if err != nil {
return err
}
Expand All @@ -1516,18 +1520,22 @@ func addDependentsToAffected(cliConfig schema.CliConfiguration, affected *[]sche
}

// addDependentsToDependents recursively adds dependent components and stacks to each dependent component
func addDependentsToDependents(cliConfig schema.CliConfiguration, dependents *[]schema.Dependent) error {
func addDependentsToDependents(
cliConfig schema.CliConfiguration,
dependents *[]schema.Dependent,
includeSettings bool,
) error {
for i := 0; i < len(*dependents); i++ {
d := &(*dependents)[i]

deps, err := ExecuteDescribeDependents(cliConfig, d.Component, d.Stack)
deps, err := ExecuteDescribeDependents(cliConfig, d.Component, d.Stack, includeSettings)
if err != nil {
return err
}

if len(deps) > 0 {
d.Dependents = deps
err = addDependentsToDependents(cliConfig, &deps)
err = addDependentsToDependents(cliConfig, &deps, includeSettings)
if err != nil {
return err
}
Expand Down
8 changes: 6 additions & 2 deletions internal/exec/describe_dependents.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func ExecuteDescribeDependentsCmd(cmd *cobra.Command, args []string) error {

component := args[0]

dependents, err := ExecuteDescribeDependents(cliConfig, component, stack)
dependents, err := ExecuteDescribeDependents(cliConfig, component, stack, false)
if err != nil {
return err
}
Expand All @@ -71,6 +71,7 @@ func ExecuteDescribeDependents(
cliConfig schema.CliConfiguration,
component string,
stack string,
includeSettings bool,
) ([]schema.Dependent, error) {

dependents := []schema.Dependent{}
Expand Down Expand Up @@ -235,7 +236,6 @@ func ExecuteDescribeDependents(

// Add Spacelift stack and Atlantis project if they are configured for the dependent stack component
if stackComponentType == "terraform" {

// Spacelift stack
configAndStacksInfo := schema.ConfigAndStacksInfo{
ComponentFromArg: stackComponentName,
Expand All @@ -262,6 +262,10 @@ func ExecuteDescribeDependents(
dependent.AtlantisProject = atlantisProjectName
}

if includeSettings {
dependent.Settings = stackComponentSettingsSection
}

dependents = append(dependents, dependent)
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/describe/describe_dependents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestDescribeDependents(t *testing.T) {
component := "test/test-component"
stack := "tenant1-ue2-test-1"

dependents, err := e.ExecuteDescribeDependents(cliConfig, component, stack)
dependents, err := e.ExecuteDescribeDependents(cliConfig, component, stack, false)
assert.Nil(t, err)
assert.Equal(t, 1, len(dependents))

Expand All @@ -38,7 +38,7 @@ func TestDescribeDependents2(t *testing.T) {
component := "test/test-component"
stack := "tenant1-ue2-dev"

dependents, err := e.ExecuteDescribeDependents(cliConfig, component, stack)
dependents, err := e.ExecuteDescribeDependents(cliConfig, component, stack, false)
assert.Nil(t, err)
assert.Equal(t, 4, len(dependents))

Expand Down
3 changes: 2 additions & 1 deletion pkg/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,8 @@ type Dependent struct {
StackSlug string `yaml:"stack_slug" json:"stack_slug" mapstructure:"stack_slug"`
SpaceliftStack string `yaml:"spacelift_stack,omitempty" json:"spacelift_stack,omitempty" mapstructure:"spacelift_stack"`
AtlantisProject string `yaml:"atlantis_project,omitempty" json:"atlantis_project,omitempty" mapstructure:"atlantis_project"`
Dependents []Dependent `yaml:"dependents,omitempty" json:"dependents,omitempty" mapstructure:"dependents"`
Dependents []Dependent `yaml:"dependents" json:"dependents" mapstructure:"dependents"`
Settings map[any]any `yaml:"settings" json:"settings" mapstructure:"settings"`
}

// Settings
Expand Down
2 changes: 1 addition & 1 deletion website/docs/integrations/atlantis.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ on:
branches: [ main ]
env:
ATMOS_VERSION: 1.82.0
ATMOS_VERSION: 1.83.0
ATMOS_CLI_CONFIG_PATH: ./
jobs:
Expand Down
2 changes: 1 addition & 1 deletion website/docs/integrations/github-actions/setup-atmos.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ jobs:
uses: cloudposse/github-action-setup-atmos
with:
# Make sure to pin to the latest version of atmos
atmos_version: 1.82.0
atmos_version: 1.83.0
```
</File>

0 comments on commit ff192f3

Please sign in to comment.