-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added global and site-level variables (#445)
<!-- Describe in detail the changes you are proposing, and the rationale. --> <!-- Link all GitHub issues fixed by this PR, and add references to prior related PRs. --> Fixes #322 ### NEW FEATURES | UPGRADE NOTES | ENHANCEMENTS | BUG FIXES | EXPERIMENTS <!-- Write a short description of your changes. Examples: - Adds option to set global and site-level variables that will be merged into components by key --> -
- Loading branch information
Showing
17 changed files
with
314 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
kind: Added | ||
body: Added option to set global and site-level configurations. These will be merged | ||
into the component variables during generation | ||
time: 2024-09-10T15:41:31.371358062+02:00 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
internal/cmd/testdata/cases/generate/with-variables/expected/main/test-1/main.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# This file is auto-generated by MACH composer | ||
# site: test-1 | ||
terraform { | ||
backend "local" { | ||
path = "./states/test-1.tfstate" | ||
} | ||
required_providers { | ||
aws = { | ||
version = "~> 3.74.1" | ||
} | ||
} | ||
} | ||
|
||
# File sources | ||
# Resources | ||
# Configuring AWS | ||
provider "aws" { | ||
region = "eu-west-1" | ||
} | ||
|
||
locals { | ||
tags = { | ||
Site = "test-1" | ||
Environment = "test" | ||
} | ||
} | ||
|
||
# Component: component | ||
module "component" { | ||
source = "{{ .PWD }}/testdata/modules/application" | ||
variables = { | ||
component_variable = "component_variable_value" | ||
global_variable = "global_variable_value" | ||
site_variable = "site_variable_value" | ||
} | ||
secrets = { | ||
component_secret = "component_secret_value" | ||
global_secret = "global_secret_value" | ||
site_secret = "site_secret_value" | ||
} | ||
component_version = "test" | ||
environment = "test" | ||
site = "test-1" | ||
tags = local.tags | ||
providers = { | ||
aws = aws, | ||
} | ||
} | ||
|
||
output "component" { | ||
description = "The module outputs for component" | ||
sensitive = true | ||
value = module.component | ||
} |
49 changes: 49 additions & 0 deletions
49
internal/cmd/testdata/cases/generate/with-variables/main.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
mach_composer: | ||
version: 1 | ||
plugins: | ||
aws: | ||
source: mach-composer/aws | ||
version: 0.1.0 | ||
|
||
global: | ||
cloud: "aws" | ||
environment: test | ||
terraform_config: | ||
remote_state: | ||
plugin: local | ||
path: ./states | ||
variables: | ||
global_variable: "global_variable_value" | ||
site_variable: "overridden_site_variable_value" | ||
component_variable: "overridden_component_variable_value" | ||
secrets: | ||
global_secret: "global_secret_value" | ||
site_secret: "overridden_site_secret_value" | ||
component_secret: "overridden_component_secret_value" | ||
|
||
sites: | ||
- identifier: test-1 | ||
variables: | ||
site_variable: "site_variable_value" | ||
component_variable: "overridden_component_variable_value" | ||
secrets: | ||
site_secret: "site_secret_value" | ||
component_secret: "overridden_component_secret_value" | ||
aws: | ||
account_id: "12345" | ||
region: eu-west-1 | ||
components: | ||
- name: component | ||
variables: | ||
component_variable: "component_variable_value" | ||
secrets: | ||
component_secret: "component_secret_value" | ||
|
||
components: | ||
- name: component | ||
source: ./testdata/modules/application | ||
version: "test" | ||
branch: main | ||
integrations: | ||
- aws | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package variable | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestMergeVariablesMaps(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
maps []VariablesMap | ||
expected VariablesMap | ||
}{ | ||
{ | ||
name: "merge two maps with different keys", | ||
maps: []VariablesMap{ | ||
{"key1": MustCreateNewScalarVariable("value1")}, | ||
{"key2": MustCreateNewScalarVariable("value2")}, | ||
}, | ||
expected: VariablesMap{ | ||
"key1": MustCreateNewScalarVariable("value1"), | ||
"key2": MustCreateNewScalarVariable("value2"), | ||
}, | ||
}, | ||
{ | ||
name: "merge two maps with same keys", | ||
maps: []VariablesMap{ | ||
{"key1": MustCreateNewScalarVariable("value1")}, | ||
{"key1": MustCreateNewScalarVariable("value2")}, | ||
}, | ||
expected: VariablesMap{ | ||
"key1": MustCreateNewScalarVariable("value2"), | ||
}, | ||
}, | ||
{ | ||
name: "merge three maps with same keys", | ||
maps: []VariablesMap{ | ||
{"key1": MustCreateNewScalarVariable("value1")}, | ||
{"key2": MustCreateNewScalarVariable("value2")}, | ||
{"key1": MustCreateNewScalarVariable("value3")}, | ||
}, | ||
expected: VariablesMap{ | ||
"key1": MustCreateNewScalarVariable("value3"), | ||
"key2": MustCreateNewScalarVariable("value2"), | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
result := MergeVariablesMaps(tc.maps...) | ||
assert.Equal(t, tc.expected, result) | ||
}) | ||
} | ||
} |
Oops, something went wrong.