Skip to content

Commit 44157ac

Browse files
authored
Merge pull request #32 from BedeGaming/remote-state-casing
config: tweak remote_state bindings to be consistent with Terraform
2 parents 9b4443c + 6d4bab4 commit 44157ac

6 files changed

Lines changed: 41 additions & 39 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ lock = {
5959
}
6060
6161
# Configure Terragrunt to automatically store tfstate files in an S3 bucket
62-
remoteState = {
62+
remote_state = {
6363
backend = "s3"
64-
backendConfigs = {
64+
config {
6565
encrypt = "true"
6666
bucket = "my-bucket"
6767
key = "terraform.tfstate"
@@ -214,9 +214,9 @@ docs](https://www.terraform.io/docs/state/remote/) for the requirements to use a
214214
For remote state management, Terragrunt supports the following settings in `.terragrunt`:
215215

216216
```hcl
217-
remoteState = {
217+
remote_state = {
218218
backend = "s3"
219-
backendConfigs = {
219+
config {
220220
key1 = "value1"
221221
key2 = "value2"
222222
key3 = "value3"

config/config.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ type TerragruntConfig struct {
1919

2020
// terragruntConfigFile represents the configuration supported in the .terragrunt file
2121
type terragruntConfigFile struct {
22-
Lock *LockConfig `json:"lock,omitempty"`
23-
RemoteState *remote.RemoteState
22+
Lock *LockConfig `hcl:"lock,omitempty"`
23+
RemoteState *remote.RemoteState `hcl:"remote_state"`
2424
}
2525

2626
// LockConfig represents generic configuration for Lock providers
2727
type LockConfig struct {
28-
Backend string `json:"backend"`
29-
Config map[string]string `json:"config"`
28+
Backend string `hcl:"backend"`
29+
Config map[string]string `hcl:"config"`
3030
}
3131

3232
// ReadTerragruntConfig the Terragrunt config file from its default location

config/config_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func TestParseTerragruntConfigRemoteStateMinimalConfig(t *testing.T) {
8585

8686
config :=
8787
`
88-
remoteState = {
88+
remote_state = {
8989
backend = "s3"
9090
}
9191
`
@@ -96,15 +96,15 @@ func TestParseTerragruntConfigRemoteStateMinimalConfig(t *testing.T) {
9696
assert.Nil(t, terragruntConfig.Lock)
9797
assert.NotNil(t, terragruntConfig.RemoteState)
9898
assert.Equal(t, "s3", terragruntConfig.RemoteState.Backend)
99-
assert.Empty(t, terragruntConfig.RemoteState.BackendConfigs)
99+
assert.Empty(t, terragruntConfig.RemoteState.Config)
100100
}
101101

102102
func TestParseTerragruntConfigRemoteStateMissingBackend(t *testing.T) {
103103
t.Parallel()
104104

105105
config :=
106106
`
107-
remoteState = {
107+
remote_state = {
108108
}
109109
`
110110

@@ -117,9 +117,9 @@ func TestParseTerragruntConfigRemoteStateFullConfig(t *testing.T) {
117117

118118
config :=
119119
`
120-
remoteState = {
120+
remote_state = {
121121
backend = "s3"
122-
backendConfigs = {
122+
config = {
123123
encrypt = "true"
124124
bucket = "my-bucket"
125125
key = "terraform.tfstate"
@@ -134,11 +134,11 @@ func TestParseTerragruntConfigRemoteStateFullConfig(t *testing.T) {
134134
assert.Nil(t, terragruntConfig.Lock)
135135
assert.NotNil(t, terragruntConfig.RemoteState)
136136
assert.Equal(t, "s3", terragruntConfig.RemoteState.Backend)
137-
assert.NotEmpty(t, terragruntConfig.RemoteState.BackendConfigs)
138-
assert.Equal(t, "true", terragruntConfig.RemoteState.BackendConfigs["encrypt"])
139-
assert.Equal(t, "my-bucket", terragruntConfig.RemoteState.BackendConfigs["bucket"])
140-
assert.Equal(t, "terraform.tfstate", terragruntConfig.RemoteState.BackendConfigs["key"])
141-
assert.Equal(t, "us-east-1", terragruntConfig.RemoteState.BackendConfigs["region"])
137+
assert.NotEmpty(t, terragruntConfig.RemoteState.Config)
138+
assert.Equal(t, "true", terragruntConfig.RemoteState.Config["encrypt"])
139+
assert.Equal(t, "my-bucket", terragruntConfig.RemoteState.Config["bucket"])
140+
assert.Equal(t, "terraform.tfstate", terragruntConfig.RemoteState.Config["key"])
141+
assert.Equal(t, "us-east-1", terragruntConfig.RemoteState.Config["region"])
142142
}
143143

144144
func TestParseTerragruntConfigRemoteStateAndDynamoDbFullConfig(t *testing.T) {
@@ -156,9 +156,9 @@ func TestParseTerragruntConfigRemoteStateAndDynamoDbFullConfig(t *testing.T) {
156156
}
157157
}
158158
159-
remoteState = {
159+
remote_state = {
160160
backend = "s3"
161-
backendConfigs = {
161+
config {
162162
encrypt = "true"
163163
bucket = "my-bucket"
164164
key = "terraform.tfstate"
@@ -180,11 +180,11 @@ func TestParseTerragruntConfigRemoteStateAndDynamoDbFullConfig(t *testing.T) {
180180

181181
assert.NotNil(t, terragruntConfig.RemoteState)
182182
assert.Equal(t, "s3", terragruntConfig.RemoteState.Backend)
183-
assert.NotEmpty(t, terragruntConfig.RemoteState.BackendConfigs)
184-
assert.Equal(t, "true", terragruntConfig.RemoteState.BackendConfigs["encrypt"])
185-
assert.Equal(t, "my-bucket", terragruntConfig.RemoteState.BackendConfigs["bucket"])
186-
assert.Equal(t, "terraform.tfstate", terragruntConfig.RemoteState.BackendConfigs["key"])
187-
assert.Equal(t, "us-east-1", terragruntConfig.RemoteState.BackendConfigs["region"])
183+
assert.NotEmpty(t, terragruntConfig.RemoteState.Config)
184+
assert.Equal(t, "true", terragruntConfig.RemoteState.Config["encrypt"])
185+
assert.Equal(t, "my-bucket", terragruntConfig.RemoteState.Config["bucket"])
186+
assert.Equal(t, "terraform.tfstate", terragruntConfig.RemoteState.Config["key"])
187+
assert.Equal(t, "us-east-1", terragruntConfig.RemoteState.Config["region"])
188188
}
189189

190190
func TestParseTerragruntConfigInvalidLockBackend(t *testing.T) {

remote/remote_state.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
package remote
22

33
import (
4-
"github.com/gruntwork-io/terragrunt/util"
5-
"github.com/gruntwork-io/terragrunt/shell"
64
"fmt"
5+
76
"github.com/gruntwork-io/terragrunt/errors"
7+
"github.com/gruntwork-io/terragrunt/shell"
8+
"github.com/gruntwork-io/terragrunt/util"
89
)
910

1011
// Configuration for Terraform remote state
1112
type RemoteState struct {
12-
Backend string
13-
BackendConfigs map[string]string
13+
Backend string `hcl:"backend"`
14+
Config map[string]string `hcl:"config"`
1415
}
1516

1617
// Fill in any default configuration for remote state
@@ -79,12 +80,12 @@ func (remoteState RemoteState) toTerraformRemoteConfigArgs() []string {
7980
baseArgs := []string{"remote", "config", "-backend", remoteState.Backend}
8081

8182
backendConfigArgs := []string{}
82-
for key, value := range remoteState.BackendConfigs {
83+
for key, value := range remoteState.Config {
8384
arg := fmt.Sprintf("-backend-config=%s=%s", key, value)
8485
backendConfigArgs = append(backendConfigArgs, arg)
8586
}
8687

8788
return append(baseArgs, backendConfigArgs...)
8889
}
8990

90-
var RemoteBackendMissing = fmt.Errorf("The remoteState.backend field cannot be empty")
91+
var RemoteBackendMissing = fmt.Errorf("The remoteState.backend field cannot be empty")

remote/remote_state_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
package remote
22

33
import (
4+
"strings"
45
"testing"
6+
57
"github.com/stretchr/testify/assert"
6-
"strings"
78
)
89

910
func TestToTerraformRemoteConfigArgs(t *testing.T) {
1011
t.Parallel()
1112

1213
remoteState := RemoteState{
1314
Backend: "s3",
14-
BackendConfigs: map[string]string {
15+
Config: map[string]string{
1516
"encrypt": "true",
16-
"bucket": "my-bucket",
17-
"key": "terraform.tfstate",
18-
"region": "us-east-1",
17+
"bucket": "my-bucket",
18+
"key": "terraform.tfstate",
19+
"region": "us-east-1",
1920
},
2021
}
2122
args := remoteState.toTerraformRemoteConfigArgs()
@@ -39,4 +40,4 @@ func assertRemoteConfigArgsEqual(t *testing.T, actualArgs []string, expectedArgs
3940
for _, expectedArg := range expected {
4041
assert.Contains(t, actualArgs, expectedArg)
4142
}
42-
}
43+
}

test/fixture/.terragrunt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ lock = {
1010
}
1111

1212
# Configure Terragrunt to automatically store tfstate files in an S3 bucket
13-
remoteState = {
13+
remote_state = {
1414
backend = "s3"
15-
backendConfigs = {
15+
config {
1616
encrypt = "true"
1717
bucket = "gruntwork-terragrunt-tests"
1818
key = "terraform.tfstate"

0 commit comments

Comments
 (0)