-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36939 from mattburgess/cloudformation-awssdkv2-mi…
…gration cloudformation: Migrate to AWS SDK v2
- Loading branch information
Showing
61 changed files
with
1,305 additions
and
1,401 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,84 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package cloudformation | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/service/cloudformation" | ||
awstypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" | ||
"github.com/hashicorp/terraform-provider-aws/internal/enum" | ||
"github.com/hashicorp/terraform-provider-aws/internal/errs" | ||
"github.com/hashicorp/terraform-provider-aws/internal/tfresource" | ||
) | ||
|
||
func findChangeSetByTwoPartKey(ctx context.Context, conn *cloudformation.Client, stackID, changeSetName string) (*cloudformation.DescribeChangeSetOutput, error) { | ||
input := &cloudformation.DescribeChangeSetInput{ | ||
ChangeSetName: aws.String(changeSetName), | ||
StackName: aws.String(stackID), | ||
} | ||
|
||
output, err := conn.DescribeChangeSet(ctx, input) | ||
|
||
if errs.IsA[*awstypes.ChangeSetNotFoundException](err) { | ||
return nil, &retry.NotFoundError{ | ||
LastError: err, | ||
LastRequest: input, | ||
} | ||
} | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if output == nil { | ||
return nil, tfresource.NewEmptyResultError(input) | ||
} | ||
|
||
return output, nil | ||
} | ||
|
||
func statusChangeSet(ctx context.Context, conn *cloudformation.Client, stackID, changeSetName string) retry.StateRefreshFunc { | ||
return func() (interface{}, string, error) { | ||
output, err := findChangeSetByTwoPartKey(ctx, conn, stackID, changeSetName) | ||
|
||
if tfresource.NotFound(err) { | ||
return nil, "", nil | ||
} | ||
|
||
if err != nil { | ||
return nil, "", err | ||
} | ||
|
||
return output, string(output.Status), nil | ||
} | ||
} | ||
|
||
func waitChangeSetCreated(ctx context.Context, conn *cloudformation.Client, stackID, changeSetName string) (*cloudformation.DescribeChangeSetOutput, error) { | ||
const ( | ||
timeout = 5 * time.Minute | ||
) | ||
stateConf := retry.StateChangeConf{ | ||
Pending: enum.Slice(awstypes.ChangeSetStatusCreateInProgress, awstypes.ChangeSetStatusCreatePending), | ||
Target: enum.Slice(awstypes.ChangeSetStatusCreateComplete), | ||
Timeout: timeout, | ||
Refresh: statusChangeSet(ctx, conn, stackID, changeSetName), | ||
} | ||
|
||
outputRaw, err := stateConf.WaitForStateContext(ctx) | ||
|
||
if output, ok := outputRaw.(*cloudformation.DescribeChangeSetOutput); ok { | ||
if output.Status == awstypes.ChangeSetStatusFailed { | ||
tfresource.SetLastError(err, errors.New(aws.ToString(output.StatusReason))) | ||
} | ||
|
||
return output, err | ||
} | ||
|
||
return nil, err | ||
} |
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,14 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package cloudformation | ||
|
||
// Exports for use in other modules. | ||
var ( | ||
FindStackByName = findStackByName | ||
FindTypeByName = findTypeByName | ||
WaitChangeSetCreated = waitChangeSetCreated | ||
WaitStackCreated = waitStackCreated | ||
WaitStackDeleted = waitStackDeleted | ||
WaitStackUpdated = waitStackUpdated | ||
) |
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,18 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package cloudformation | ||
|
||
// Exports for use in tests only. | ||
var ( | ||
ResourceStack = resourceStack | ||
ResourceStackSet = resourceStackSet | ||
ResourceStackSetInstance = resourceStackSetInstance | ||
ResourceType = resourceType | ||
|
||
FindStackInstanceByFourPartKey = findStackInstanceByFourPartKey | ||
FindStackInstanceSummariesByFourPartKey = findStackInstanceSummariesByFourPartKey | ||
FindStackSetByName = findStackSetByName | ||
FindTypeByARN = findTypeByARN | ||
StackSetInstanceResourceIDPartCount = stackSetInstanceResourceIDPartCount | ||
) |
Oops, something went wrong.