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

Tech debt: Migrate glacier resources to AWS SDK for Go v2 #31829

Merged
merged 12 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/ec2 v1.99.0
github.com/aws/aws-sdk-go-v2/service/finspace v1.10.0
github.com/aws/aws-sdk-go-v2/service/fis v1.14.10
github.com/aws/aws-sdk-go-v2/service/glacier v1.14.11
github.com/aws/aws-sdk-go-v2/service/healthlake v1.16.0
github.com/aws/aws-sdk-go-v2/service/identitystore v1.16.11
github.com/aws/aws-sdk-go-v2/service/inspector2 v1.14.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ github.com/aws/aws-sdk-go-v2/service/finspace v1.10.0 h1:vZczEtJSs8HEkZ9JuxkKIHg
github.com/aws/aws-sdk-go-v2/service/finspace v1.10.0/go.mod h1:y9XeW3Hxtkh+Sled61taaqOk1Lk7wdGpLRBx9Z/twOk=
github.com/aws/aws-sdk-go-v2/service/fis v1.14.10 h1:uDfGkU0W6mO34XFbXgc9sFjOXTNA6IRoeeoPkCnZnx4=
github.com/aws/aws-sdk-go-v2/service/fis v1.14.10/go.mod h1:UFu/qHPW17t5CcwChAc76mSq3v/bRyzhqjwiTcqlwLI=
github.com/aws/aws-sdk-go-v2/service/glacier v1.14.11 h1:dTa4Macg5HxqrQfauBnhpx5cDU9S17mpMI/++BuG/2g=
github.com/aws/aws-sdk-go-v2/service/glacier v1.14.11/go.mod h1:7RgtFQVsN4MpvQieAJkHSUuvPTiMcEZO57tAnpzlM1I=
github.com/aws/aws-sdk-go-v2/service/healthlake v1.16.0 h1:8CXnXojAdCTtFhrJn2Ez6DDFFykbd9lWOu0Frs1zoqk=
github.com/aws/aws-sdk-go-v2/service/healthlake v1.16.0/go.mod h1:n1IxBDIRdNPVLrEDqwDSZSF60FkFIO43gWVMZo4Y/Rk=
github.com/aws/aws-sdk-go-v2/service/iam v1.19.12 h1:JH1H7POlsZt41X9JYIBLZoXW0Qv+WOuC48xsafsls2Q=
Expand Down
8 changes: 4 additions & 4 deletions internal/conns/awsclient_gen.go

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

8 changes: 6 additions & 2 deletions internal/conns/config_gen.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,14 @@ func SetTagsOut(ctx context.Context, tags map[string]string) {
inContext.TagsOut = types.Some(KeyValueTags(ctx, tags))
}
}

{{- if ne .CreateTagsFunc "" }}
// {{ .CreateTagsFunc }} creates {{ .ServicePackage }} service tags for new resources.
func {{ .CreateTagsFunc }}(ctx context.Context, conn {{ .ClientType }}, identifier{{ if .TagResTypeElem }}, resourceType{{ end }} string, tags map[string]string) error {
if len(tags) == 0 {
return nil
}

return {{ .UpdateTagsFunc }}(ctx, conn, identifier{{ if .TagResTypeElem }}, resourceType{{ end }}, nil, tags)
}
{{- end }}
10 changes: 10 additions & 0 deletions internal/service/glacier/exports_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package glacier

// Exports for use in tests only.
var (
ResourceVault = resourceVault
ResourceVaultLock = resourceVaultLock

FindVaultByName = findVaultByName
FindVaultLockByName = findVaultLockByName
)
2 changes: 1 addition & 1 deletion internal/service/glacier/generate.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate go run ../../generate/tags/main.go -ListTags -ListTagsOp=ListTagsForVault -ListTagsInIDElem=VaultName -ServiceTagsMap -TagOp=AddTagsToVault -TagInIDElem=VaultName -UntagOp=RemoveTagsFromVault -UpdateTags -CreateTags
//go:generate go run ../../generate/tags/main.go -AWSSDKVersion=2 -ListTags -ListTagsOp=ListTagsForVault -ListTagsInIDElem=VaultName -ServiceTagsMap -KVTValues -TagOp=AddTagsToVault -TagInIDElem=VaultName -UntagOp=RemoveTagsFromVault -UpdateTags -CreateTags -SkipTypesImp
// ONLY generate directives and package declaration! Do not add anything else to this file.

package glacier
4 changes: 2 additions & 2 deletions internal/service/glacier/service_package_gen.go

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

35 changes: 16 additions & 19 deletions internal/service/glacier/sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"fmt"
"log"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/glacier"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/glacier"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/sweep"
Expand All @@ -28,32 +28,29 @@ func sweepVaults(region string) error {
return fmt.Errorf("error getting client: %w", err)
}
input := &glacier.ListVaultsInput{}
conn := client.(*conns.AWSClient).GlacierConn()
conn := client.(*conns.AWSClient).GlacierClient()
sweepResources := make([]sweep.Sweepable, 0)

err = conn.ListVaultsPagesWithContext(ctx, input, func(page *glacier.ListVaultsOutput, lastPage bool) bool {
if page == nil {
return !lastPage
pages := glacier.NewListVaultsPaginator(conn, input)
for pages.HasMorePages() {
page, err := pages.NextPage(ctx)

if sweep.SkipSweepError(err) {
log.Printf("[WARN] Skipping Glacier Vault sweep for %s: %s", region, err)
return nil
}

if err != nil {
return fmt.Errorf("error listing Glacier Vaults (%s): %w", region, err)
}

for _, v := range page.VaultList {
r := ResourceVault()
r := resourceVault()
d := r.Data(nil)
d.SetId(aws.StringValue(v.VaultName))
d.SetId(aws.ToString(v.VaultName))

sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client))
}

return !lastPage
})

if sweep.SkipSweepError(err) {
log.Printf("[WARN] Skipping Glacier Vault sweep for %s: %s", region, err)
return nil
}

if err != nil {
return fmt.Errorf("error listing Glacier Vaults (%s): %w", region, err)
}

err = sweep.SweepOrchestratorWithContext(ctx, sweepResources)
Expand Down
35 changes: 17 additions & 18 deletions internal/service/glacier/tags_gen.go

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

Loading