Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate ssm resources to AWS SDK for Go v2 #37481

Merged
merged 37 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
667e7c2
ssm: Only use AWS SDK for Go v2.
ewbankkit May 11, 2024
25925b3
ssm: Generate AWS SDK for Go v2 tagging code.
ewbankkit May 11, 2024
41727fe
Run 'make gen'.
ewbankkit May 11, 2024
94058db
r/aws_ssm_activation: Migrate to AWS SDK for Go v2.
ewbankkit May 11, 2024
d615ed0
internal/generate/tags: Add 'TagResTypeElemType' argument.
ewbankkit May 11, 2024
3ebd0b9
r/aws_ssm_association: Migrate to AWS SDK for Go v2.
ewbankkit May 11, 2024
7b3764d
r/aws_ssm_document: Migrate to AWS SDK for Go v2.
ewbankkit May 12, 2024
4f146b8
d/aws_ssm_document: Migrate to AWS SDK for Go v2.
ewbankkit May 12, 2024
28ac990
d/aws_ssm_instances: Migrate to AWS SDK for Go v2.
ewbankkit May 12, 2024
c615aa7
Merge branch 'main' into td-migrate-ssm-to-aws-sdk-v2
ewbankkit May 13, 2024
5dfaf34
r/aws_ssm_maintenance_window_target: Migrate to AWS SDK for Go v2.
ewbankkit May 13, 2024
a023f11
r/aws_ssm_maintenance_window_task: Migrate to AWS SDK for Go v2.
ewbankkit May 13, 2024
fcf551c
r/aws_ssm_maintenance_window: Migrate to AWS SDK for Go v2.
ewbankkit May 13, 2024
43a2e76
d/aws_ssm_maintenance_windows: Migrate to AWS SDK for Go v2.
ewbankkit May 13, 2024
d21628e
r/aws_ssm_parameter: Migrate to AWS SDK for Go v2.
ewbankkit May 13, 2024
77fe140
d/aws_ssm_parameter: Migrate to AWS SDK for Go v2.
ewbankkit May 13, 2024
879648d
d/aws_ssm_parameters_by_path: Migrate to AWS SDK for Go v2.
ewbankkit May 13, 2024
8873dc8
r/aws_ssm_patch_baseline: Migrate to AWS SDK for Go v2.
ewbankkit May 13, 2024
cb95f5a
d/aws_ssm_patch_baseline: Migrate to AWS SDK for Go v2.
ewbankkit May 13, 2024
f0ab145
Tidy up return 'diag.Diagnostics'.
ewbankkit May 13, 2024
c7136e6
r/aws_ssm_default_patch_baseline: Tidy up.
ewbankkit May 13, 2024
fadf339
r/aws_ssm_patch_group: Migrate to AWS SDK for Go v2.
ewbankkit May 13, 2024
61bca03
r/aws_ssm_resource_data_sync: Migrate to AWS SDK for Go v2.
ewbankkit May 13, 2024
01a5180
r/aws_ssm_service_setting: Migrate to AWS SDK for Go v2.
ewbankkit May 13, 2024
3115a31
ssm: Migrate sweepers to AWS SDK for Go v2.
ewbankkit May 13, 2024
83bc53f
Merge branch 'main' into td-migrate-ssm-to-aws-sdk-v2
ewbankkit May 13, 2024
f80f8b1
Fix golangci-lint 'whitespace'.
ewbankkit May 13, 2024
37af607
Fix golangci-lint 'durationcheck'.
ewbankkit May 13, 2024
ad8d7c7
Correct CHANGELOG entry file name.
ewbankkit May 13, 2024
6712f09
r/aws_ssm_maintenance_window_task: Don't validate 'task-arn'.
ewbankkit May 14, 2024
7690b7c
Merge branch 'main' into td-migrate-ssm-to-aws-sdk-v2
ewbankkit May 14, 2024
af4193b
r/aws_ssm_patch_baseline: Fix 'ResourceInUseException: PatchBaseline …
ewbankkit May 14, 2024
90ed97e
Remove 'TestAccSSMServiceSetting_disappears' -- aws_ssm_service_setti…
ewbankkit May 14, 2024
3096a4e
'findMaintenanceWindowTargetByID' -> 'findMaintenanceWindowTargetByTw…
ewbankkit May 14, 2024
5159559
Fix call to 'findMaintenanceWindowTaskByTwoPartKey'.
ewbankkit May 14, 2024
c4ed754
Fix typo.
ewbankkit May 14, 2024
30e6c5f
Fix 'findMaintenanceWindowTargets'.
ewbankkit May 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/37481.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_ssm_resource_data_sync: Add plan-time validation of `s3_destination.kms_key_arn`, `s3_destination.region` and `s3_destination.sync_format`
```
5 changes: 0 additions & 5 deletions internal/conns/awsclient_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions internal/generate/tags/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ var (
tagOp = flag.String("TagOp", "TagResource", "tagOp")
tagOpBatchSize = flag.String("TagOpBatchSize", "", "tagOpBatchSize")
tagResTypeElem = flag.String("TagResTypeElem", "", "tagResTypeElem")
tagResTypeElemType = flag.String("TagResTypeElemType", "", "tagResTypeElemType")
tagType = flag.String("TagType", "Tag", "tagType")
tagType2 = flag.String("TagType2", "", "tagType")
tagTypeAddBoolElem = flag.String("TagTypeAddBoolElem", "", "TagTypeAddBoolElem")
Expand Down Expand Up @@ -192,6 +193,7 @@ type TemplateData struct {
TagOpBatchSize string
TagPackage string
TagResTypeElem string
TagResTypeElemType string
TagType string
TagType2 string
TagTypeAddBoolElem string
Expand Down Expand Up @@ -356,6 +358,7 @@ func main() {
TagOpBatchSize: *tagOpBatchSize,
TagPackage: tagPackage,
TagResTypeElem: *tagResTypeElem,
TagResTypeElemType: *tagResTypeElemType,
TagType: *tagType,
TagType2: *tagType2,
TagTypeAddBoolElem: *tagTypeAddBoolElem,
Expand Down
4 changes: 4 additions & 0 deletions internal/generate/tags/templates/v2/list_tags_body.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ func {{ .ListTagsFunc }}(ctx context.Context, conn {{ .ClientType }}, identifier
{{ .ListTagsInIDElem }}: aws.String(identifier),
{{- end }}
{{- if .TagResTypeElem }}
{{- if .TagResTypeElemType }}
{{ .TagResTypeElem }}: awstypes.{{ .TagResTypeElemType }}(resourceType),
{{- else }}
{{ .TagResTypeElem }}: aws.String(resourceType),
{{- end }}
{{- end }}
{{- end }}
}
{{- if .ListTagsOpPaginated }}
var output []awstypes.{{ or .TagType2 .TagType }}
Expand Down
12 changes: 12 additions & 0 deletions internal/generate/tags/templates/v2/update_tags_body.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ func {{ .UpdateTagsFunc }}(ctx context.Context, conn {{ .ClientType }}, identifi
{{ .TagInIDElem }}: aws.String(identifier),
{{- end }}
{{- if .TagResTypeElem }}
{{- if .TagResTypeElemType }}
{{ .TagResTypeElem }}: awstypes.{{ .TagResTypeElemType }}(resourceType),
{{- else }}
{{ .TagResTypeElem }}: aws.String(resourceType),
{{- end }}
{{- end }}
{{- end }}
}

if len(updatedTags) > 0 {
Expand Down Expand Up @@ -86,9 +90,13 @@ func {{ .UpdateTagsFunc }}(ctx context.Context, conn {{ .ClientType }}, identifi
{{ .TagInIDElem }}: aws.String(identifier),
{{- end }}
{{- if .TagResTypeElem }}
{{- if .TagResTypeElemType }}
{{ .TagResTypeElem }}: awstypes.{{ .TagResTypeElemType }}(resourceType),
{{- else }}
{{ .TagResTypeElem }}: aws.String(resourceType),
{{- end }}
{{- end }}
{{- end }}
{{- if .UntagInNeedTagType }}
{{ .UntagInTagsElem }}: {{ .TagsFunc }}(removedTags),
{{- else if .UntagInNeedTagKeyType }}
Expand Down Expand Up @@ -128,9 +136,13 @@ func {{ .UpdateTagsFunc }}(ctx context.Context, conn {{ .ClientType }}, identifi
{{ .TagInIDElem }}: aws.String(identifier),
{{- end }}
{{- if .TagResTypeElem }}
{{- if .TagResTypeElemType }}
{{ .TagResTypeElem }}: awstypes.{{ .TagResTypeElemType }}(resourceType),
{{- else }}
{{ .TagResTypeElem }}: aws.String(resourceType),
{{- end }}
{{- end }}
{{- end }}
{{- if .TagInCustomVal }}
{{ .TagInTagsElem }}: {{ .TagInCustomVal }},
{{- else }}
Expand Down
4 changes: 3 additions & 1 deletion internal/service/codepipeline/codepipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,9 @@ func findPipelineByName(ctx context.Context, conn *codepipeline.Client, name str
return output, nil
}

func pipelineValidateActionProvider(i interface{}, path cty.Path) (diags diag.Diagnostics) {
func pipelineValidateActionProvider(i interface{}, path cty.Path) diag.Diagnostics {
var diags diag.Diagnostics

v, ok := i.(string)
if !ok {
return sdkdiag.AppendErrorf(diags, "expected type to be string")
Expand Down
6 changes: 1 addition & 5 deletions internal/service/ec2/vpc_default_network_acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func resourceDefaultNetworkACL() *schema.Resource {
CreateWithoutTimeout: resourceDefaultNetworkACLCreate,
ReadWithoutTimeout: resourceNetworkACLRead,
UpdateWithoutTimeout: resourceDefaultNetworkACLUpdate,
DeleteWithoutTimeout: resourceDefaultNetworkACLDelete,
DeleteWithoutTimeout: schema.NoopContext,

Importer: &schema.ResourceImporter{
StateContext: func(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
Expand Down Expand Up @@ -158,7 +158,3 @@ func resourceDefaultNetworkACLUpdate(ctx context.Context, d *schema.ResourceData

return append(diags, resourceNetworkACLRead(ctx, d, meta)...)
}

func resourceDefaultNetworkACLDelete(_ context.Context, d *schema.ResourceData, meta interface{}) (diags diag.Diagnostics) {
return sdkdiag.AppendWarningf(diags, "EC2 Default Network ACL (%s) not deleted, removing from state", d.Id())
}
5 changes: 4 additions & 1 deletion internal/service/inspector2/organization_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ const (
orgConfigMutex = "f14b54d7-2b10-58c2-9c1b-c48260a4825d"
)

func resourceOrganizationConfigurationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) (diags diag.Diagnostics) {
func resourceOrganizationConfigurationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics

d.SetId(meta.(*conns.AWSClient).AccountID)

return append(diags, resourceOrganizationConfigurationUpdate(ctx, d, meta)...)
}

Expand Down
4 changes: 3 additions & 1 deletion internal/service/lightsail/flex.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import (
)

// expandOperations provides a uniform approach for handling lightsail operations and errors.
func expandOperations(ctx context.Context, conn *lightsail.Client, operations []types.Operation, action types.OperationType, resource string, id string) (diags diag.Diagnostics) {
func expandOperations(ctx context.Context, conn *lightsail.Client, operations []types.Operation, action types.OperationType, resource string, id string) diag.Diagnostics {
var diags diag.Diagnostics

if len(operations) == 0 {
return create.AppendDiagError(diags, names.Lightsail, string(action), resource, id, errors.New("no operations found for request"))
}
Expand Down
78 changes: 37 additions & 41 deletions internal/service/ssm/activation.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import (
"log"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ssm"
"github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/ssm"
awstypes "github.com/aws/aws-sdk-go-v2/service/ssm/types"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/errs"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
Expand All @@ -24,7 +25,7 @@ import (

// @SDKResource("aws_ssm_activation", name="Activation")
// @Tags
func ResourceActivation() *schema.Resource {
func resourceActivation() *schema.Resource {
return &schema.Resource{
CreateWithoutTimeout: resourceActivationCreate,
ReadWithoutTimeout: resourceActivationRead,
Expand Down Expand Up @@ -84,7 +85,7 @@ func ResourceActivation() *schema.Resource {

func resourceActivationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).SSMConn(ctx)
conn := meta.(*conns.AWSClient).SSMClient(ctx)

name := d.Get(names.AttrName).(string)
input := &ssm.CreateActivationInput{
Expand All @@ -103,30 +104,30 @@ func resourceActivationCreate(ctx context.Context, d *schema.ResourceData, meta
}

if v, ok := d.GetOk("registration_limit"); ok {
input.RegistrationLimit = aws.Int64(int64(v.(int)))
input.RegistrationLimit = aws.Int32(int32(v.(int)))
}

outputRaw, err := tfresource.RetryWhenAWSErrMessageContains(ctx, propagationTimeout, func() (interface{}, error) {
return conn.CreateActivationWithContext(ctx, input)
}, "ValidationException", "Nonexistent role")
return conn.CreateActivation(ctx, input)
}, errCodeValidationException, "Nonexistent role")

if err != nil {
return sdkdiag.AppendErrorf(diags, "creating SSM Activation (%s): %s", name, err)
}

output := outputRaw.(*ssm.CreateActivationOutput)

d.SetId(aws.StringValue(output.ActivationId))
d.SetId(aws.ToString(output.ActivationId))
d.Set("activation_code", output.ActivationCode)

return append(diags, resourceActivationRead(ctx, d, meta)...)
}

func resourceActivationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).SSMConn(ctx)
conn := meta.(*conns.AWSClient).SSMClient(ctx)

activation, err := FindActivationByID(ctx, conn, d.Id())
activation, err := findActivationByID(ctx, conn, d.Id())

if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] SSM Activation %s not found, removing from state", d.Id())
Expand All @@ -139,7 +140,7 @@ func resourceActivationRead(ctx context.Context, d *schema.ResourceData, meta in
}

d.Set(names.AttrDescription, activation.Description)
d.Set("expiration_date", aws.TimeValue(activation.ExpirationDate).Format(time.RFC3339))
d.Set("expiration_date", aws.ToTime(activation.ExpirationDate).Format(time.RFC3339))
d.Set("expired", activation.Expired)
d.Set("iam_role", activation.IamRole)
d.Set(names.AttrName, activation.DefaultInstanceName)
Expand All @@ -153,14 +154,14 @@ func resourceActivationRead(ctx context.Context, d *schema.ResourceData, meta in

func resourceActivationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).SSMConn(ctx)
conn := meta.(*conns.AWSClient).SSMClient(ctx)

log.Printf("[DEBUG] Deleting SSM Activation: %s", d.Id())
_, err := conn.DeleteActivationWithContext(ctx, &ssm.DeleteActivationInput{
_, err := conn.DeleteActivation(ctx, &ssm.DeleteActivationInput{
ActivationId: aws.String(d.Id()),
})

if tfawserr.ErrCodeEquals(err, ssm.ErrCodeInvalidActivation) {
if errs.IsA[*awstypes.InvalidActivation](err) {
return diags
}

Expand All @@ -171,47 +172,42 @@ func resourceActivationDelete(ctx context.Context, d *schema.ResourceData, meta
return diags
}

func FindActivationByID(ctx context.Context, conn *ssm.SSM, id string) (*ssm.Activation, error) {
func findActivationByID(ctx context.Context, conn *ssm.Client, id string) (*awstypes.Activation, error) {
input := &ssm.DescribeActivationsInput{
Filters: []*ssm.DescribeActivationsFilter{
Filters: []awstypes.DescribeActivationsFilter{
{
FilterKey: aws.String("ActivationIds"),
FilterValues: aws.StringSlice([]string{id}),
FilterKey: awstypes.DescribeActivationsFilterKeysActivationIds,
FilterValues: []string{id},
},
},
}

return findActivation(ctx, conn, input)
}

func findActivation(ctx context.Context, conn *ssm.SSM, input *ssm.DescribeActivationsInput) (*ssm.Activation, error) {
var output []*ssm.Activation

err := conn.DescribeActivationsPagesWithContext(ctx, input, func(page *ssm.DescribeActivationsOutput, lastPage bool) bool {
if page == nil {
return !lastPage
}

for _, v := range page.ActivationList {
if v != nil {
output = append(output, v)
}
}

return !lastPage
})
func findActivation(ctx context.Context, conn *ssm.Client, input *ssm.DescribeActivationsInput) (*awstypes.Activation, error) {
output, err := findActivations(ctx, conn, input)

if err != nil {
return nil, err
}

if len(output) == 0 || output[0] == nil {
return nil, tfresource.NewEmptyResultError(input)
}
return tfresource.AssertSingleValueResult(output)
}

func findActivations(ctx context.Context, conn *ssm.Client, input *ssm.DescribeActivationsInput) ([]awstypes.Activation, error) {
var output []awstypes.Activation

pages := ssm.NewDescribeActivationsPaginator(conn, input)
for pages.HasMorePages() {
page, err := pages.NextPage(ctx)

if err != nil {
return nil, err
}

if count := len(output); count > 1 {
return nil, tfresource.NewTooManyResultsError(count, input)
output = append(output, page.ActivationList...)
}

return output[0], nil
return output, nil
}
20 changes: 8 additions & 12 deletions internal/service/ssm/activation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"testing"
"time"

"github.com/aws/aws-sdk-go/service/ssm"
awstypes "github.com/aws/aws-sdk-go-v2/service/ssm/types"
sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
Expand All @@ -22,7 +22,7 @@ import (

func TestAccSSMActivation_basic(t *testing.T) {
ctx := acctest.Context(t)
var ssmActivation ssm.Activation
var ssmActivation awstypes.Activation
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
roleName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_ssm_activation.test"
Expand Down Expand Up @@ -56,7 +56,7 @@ func TestAccSSMActivation_basic(t *testing.T) {

func TestAccSSMActivation_tags(t *testing.T) {
ctx := acctest.Context(t)
var ssmActivation ssm.Activation
var ssmActivation awstypes.Activation
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
roleName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_ssm_activation.test"
Expand Down Expand Up @@ -91,7 +91,7 @@ func TestAccSSMActivation_tags(t *testing.T) {

func TestAccSSMActivation_expirationDate(t *testing.T) {
ctx := acctest.Context(t)
var ssmActivation ssm.Activation
var ssmActivation awstypes.Activation
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
roleName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
expirationDate := time.Now().Add(48 * time.Hour).UTC().Format(time.RFC3339)
Expand Down Expand Up @@ -124,7 +124,7 @@ func TestAccSSMActivation_expirationDate(t *testing.T) {

func TestAccSSMActivation_disappears(t *testing.T) {
ctx := acctest.Context(t)
var ssmActivation ssm.Activation
var ssmActivation awstypes.Activation
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
roleName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_ssm_activation.test"
Expand All @@ -147,18 +147,14 @@ func TestAccSSMActivation_disappears(t *testing.T) {
})
}

func testAccCheckActivationExists(ctx context.Context, n string, v *ssm.Activation) resource.TestCheckFunc {
func testAccCheckActivationExists(ctx context.Context, n string, v *awstypes.Activation) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}

if rs.Primary.ID == "" {
return fmt.Errorf("No SSM Activation ID is set")
}

conn := acctest.Provider.Meta().(*conns.AWSClient).SSMConn(ctx)
conn := acctest.Provider.Meta().(*conns.AWSClient).SSMClient(ctx)

output, err := tfssm.FindActivationByID(ctx, conn, rs.Primary.ID)

Expand All @@ -174,7 +170,7 @@ func testAccCheckActivationExists(ctx context.Context, n string, v *ssm.Activati

func testAccCheckActivationDestroy(ctx context.Context) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := acctest.Provider.Meta().(*conns.AWSClient).SSMConn(ctx)
conn := acctest.Provider.Meta().(*conns.AWSClient).SSMClient(ctx)

for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_ssm_activation" {
Expand Down
Loading
Loading