Skip to content

Commit

Permalink
fix: Move force_path_style to use_path_style
Browse files Browse the repository at this point in the history
As per the documentation linked below the force_path_style option is now
deprecated and should be changed to use_path_style.

https://developer.hashicorp.com/terraform/language/backend/s3#force_path_style

As per the comments in #3472 I have made this PR to support both options
but commented the code and the documentation to indicate that the old
option is now deprecated
  • Loading branch information
lazzurs committed Oct 27, 2024
1 parent 98a8874 commit 2d7a8e6
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ For the `s3` backend, the following config options can be used for S3-compatible

**Note**: The `skip_bucket_accesslogging` is now DEPRECATED. It is replaced by `accesslogging_bucket_name`. Please read below for more details on when to use the new config option.

**Note**: The `force_path_style` is now DEPRECATED. It is replaced by `use_path_style`. Please read below for more details on when to use the new config option.

``` hcl
remote_state {
# ...
Expand All @@ -245,7 +247,7 @@ remote_state {
shared_credentials_file = "/path/to/credentials/file"
skip_metadata_api_check = true
force_path_style = true
use_path_style = true
}
}
```
Expand Down
17 changes: 14 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,9 @@ golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
Expand Down Expand Up @@ -1292,7 +1295,8 @@ golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
golang.org/x/net v0.0.0-20170114055629-f2499483f923/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -1357,6 +1361,8 @@ golang.org/x/net v0.0.0-20221002022538-bcab6841153b/go.mod h1:YDH+HFinaLZZlnHAfS
golang.org/x/net v0.0.0-20221014081412-f15817d10f9b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
Expand Down Expand Up @@ -1490,6 +1496,8 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
Expand All @@ -1500,6 +1508,9 @@ golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuX
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
golang.org/x/term v0.23.0 h1:F6D4vR+EHoL9/sWAWgAR1H2DcHr4PareCbAaCo1RpuU=
golang.org/x/term v0.23.0/go.mod h1:DgV24QBUrK6jhZXl+20l6UWznPlwAHm1Q1mGHtydmSk=
golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24=
golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M=
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand All @@ -1514,8 +1525,8 @@ golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down
4 changes: 3 additions & 1 deletion remote/remote_state_s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ type RemoteStateConfigS3 struct {
LockTable string `mapstructure:"lock_table"` // Deprecated in Terraform version 0.13 or newer.
DynamoDBTable string `mapstructure:"dynamodb_table"`
CredsFilename string `mapstructure:"shared_credentials_file"`
S3ForcePathStyle bool `mapstructure:"force_path_style"`
S3ForcePathStyle bool `mapstructure:"force_path_style"` // Deprecated in Terraform version 1.6 or newer.
S3UsePathStyle bool `mapstructure:"use_path_style"`
AssumeRole RemoteStateConfigS3AssumeRole `mapstructure:"assume_role"`
}

Expand All @@ -132,6 +133,7 @@ func (c *ExtendedRemoteStateConfigS3) GetAwsSessionConfig() *awshelper.AwsSessio
SessionName: c.RemoteStateConfigS3.GetSessionName(),
CredsFilename: c.RemoteStateConfigS3.CredsFilename,
S3ForcePathStyle: c.RemoteStateConfigS3.S3ForcePathStyle,
S3UsePathStyle: c.RemoteStateConfigS3.S3UsePathStyle,
DisableComputeChecksums: c.DisableAWSClientChecksums,
}
}
Expand Down
56 changes: 52 additions & 4 deletions remote/remote_state_s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,55 @@ func TestAwsForcePathStyleClientSession(t *testing.T) {
s3Client, err := remote.CreateS3Client(s3ConfigExtended.GetAwsSessionConfig(), terragruntOptions)
require.NoError(t, err, "Unexpected error creating client for test: %v", err)

actual := aws.BoolValue(s3Client.Config.S3ForcePathStyle)
actual := aws.BoolValue(s3Client.Config.S3UsePathStyle)
assert.Equal(t, testCase.expected, actual)
})
}
}

func TestAwsUsePathStyleClientSession(t *testing.T) {
t.Parallel()

terragruntOptions, err := options.NewTerragruntOptionsForTest("s3_client_test")
require.NoError(t, err, "Unexpected error creating NewTerragruntOptionsForTest: %v", err)

testCases := []struct {
name string
config map[string]interface{}
expected bool
}{
{
"path-style-true",
map[string]interface{}{"use_path_style": true},
true,
},
{
"path-style-false",
map[string]interface{}{"use_path_style": false},
false,
},
{
"path-style-non-existent",
map[string]interface{}{},
false,
},
}

for _, testCase := range testCases {
// The following is necessary to make sure testCase's values don't
// get updated due to concurrency within the scope of t.Run(..) below
testCase := testCase

t.Run(testCase.name, func(t *testing.T) {
t.Parallel()

s3ConfigExtended, err := remote.ParseExtendedS3Config(testCase.config)
require.NoError(t, err, "Unexpected error parsing config for test: %v", err)

s3Client, err := remote.CreateS3Client(s3ConfigExtended.GetAwsSessionConfig(), terragruntOptions)
require.NoError(t, err, "Unexpected error creating client for test: %v", err)

actual := aws.BoolValue(s3Client.Config.S3UsePathStyle)
assert.Equal(t, testCase.expected, actual)
})
}
Expand All @@ -302,15 +350,15 @@ func TestAwsGetAwsSessionConfig(t *testing.T) {
}{
{
"all-values",
map[string]interface{}{"region": "foo", "endpoint": "bar", "profile": "baz", "role_arn": "arn::it", "shared_credentials_file": "my-file", "force_path_style": true},
map[string]interface{}{"region": "foo", "endpoint": "bar", "profile": "baz", "role_arn": "arn::it", "shared_credentials_file": "my-file", "use_path_style": true},
},
{
"no-values",
map[string]interface{}{},
},
{
"extra-values",
map[string]interface{}{"something": "unexpected", "region": "foo", "endpoint": "bar", "dynamodb_endpoint": "foobar", "profile": "baz", "role_arn": "arn::it", "shared_credentials_file": "my-file", "force_path_style": false},
map[string]interface{}{"something": "unexpected", "region": "foo", "endpoint": "bar", "dynamodb_endpoint": "foobar", "profile": "baz", "role_arn": "arn::it", "shared_credentials_file": "my-file", "use_path_style": false},
},
}

Expand All @@ -332,7 +380,7 @@ func TestAwsGetAwsSessionConfig(t *testing.T) {
Profile: s3ConfigExtended.RemoteStateConfigS3.Profile,
RoleArn: s3ConfigExtended.RemoteStateConfigS3.RoleArn,
CredsFilename: s3ConfigExtended.RemoteStateConfigS3.CredsFilename,
S3ForcePathStyle: s3ConfigExtended.RemoteStateConfigS3.S3ForcePathStyle,
S3UsePathStyle: s3ConfigExtended.RemoteStateConfigS3.S3UsePathStyle,
DisableComputeChecksums: s3ConfigExtended.DisableAWSClientChecksums,
}

Expand Down
4 changes: 2 additions & 2 deletions remote/remote_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ func TestToTerraformInitArgs(t *testing.T) {
"skip_bucket_versioning": true,

"shared_credentials_file": "my-file",
"force_path_style": true,
"use_path_style": true,
},
}
args := remoteState.ToTerraformInitArgs()

// must not contain s3_bucket_tags or dynamodb_table_tags or accesslogging_bucket_tags or skip_bucket_versioning
assertTerraformInitArgsEqual(t, args, "-backend-config=encrypt=true -backend-config=bucket=my-bucket -backend-config=key=terraform.tfstate -backend-config=region=us-east-1 -backend-config=force_path_style=true -backend-config=shared_credentials_file=my-file")
assertTerraformInitArgsEqual(t, args, "-backend-config=encrypt=true -backend-config=bucket=my-bucket -backend-config=key=terraform.tfstate -backend-config=region=us-east-1 -backend-config=use_path_style=true -backend-config=shared_credentials_file=my-file")
}

func TestToTerraformInitArgsForGCS(t *testing.T) {
Expand Down

0 comments on commit 2d7a8e6

Please sign in to comment.