Skip to content

Commit de7da5b

Browse files
authored
Update remote-state module (#66)
1 parent f302b85 commit de7da5b

9 files changed

Lines changed: 472 additions & 90 deletions

File tree

.github/workflows/release-branch.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010
- 'docs/**'
1111
- 'examples/**'
1212
- 'test/**'
13+
- 'README.*'
1314

1415
permissions:
1516
contents: write

.github/workflows/release-published.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ permissions:
1111

1212
jobs:
1313
terraform-module:
14-
uses: cloudposse/github-actions-workflows-terraform-module/.github/workflows/release.yml@main
14+
uses: cloudposse/github-actions-workflows-terraform-module/.github/workflows/release-published.yml@main

examples/remote-state/main.tf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,24 @@ module "remote_state_using_context_ignore_errors" {
6565

6666
context = module.this.context
6767
}
68+
69+
module "remote_state_with_bypass" {
70+
source = "../../modules/remote-state"
71+
72+
bypass = true
73+
74+
defaults = {
75+
default_output = "default-value"
76+
}
77+
78+
component = "test/test-component-override"
79+
namespace = ""
80+
tenant = "tenant1"
81+
environment = "ue2"
82+
stage = "dev"
83+
84+
atmos_cli_config_path = var.atmos_cli_config_path
85+
atmos_base_path = var.atmos_base_path
86+
87+
context = module.this.context
88+
}

examples/remote-state/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ output "remote_state_using_context_ignore_errors" {
1212
value = module.remote_state_using_context_ignore_errors.outputs
1313
description = "Component remote state using wrong component. Errors are ignored in the 'utils' provider"
1414
}
15+
16+
output "remote_state_with_bypass" {
17+
value = module.remote_state_with_bypass.outputs
18+
description = "Component remote state with 'bypass' set to 'true'"
19+
}
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,11 @@ locals {
8383

8484
} # ds_configurations
8585

86-
8786
}
8887

89-
# Due to issues like
90-
# - https://github.com/hashicorp/terraform/issues/32023
91-
# - https://github.com/hashicorp/terraform/issues/27849
92-
# we want to avoid using `count` to enable or disable the data source,
93-
# so instead we use a dummy remote state (a local file) when otherwise
94-
# we would disable the data source via `count = 0`.
9588
data "terraform_remote_state" "data_source" {
89+
count = var.bypass ? 0 : 1
90+
9691
backend = local.ds_backend
9792
workspace = local.ds_workspace
9893
config = local.ds_configurations[local.ds_backend]

modules/remote-state/main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
data "utils_component_config" "config" {
2+
count = var.bypass ? 0 : 1
3+
24
component = var.component
35
stack = var.stack
46
namespace = module.always.namespace
@@ -12,7 +14,7 @@ data "utils_component_config" "config" {
1214
}
1315

1416
locals {
15-
config = yamldecode(data.utils_component_config.config.output)
17+
config = try(yamldecode(data.utils_component_config.config[0].output), {})
1618

1719
remote_state_backend_type = try(local.config.remote_state_backend_type, "")
1820
backend_type = try(coalesce(local.remote_state_backend_type, local.config.backend_type), "")
@@ -31,12 +33,10 @@ locals {
3133
workspace = lookup(local.config, "workspace", "")
3234
workspace_key_prefix = lookup(local.backend, "workspace_key_prefix", null)
3335

34-
remote_state_enabled = !var.bypass
35-
3636
remote_states = {
3737
# s3 = data.terraform_remote_state.s3
3838
# remote = data.terraform_remote_state.remote
39-
data_source = try(data.terraform_remote_state.data_source.outputs, var.defaults)
39+
data_source = try(data.terraform_remote_state.data_source[0].outputs, var.defaults)
4040
bypass = var.defaults
4141
static = local.backend
4242
}

test/src/examples_remote_state_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ func TestExamplesRemoteState(t *testing.T) {
2828

2929
terraform.OutputStruct(t, terraformOptions, "remote_state_using_stack", &output)
3030
remoteStateUsingStack := output.(map[string]any)
31-
3231
// Verify we're getting back the outputs we expect
3332
assert.NotNilf(t, remoteStateUsingStack, "remote state is empty")
3433
assert.Equal(t, true, remoteStateUsingStack["val1"])
@@ -38,7 +37,6 @@ func TestExamplesRemoteState(t *testing.T) {
3837

3938
terraform.OutputStruct(t, terraformOptions, "remote_state_using_context", &output)
4039
remoteStateUsingContext := output.(map[string]any)
41-
4240
// Verify we're getting back the outputs we expect
4341
assert.NotNilf(t, remoteStateUsingContext, "remote state is empty")
4442
assert.Equal(t, true, remoteStateUsingContext["val1"])
@@ -48,8 +46,13 @@ func TestExamplesRemoteState(t *testing.T) {
4846

4947
terraform.OutputStruct(t, terraformOptions, "remote_state_using_context_ignore_errors", &output)
5048
remoteStateUsingContextIgnoreErrors := output.(map[string]any)
51-
5249
// Verify we're getting back the outputs we expect
5350
assert.NotNilf(t, remoteStateUsingContextIgnoreErrors, "remote state is empty")
5451
assert.Equal(t, "default-value", remoteStateUsingContextIgnoreErrors["default_output"])
52+
53+
terraform.OutputStruct(t, terraformOptions, "remote_state_with_bypass", &output)
54+
remoteStateWithBypass := output.(map[string]any)
55+
// Verify we're getting back the outputs we expect
56+
assert.NotNilf(t, remoteStateWithBypass, "remote state is empty")
57+
assert.Equal(t, "default-value", remoteStateWithBypass["default_output"])
5558
}

test/src/go.mod

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,59 @@
11
module github.com/cloudposse/terraform-yaml-stack-config
22

3-
go 1.19
3+
go 1.20
44

55
require (
6-
github.com/gruntwork-io/terratest v0.41.10
7-
github.com/stretchr/testify v1.8.1
6+
github.com/gruntwork-io/terratest v0.43.0
7+
github.com/stretchr/testify v1.8.4
88
)
99

1010
require (
11-
cloud.google.com/go v0.83.0 // indirect
12-
cloud.google.com/go/storage v1.10.0 // indirect
11+
cloud.google.com/go v0.105.0 // indirect
12+
cloud.google.com/go/compute v1.12.1 // indirect
13+
cloud.google.com/go/compute/metadata v0.2.1 // indirect
14+
cloud.google.com/go/iam v0.7.0 // indirect
15+
cloud.google.com/go/storage v1.27.0 // indirect
1316
github.com/agext/levenshtein v1.2.3 // indirect
1417
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
15-
github.com/aws/aws-sdk-go v1.40.56 // indirect
18+
github.com/aws/aws-sdk-go v1.44.122 // indirect
1619
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
1720
github.com/davecgh/go-spew v1.1.1 // indirect
18-
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
19-
github.com/golang/protobuf v1.5.2 // indirect
20-
github.com/golang/snappy v0.0.3 // indirect
21-
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
21+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
22+
github.com/golang/protobuf v1.5.3 // indirect
23+
github.com/google/go-cmp v0.5.9 // indirect
24+
github.com/google/uuid v1.3.0 // indirect
25+
github.com/googleapis/enterprise-certificate-proxy v0.2.0 // indirect
26+
github.com/googleapis/gax-go/v2 v2.7.0 // indirect
2227
github.com/hashicorp/errwrap v1.0.0 // indirect
2328
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
24-
github.com/hashicorp/go-getter v1.6.1 // indirect
29+
github.com/hashicorp/go-getter v1.7.1 // indirect
2530
github.com/hashicorp/go-multierror v1.1.0 // indirect
2631
github.com/hashicorp/go-safetemp v1.0.0 // indirect
27-
github.com/hashicorp/go-version v1.3.0 // indirect
32+
github.com/hashicorp/go-version v1.6.0 // indirect
2833
github.com/hashicorp/hcl/v2 v2.9.1 // indirect
2934
github.com/hashicorp/terraform-json v0.13.0 // indirect
3035
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a // indirect
3136
github.com/jmespath/go-jmespath v0.4.0 // indirect
32-
github.com/jstemmer/go-junit-report v0.9.1 // indirect
33-
github.com/klauspost/compress v1.13.0 // indirect
37+
github.com/klauspost/compress v1.15.11 // indirect
3438
github.com/mattn/go-zglob v0.0.2-0.20190814121620-e3c945676326 // indirect
3539
github.com/mitchellh/go-homedir v1.1.0 // indirect
36-
github.com/mitchellh/go-testing-interface v1.0.0 // indirect
40+
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
3741
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
3842
github.com/pmezard/go-difflib v1.0.0 // indirect
3943
github.com/tmccombs/hcl2json v0.3.3 // indirect
40-
github.com/ulikunitz/xz v0.5.8 // indirect
44+
github.com/ulikunitz/xz v0.5.10 // indirect
4145
github.com/zclconf/go-cty v1.9.1 // indirect
42-
go.opencensus.io v0.23.0 // indirect
43-
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a // indirect
44-
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
45-
golang.org/x/mod v0.4.2 // indirect
46-
golang.org/x/net v0.0.0-20210614182718-04defd469f4e // indirect
47-
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c // indirect
48-
golang.org/x/sys v0.0.0-20220517195934-5e4e11fc645e // indirect
49-
golang.org/x/text v0.3.6 // indirect
50-
golang.org/x/tools v0.1.2 // indirect
51-
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
52-
google.golang.org/api v0.47.0 // indirect
46+
go.opencensus.io v0.24.0 // indirect
47+
golang.org/x/crypto v0.1.0 // indirect
48+
golang.org/x/net v0.8.0 // indirect
49+
golang.org/x/oauth2 v0.1.0 // indirect
50+
golang.org/x/sys v0.6.0 // indirect
51+
golang.org/x/text v0.8.0 // indirect
52+
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
53+
google.golang.org/api v0.103.0 // indirect
5354
google.golang.org/appengine v1.6.7 // indirect
54-
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect
55-
google.golang.org/grpc v1.38.0 // indirect
56-
google.golang.org/protobuf v1.26.0 // indirect
55+
google.golang.org/genproto v0.0.0-20221201164419-0e50fba7f41c // indirect
56+
google.golang.org/grpc v1.51.0 // indirect
57+
google.golang.org/protobuf v1.28.1 // indirect
5758
gopkg.in/yaml.v3 v3.0.1 // indirect
5859
)

0 commit comments

Comments
 (0)