Skip to content

Commit bd272a5

Browse files
committed
Merge branch 'main' into HEAD
2 parents baacd6c + 611b473 commit bd272a5

File tree

821 files changed

+1669
-1368
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

821 files changed

+1669
-1368
lines changed

.changelog/23384.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
provider: Makes `region` an optional parameter to allow sourcing from shared config files and IMDS
3+
```

.changelog/23388.txt

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
```release-note:enhancement
2+
provider: Retrieves region from IMDS when credentials retrieved from IMDS.
3+
```
4+
5+
```release-note:enhancement
6+
provider: Improves error message when `Profile` and static credential environment variables are set.
7+
```
8+
9+
```release-note:bug
10+
provider: Validates names of named profiles before use.
11+
```

.markdownlint.yml

+38-14
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,47 @@
22
# https://github.com/DavidAnson/markdownlint#configuration
33

44
default: true
5-
MD007:
5+
6+
# MD007
7+
ul-indent:
68
indent: 4
7-
MD010:
9+
10+
# MD010
11+
no-hard-tabs:
812
code_blocks: false
913

1014
# Disabled Rules
1115
# https://github.com/DavidAnson/markdownlint/blob/master/doc/Rules.md
1216

13-
MD001: false
14-
MD004: false
15-
MD006: false
16-
MD012: false
17-
MD013: false
18-
MD014: false
19-
MD022: false
20-
MD024: false
21-
MD034: false
22-
MD038: false
23-
MD040: false
24-
MD047: false
17+
# MD001
18+
heading-increment: false
19+
20+
# MD004
21+
ul-style: false
22+
23+
# MD012
24+
no-multiple-blanks: false
25+
26+
# MD013
27+
line-length: false
28+
29+
# MD014
30+
commands-show-output: false
31+
32+
# MD022
33+
blanks-around-headings: false
34+
35+
# MD024
36+
no-duplicate-heading: false
37+
38+
# MD034
39+
no-bare-urls: false
40+
41+
# MD038
42+
no-space-in-code: false
43+
44+
# MD040
45+
fenced-code-language: false
46+
47+
# MD047
48+
single-trailing-newline: false

.semgrep.yml

+10
Original file line numberDiff line numberDiff line change
@@ -693,3 +693,13 @@ rules:
693693
patterns:
694694
- pattern: validation.Any(..., validation.StringIsEmpty, ...)
695695
severity: ERROR
696+
697+
- id: use-error-code-equals-if-not-checking-message
698+
languages: [go]
699+
message: Use tfawserr.ErrCodeEquals() when message parameter is empty string
700+
paths:
701+
include:
702+
- internal/
703+
patterns:
704+
- pattern: tfawserr.ErrMessageContains(err, ..., "")
705+
severity: ERROR

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ FEATURES:
2020
ENHANCEMENTS:
2121

2222
* data-source/aws_ec2_transit_gateway: Add `multicast_support` attribute ([#22756](https://github.com/hashicorp/terraform-provider-aws/issues/22756))
23+
* provider: Improves error message when `Profile` and static credential environment variables are set. ([#23388](https://github.com/hashicorp/terraform-provider-aws/issues/23388))
24+
* provider: Makes `region` an optional parameter to allow sourcing from shared config files and IMDS ([#23384](https://github.com/hashicorp/terraform-provider-aws/issues/23384))
25+
* provider: Retrieves region from IMDS when credentials retrieved from IMDS. ([#23388](https://github.com/hashicorp/terraform-provider-aws/issues/23388))
2326
* resource/aws_ec2_fleet: Add `context` argument ([#23304](https://github.com/hashicorp/terraform-provider-aws/issues/23304))
2427
* resource/aws_ec2_transit_gateway: Add `multicast_support` argument ([#22756](https://github.com/hashicorp/terraform-provider-aws/issues/22756))
2528
* resource/aws_imagebuilder_image_pipeline: Add `schedule.timezone` argument ([#23322](https://github.com/hashicorp/terraform-provider-aws/issues/23322))
@@ -29,6 +32,7 @@ ENHANCEMENTS:
2932

3033
BUG FIXES:
3134

35+
* provider: Validates names of named profiles before use. ([#23388](https://github.com/hashicorp/terraform-provider-aws/issues/23388))
3236
* resource/aws_dms_replication_task: Allow `cdc_start_position` to be computed ([#23328](https://github.com/hashicorp/terraform-provider-aws/issues/23328))
3337
* resource/aws_ecs_cluster: Fix bug preventing describing clusters in ISO regions ([#23341](https://github.com/hashicorp/terraform-provider-aws/issues/23341))
3438

docs/contributing/data-handling-and-conversion.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ To expand on the data handling that occurs specifically within the Terraform AWS
9696

9797
To further understand the necessary data conversions used throughout the Terraform AWS Provider codebase between AWS Go SDK types and the Terraform Plugin SDK, the following table can be referenced for most scenarios:
9898

99-
<!-- markdownlint-disable MD033 --->
99+
<!-- markdownlint-disable no-inline-html --->
100100

101101
| AWS API Model | AWS Go SDK | Terraform Plugin SDK | Terraform Language/State |
102102
|---------------|------------|----------------------|--------------------------|
@@ -109,7 +109,7 @@ To further understand the necessary data conversions used throughout the Terrafo
109109
| `structure` | `struct` | `TypeList` (`[]interface{}` of `map[string]interface{}`) | `list(object(any))` |
110110
| `timestamp` | `*time.Time` | `TypeString` (typically RFC3339 formatted) | `string` |
111111

112-
<!-- markdownlint-enable MD033 --->
112+
<!-- markdownlint-enable no-inline-html --->
113113

114114
You may notice there are type encoding differences the AWS Go SDK and Terraform Plugin SDK:
115115

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ require (
1010
github.com/beevik/etree v1.1.0
1111
github.com/google/go-cmp v0.5.7
1212
github.com/hashicorp/aws-cloudformation-resource-schema-sdk-go v0.16.0
13-
github.com/hashicorp/aws-sdk-go-base/v2 v2.0.0-beta.8
14-
github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2 v2.0.0-beta.9
13+
github.com/hashicorp/aws-sdk-go-base/v2 v2.0.0-beta.10
14+
github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2 v2.0.0-beta.11
1515
github.com/hashicorp/awspolicyequivalence v1.5.0
1616
github.com/hashicorp/go-cleanhttp v0.5.2
1717
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320

go.sum

+4-4
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,10 @@ github.com/googleapis/gax-go/v2 v2.0.5 h1:sjZBwGj9Jlw33ImPtvFviGYvseOtDM7hkSKB7+
196196
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
197197
github.com/hashicorp/aws-cloudformation-resource-schema-sdk-go v0.16.0 h1:r2RUzeK2gAitl0HY9SLH1axAEu+6aPBY20g1jOoBepM=
198198
github.com/hashicorp/aws-cloudformation-resource-schema-sdk-go v0.16.0/go.mod h1:C6GVuO9RWOrt6QCGTmLCOYuSHpkfQSBDuRqTteOlo0g=
199-
github.com/hashicorp/aws-sdk-go-base/v2 v2.0.0-beta.8 h1:BlV2HAJxG5/UHMgBQ9rKrGLg6ThIkqTs6Hnr3OHOjps=
200-
github.com/hashicorp/aws-sdk-go-base/v2 v2.0.0-beta.8/go.mod h1:O0d2KtdvgHuWVQ9go3oK6BFPLht6254JIHjLfEzo+lM=
201-
github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2 v2.0.0-beta.9 h1:sFb+svRVSNWtVd4JDHen7R+rd0TB3yKt8+OgbYcpamU=
202-
github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2 v2.0.0-beta.9/go.mod h1:bUMECpdj5Vo+mLFC8gYUb+epVTg1ocf6xx9T7QVeK18=
199+
github.com/hashicorp/aws-sdk-go-base/v2 v2.0.0-beta.10 h1:HvzuTawTMw+enUgu4plvLJ3kgH/Gaz1MRFmZcVAnEeo=
200+
github.com/hashicorp/aws-sdk-go-base/v2 v2.0.0-beta.10/go.mod h1:O0d2KtdvgHuWVQ9go3oK6BFPLht6254JIHjLfEzo+lM=
201+
github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2 v2.0.0-beta.11 h1:GQ5vECuNqulzr2Jizlvrf4C8JcK50BFqieB/PprHYc8=
202+
github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2 v2.0.0-beta.11/go.mod h1:rDvk2q2KbYHahKgYmFHJh0eM310hYWUSTTJ1LAZY4Vs=
203203
github.com/hashicorp/awspolicyequivalence v1.5.0 h1:tGw6h9qN1AWNBaUf4OUcdCyE/kqNBItTiyTPQeV/KUg=
204204
github.com/hashicorp/awspolicyequivalence v1.5.0/go.mod h1:9IOaIHx+a7C0NfUNk1A93M7kHd5rJ19aoUx37LZGC14=
205205
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=

internal/acctest/acctest.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ func PreCheckOrganizationsAccount(t *testing.T) {
673673
conn := Provider.Meta().(*conns.AWSClient).OrganizationsConn
674674
input := &organizations.DescribeOrganizationInput{}
675675
_, err := conn.DescribeOrganization(input)
676-
if tfawserr.ErrMessageContains(err, organizations.ErrCodeAWSOrganizationsNotInUseException, "") {
676+
if tfawserr.ErrCodeEquals(err, organizations.ErrCodeAWSOrganizationsNotInUseException) {
677677
return
678678
}
679679
if err != nil {
@@ -686,7 +686,7 @@ func PreCheckOrganizationsEnabled(t *testing.T) {
686686
conn := Provider.Meta().(*conns.AWSClient).OrganizationsConn
687687
input := &organizations.DescribeOrganizationInput{}
688688
_, err := conn.DescribeOrganization(input)
689-
if tfawserr.ErrMessageContains(err, organizations.ErrCodeAWSOrganizationsNotInUseException, "") {
689+
if tfawserr.ErrCodeEquals(err, organizations.ErrCodeAWSOrganizationsNotInUseException) {
690690
t.Skip("this AWS account must be an existing member of an AWS Organization")
691691
}
692692
if err != nil {
@@ -748,7 +748,7 @@ func PreCheckHasIAMRole(t *testing.T, roleName string) {
748748
}
749749
_, err := conn.GetRole(input)
750750

751-
if tfawserr.ErrMessageContains(err, iam.ErrCodeNoSuchEntityException, "") {
751+
if tfawserr.ErrCodeEquals(err, iam.ErrCodeNoSuchEntityException) {
752752
t.Skipf("skipping acceptance test: required IAM role \"%s\" is not present", roleName)
753753
}
754754
if PreCheckSkipError(err) {
@@ -1087,18 +1087,18 @@ func PreCheckSkipError(err error) bool {
10871087
// GovCloud has endpoints that respond with (no message provided after the error code):
10881088
// AccessDeniedException:
10891089
// Ignore these API endpoints that exist but are not officially enabled
1090-
if tfawserr.ErrMessageContains(err, "AccessDeniedException", "") {
1090+
if tfawserr.ErrCodeEquals(err, "AccessDeniedException") {
10911091
return true
10921092
}
10931093
// Ignore missing API endpoints
10941094
if tfawserr.ErrMessageContains(err, "RequestError", "send request failed") {
10951095
return true
10961096
}
10971097
// Ignore unsupported API calls
1098-
if tfawserr.ErrMessageContains(err, "UnknownOperationException", "") {
1098+
if tfawserr.ErrCodeEquals(err, "UnknownOperationException") {
10991099
return true
11001100
}
1101-
if tfawserr.ErrMessageContains(err, "UnsupportedOperation", "") {
1101+
if tfawserr.ErrCodeEquals(err, "UnsupportedOperation") {
11021102
return true
11031103
}
11041104
if tfawserr.ErrMessageContains(err, "InvalidInputException", "Unknown operation") {

internal/conns/conns.go

+6-8
Original file line numberDiff line numberDiff line change
@@ -1194,14 +1194,6 @@ func (client *AWSClient) RegionalHostname(prefix string) string {
11941194

11951195
// Client configures and returns a fully initialized AWSClient
11961196
func (c *Config) Client(ctx context.Context) (interface{}, diag.Diagnostics) {
1197-
// Get the auth and region. This can fail if keys/regions were not
1198-
// specified and we're attempting to use the environment.
1199-
if !c.SkipRegionValidation {
1200-
if err := awsbase.ValidateRegion(c.Region); err != nil {
1201-
return nil, diag.FromErr(err)
1202-
}
1203-
}
1204-
12051197
awsbaseConfig := awsbase.Config{
12061198
AccessKey: c.AccessKey,
12071199
APNInfo: StdUserAgentProducts(c.TerraformVersion),
@@ -1253,6 +1245,12 @@ func (c *Config) Client(ctx context.Context) (interface{}, diag.Diagnostics) {
12531245
return nil, diag.Errorf("error configuring Terraform AWS Provider: %s", err)
12541246
}
12551247

1248+
if !c.SkipRegionValidation {
1249+
if err := awsbase.ValidateRegion(cfg.Region); err != nil {
1250+
return nil, diag.FromErr(err)
1251+
}
1252+
}
1253+
12561254
sess, err := awsbasev1.GetSession(&cfg, &awsbaseConfig)
12571255
if err != nil {
12581256
return nil, diag.Errorf("error creating AWS SDK v1 session: %s", err)

internal/provider/provider.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -291,14 +291,9 @@ func Provider() *schema.Provider {
291291
},
292292
"region": {
293293
Type: schema.TypeString,
294-
Required: true,
295-
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
296-
"AWS_REGION",
297-
"AWS_DEFAULT_REGION",
298-
}, nil),
294+
Optional: true,
299295
Description: "The region where AWS operations will take place. Examples\n" +
300296
"are us-east-1, us-west-2, etc.", // lintignore:AWSAT003,
301-
InputDefault: "us-east-1", // lintignore:AWSAT003
302297
},
303298
"s3_force_path_style": {
304299
Type: schema.TypeBool,

internal/service/accessanalyzer/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# Terraform AWS Provider AccessAnalyzer Package
2-
<!-- markdownlint-disable MD026 -->
2+
33
This area is primarily for AWS provider contributors and maintainers. For information on _using_ Terraform and the AWS provider, see the links below.
44

55

66
## Handy Links
7+
78
* [Find out about contributing](../../../docs/contributing) to the AWS provider!
89
* AWS Provider Docs: [Home](https://registry.terraform.io/providers/hashicorp/aws/latest/docs)
910
* AWS Provider Docs: [One of the AccessAnalyzer resources](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/accessanalyzer_analyzer)

internal/service/accessanalyzer/analyzer_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func testAccCheckAccessAnalyzerAnalyzerDestroy(s *terraform.State) error {
165165

166166
output, err := conn.GetAnalyzer(input)
167167

168-
if tfawserr.ErrMessageContains(err, accessanalyzer.ErrCodeResourceNotFoundException, "") {
168+
if tfawserr.ErrCodeEquals(err, accessanalyzer.ErrCodeResourceNotFoundException) {
169169
continue
170170
}
171171

internal/service/acm/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# Terraform AWS Provider ACM Package
2-
<!-- markdownlint-disable MD026 -->
2+
33
This area is primarily for AWS provider contributors and maintainers. For information on _using_ Terraform and the AWS provider, see the links below.
44

55

66
## Handy Links
7+
78
* [Find out about contributing](../../../docs/contributing) to the AWS provider!
89
* AWS Provider Docs: [Home](https://registry.terraform.io/providers/hashicorp/aws/latest/docs)
910
* AWS Provider Docs: [One of the ACM resources](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/acm_certificate)

internal/service/acm/certificate_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ func testAccCheckAcmCertificateDestroy(s *terraform.State) error {
780780
}
781781

782782
// Verify the error is what we want
783-
if !tfawserr.ErrMessageContains(err, acm.ErrCodeResourceNotFoundException, "") {
783+
if !tfawserr.ErrCodeEquals(err, acm.ErrCodeResourceNotFoundException) {
784784
return err
785785
}
786786
}

internal/service/acmpca/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# Terraform AWS Provider ACMPCA Package
2-
<!-- markdownlint-disable MD026 -->
2+
33
This area is primarily for AWS provider contributors and maintainers. For information on _using_ Terraform and the AWS provider, see the links below.
44

55

66
## Handy Links
7+
78
* [Find out about contributing](../../../docs/contributing) to the AWS provider!
89
* AWS Provider Docs: [Home](https://registry.terraform.io/providers/hashicorp/aws/latest/docs)
910
* AWS Provider Docs: [One of the ACMPCA resources](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/acmpca_certificate)

internal/service/acmpca/certificate_authority_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ func testAccCheckCertificateAuthorityDestroy(s *terraform.State) error {
514514
output, err := conn.DescribeCertificateAuthority(input)
515515

516516
if err != nil {
517-
if tfawserr.ErrMessageContains(err, acmpca.ErrCodeResourceNotFoundException, "") {
517+
if tfawserr.ErrCodeEquals(err, acmpca.ErrCodeResourceNotFoundException) {
518518
return nil
519519
}
520520
return err

internal/service/acmpca/sweep.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func sweepCertificateAuthorities(region string) error {
5454
CertificateAuthorityArn: aws.String(arn),
5555
Status: aws.String(acmpca.CertificateAuthorityStatusDisabled),
5656
})
57-
if tfawserr.ErrMessageContains(err, acmpca.ErrCodeResourceNotFoundException, "") {
57+
if tfawserr.ErrCodeEquals(err, acmpca.ErrCodeResourceNotFoundException) {
5858
continue
5959
}
6060
if err != nil {
@@ -70,7 +70,7 @@ func sweepCertificateAuthorities(region string) error {
7070
CertificateAuthorityArn: aws.String(arn),
7171
PermanentDeletionTimeInDays: aws.Int64(7),
7272
})
73-
if tfawserr.ErrMessageContains(err, acmpca.ErrCodeResourceNotFoundException, "") {
73+
if tfawserr.ErrCodeEquals(err, acmpca.ErrCodeResourceNotFoundException) {
7474
continue
7575
}
7676
if err != nil {

internal/service/amp/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# Terraform AWS Provider AMP Package
2-
<!-- markdownlint-disable MD026 -->
2+
33
This area is primarily for AWS provider contributors and maintainers. For information on _using_ Terraform and the AWS provider, see the links below.
44

55
AMP (**A**mazon **M**anaged Service for **P**rometheus) is also called just _Prometheus_ or _Prometheus Service_.
66

77

88
## Handy Links
9+
910
* [Find out about contributing](../../../docs/contributing) to the AWS provider!
1011
* AWS Provider Docs: [Home](https://registry.terraform.io/providers/hashicorp/aws/latest/docs)
1112
* AWS Provider Docs: [One of the Prometheus resources](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/prometheus_workspace)

internal/service/amp/workspace_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func testAccCheckAMPWorkspaceDestroy(s *terraform.State) error {
171171
_, err := conn.DescribeWorkspace(&prometheusservice.DescribeWorkspaceInput{
172172
WorkspaceId: aws.String(rs.Primary.ID),
173173
})
174-
if tfawserr.ErrMessageContains(err, prometheusservice.ErrCodeResourceNotFoundException, "") {
174+
if tfawserr.ErrCodeEquals(err, prometheusservice.ErrCodeResourceNotFoundException) {
175175
continue
176176
}
177177

internal/service/amplify/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# Terraform AWS Provider Amplify Package
2-
<!-- markdownlint-disable MD026 -->
2+
33
This area is primarily for AWS provider contributors and maintainers. For information on _using_ Terraform and the AWS provider, see the links below.
44

55

66
## Handy Links
7+
78
* [Find out about contributing](../../../docs/contributing) to the AWS provider!
89
* AWS Provider Docs: [Home](https://registry.terraform.io/providers/hashicorp/aws/latest/docs)
910
* AWS Provider Docs: [One of the Amplify resources](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/amplify_app)

internal/service/apigateway/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# Terraform AWS Provider APIGateway Package
2-
<!-- markdownlint-disable MD026 -->
2+
33
This area is primarily for AWS provider contributors and maintainers. For information on _using_ Terraform and the AWS provider, see the links below.
44

55

66
## Handy Links
7+
78
* [Find out about contributing](../../../docs/contributing) to the AWS provider!
89
* AWS Provider Docs: [Home](https://registry.terraform.io/providers/hashicorp/aws/latest/docs)
910
* AWS Provider Docs: [One of the APIGateway resources](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_account)

internal/service/apigateway/api_key.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ func resourceAPIKeyDelete(d *schema.ResourceData, meta interface{}) error {
209209
ApiKey: aws.String(d.Id()),
210210
})
211211

212-
if tfawserr.ErrMessageContains(err, apigateway.ErrCodeNotFoundException, "") {
212+
if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) {
213213
return nil
214214
}
215215

0 commit comments

Comments
 (0)