From 8eee0d44245e1569c481bde23dd0efc17c4eed71 Mon Sep 17 00:00:00 2001 From: Kait Healy Date: Tue, 14 May 2024 17:16:28 -0500 Subject: [PATCH 01/29] adding all files from gitlab --- .go-version | 2 +- go.mod | 2 +- internal/service/appfabric/app_bundle.go | 205 +++++++++++++++ internal/service/appfabric/app_bundle_test.go | 247 ++++++++++++++++++ internal/service/appfabric/exports_test.go | 9 + .../appfabric/service_endpoints_gen_test.go | 25 +- .../service/appfabric/service_package_gen.go | 12 +- internal/service/appfabric/tags_gen.go | 94 +++++++ 8 files changed, 579 insertions(+), 17 deletions(-) create mode 100644 internal/service/appfabric/app_bundle.go create mode 100644 internal/service/appfabric/app_bundle_test.go create mode 100644 internal/service/appfabric/exports_test.go create mode 100644 internal/service/appfabric/tags_gen.go diff --git a/.go-version b/.go-version index 6fee2fedb0a..428abfd24fb 100644 --- a/.go-version +++ b/.go-version @@ -1 +1 @@ -1.22.2 +1.21.8 diff --git a/go.mod b/go.mod index c905a722c39..02b3fa22d97 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/hashicorp/terraform-provider-aws -go 1.22.2 +go 1.21 require ( github.com/ProtonMail/go-crypto v1.1.0-alpha.2 diff --git a/internal/service/appfabric/app_bundle.go b/internal/service/appfabric/app_bundle.go new file mode 100644 index 00000000000..4389504354f --- /dev/null +++ b/internal/service/appfabric/app_bundle.go @@ -0,0 +1,205 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package appfabric + +import ( + "context" + "errors" + "time" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/appfabric" + awstypes "github.com/aws/aws-sdk-go-v2/service/appfabric/types" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-provider-aws/internal/create" + "github.com/hashicorp/terraform-provider-aws/internal/errs" + "github.com/hashicorp/terraform-provider-aws/internal/framework" + "github.com/hashicorp/terraform-provider-aws/internal/framework/flex" + tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + "github.com/hashicorp/terraform-provider-aws/names" +) + +func newResourceAppBundle(_ context.Context) (resource.ResourceWithConfigure, error) { + r := &resourceAppBundle{} + r.SetDefaultCreateTimeout(5 * time.Minute) + r.SetDefaultUpdateTimeout(5 * time.Minute) + r.SetDefaultDeleteTimeout(5 * time.Minute) + return r, nil +} + +const ( + ResNameAppBundle = "AppBundle" +) + +type resourceAppBundle struct { + framework.ResourceWithConfigure + framework.WithTimeouts +} + +func (r *resourceAppBundle) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = "aws_appfabric_app_bundle" +} + +func (r *resourceAppBundle) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { + resp.Schema = schema.Schema{ + Attributes: map[string]schema.Attribute{ + "arn": framework.ARNAttributeComputedOnly(), + "customer_managed_key_identifier": schema.StringAttribute{ + Optional: true, + }, + names.AttrID: framework.IDAttribute(), + names.AttrTags: tftags.TagsAttribute(), + names.AttrTagsAll: tftags.TagsAttributeComputedOnly(), + }, + } +} + +func (r *resourceAppBundle) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + conn := r.Meta().AppFabricClient(ctx) + + var plan resourceAppBundleData + resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + if resp.Diagnostics.HasError() { + return + } + in := &appfabric.CreateAppBundleInput{ + Tags: getTagsIn(ctx), + } + + /*if !plan.CustomerManagedKeyArn.IsNull() { + in.CustomerManagedKeyIdentifier = aws.String(plan.CustomerManagedKeyArn.ValueString()) + }*/ + out, err := conn.CreateAppBundle(ctx, in) + if err != nil { + resp.Diagnostics.AddError( + create.ProblemStandardMessage(names.AppFabric, create.ErrActionCreating, ResNameAppBundle, plan.ARN.String(), err), + err.Error(), + ) + return + } + if out == nil || out.AppBundle == nil { + resp.Diagnostics.AddError( + create.ProblemStandardMessage(names.AppFabric, create.ErrActionCreating, ResNameAppBundle, plan.ARN.String(), nil), + errors.New("empty output").Error(), + ) + return + } + + plan.ARN = flex.StringToFramework(ctx, out.AppBundle.Arn) + plan.CustomerManagedKeyArn = flex.StringToFramework(ctx, out.AppBundle.CustomerManagedKeyArn) + plan.ID = types.StringValue(string(*out.AppBundle.Arn)) + + resp.Diagnostics.Append(resp.State.Set(ctx, plan)...) +} + +func (r *resourceAppBundle) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + conn := r.Meta().AppFabricClient(ctx) + + var state resourceAppBundleData + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + out, err := findAppBundleByID(ctx, conn, state.ARN.ValueString()) + + if tfresource.NotFound(err) { + resp.State.RemoveResource(ctx) + return + } + if err != nil { + resp.Diagnostics.AddError( + create.ProblemStandardMessage(names.AppFabric, create.ErrActionSetting, ResNameAppBundle, state.ARN.String(), err), + err.Error(), + ) + return + } + + state.ARN = flex.StringToFramework(ctx, out.Arn) + state.CustomerManagedKeyArn = flex.StringToFramework(ctx, out.CustomerManagedKeyArn) + state.ID = types.StringValue(string(*out.Arn)) + + resp.Diagnostics.Append(resp.State.Set(ctx, &state)...) +} + +func (r *resourceAppBundle) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + //No update +} + +func (r *resourceAppBundle) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + + conn := r.Meta().AppFabricClient(ctx) + + var state resourceAppBundleData + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + + in := &appfabric.DeleteAppBundleInput{ + AppBundleIdentifier: aws.String(state.ARN.ValueString()), + } + + _, err := conn.DeleteAppBundle(ctx, in) + + if err != nil { + if errs.IsA[*awstypes.ResourceNotFoundException](err) { + return + } + resp.Diagnostics.AddError( + create.ProblemStandardMessage(names.AppFabric, create.ErrActionDeleting, ResNameAppBundle, state.ARN.String(), err), + err.Error(), + ) + return + } +} + +// change id to arn +func (r *resourceAppBundle) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + resource.ImportStatePassthroughID(ctx, path.Root("arn"), req, resp) +} + +const ( + statusChangePending = "Pending" + statusDeleting = "Deleting" + statusNormal = "Normal" + statusUpdated = "Updated" +) + +func findAppBundleByID(ctx context.Context, conn *appfabric.Client, arn string) (*awstypes.AppBundle, error) { + in := &appfabric.GetAppBundleInput{ + AppBundleIdentifier: aws.String(arn), + } + + out, err := conn.GetAppBundle(ctx, in) + if err != nil { + if errs.IsA[*awstypes.ResourceNotFoundException](err) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: in, + } + } + + return nil, err + } + + if out == nil || out.AppBundle == nil { + return nil, tfresource.NewEmptyResultError(in) + } + + return out.AppBundle, nil +} + +type resourceAppBundleData struct { + ARN types.String `tfsdk:"arn"` + CustomerManagedKeyArn types.String `tfsdk:"customer_managed_key_identifier"` + ID types.String `tfsdk:"id"` + Tags types.Map `tfsdk:"tags"` + TagsAll types.Map `tfsdk:"tags_all"` +} diff --git a/internal/service/appfabric/app_bundle_test.go b/internal/service/appfabric/app_bundle_test.go new file mode 100644 index 00000000000..a275faf4a21 --- /dev/null +++ b/internal/service/appfabric/app_bundle_test.go @@ -0,0 +1,247 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package appfabric_test + +// **PLEASE DELETE THIS AND ALL TIP COMMENTS BEFORE SUBMITTING A PR FOR REVIEW!** +// +// TIP: ==== INTRODUCTION ==== +// Thank you for trying the skaff tool! +// +// You have opted to include these helpful comments. They all include "TIP:" +// to help you find and remove them when you're done with them. +// +// While some aspects of this file are customized to your input, the +// scaffold tool does *not* look at the AWS API and ensure it has correct +// function, structure, and variable names. It makes guesses based on +// commonalities. You will need to make significant adjustments. +// +// In other words, as generated, this is a rough outline of the work you will +// need to do. If something doesn't make sense for your situation, get rid of +// it. + +import ( + // TIP: ==== IMPORTS ==== + // This is a common set of imports but not customized to your code since + // your code hasn't been written yet. Make sure you, your IDE, or + // goimports -w fixes these imports. + // + // The provider linter wants your imports to be in two groups: first, + // standard library (i.e., "fmt" or "strings"), second, everything else. + // + // Also, AWS Go SDK v2 may handle nested structures differently than v1, + // using the services/appfabric/types package. If so, you'll + // need to import types and reference the nested types, e.g., as + // types.. + "context" + "errors" + "fmt" + "testing" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/appfabric" + "github.com/aws/aws-sdk-go-v2/service/appfabric/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" + "github.com/hashicorp/terraform-provider-aws/internal/acctest" + "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/create" + "github.com/hashicorp/terraform-provider-aws/internal/errs" + "github.com/hashicorp/terraform-provider-aws/names" + + // TIP: You will often need to import the package that this test file lives + // in. Since it is in the "test" context, it must import the package to use + // any normal context constants, variables, or functions. + tfappfabric "github.com/hashicorp/terraform-provider-aws/internal/service/appfabric" +) + +// TIP: ==== ACCEPTANCE TESTS ==== +// This is an example of a basic acceptance test. This should test as much of +// standard functionality of the resource as possible, and test importing, if +// applicable. We prefix its name with "TestAcc", the service, and the +// resource name. +// +// Acceptance test access AWS and cost money to run. +func TestAccAppFabricAppBundle_basic(t *testing.T) { + ctx := acctest.Context(t) + // TIP: This is a long-running test guard for tests that run longer than + // 300s (5 min) generally. + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + + var appbundle appfabric.GetAppBundleOutput + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_appfabric_app_bundle.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + testAccPreCheck(ctx, t) + }, + ErrorCheck: acctest.ErrorCheck(t, names.AppFabricServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckAppBundleDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccAppBundleConfig_basic(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAppBundleExists(ctx, resourceName, &appbundle), + //resource.TestCheckResourceAttrSet(resourceName, "customer_managed_key_identifier"), + // Do we add client token here? + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccAppBundleImportStateIDFunc(ctx, resourceName), + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAppFabricAppBundle_disappears(t *testing.T) { + ctx := acctest.Context(t) + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + + var appbundle appfabric.GetAppBundleOutput + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_appfabric_app_bundle.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + testAccPreCheck(ctx, t) + }, + ErrorCheck: acctest.ErrorCheck(t, names.AppFabricServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckAppBundleDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccAppBundleConfig_basic(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAppBundleExists(ctx, resourceName, &appbundle), + // TIP: The Plugin-Framework disappears helper is similar to the Plugin-SDK version, + // but expects a new resource factory function as the third argument. To expose this + // private function to the testing package, you may need to add a line like the following + // to exports_test.go: + // + // var ResourceAppBundle = newResourceAppBundle + acctest.CheckFrameworkResourceDisappears(ctx, acctest.Provider, tfappfabric.ResourceAppBundle, resourceName), + ), + ExpectNonEmptyPlan: true, + }, + }, + }) +} + +func testAccCheckAppBundleDestroy(ctx context.Context) resource.TestCheckFunc { + return func(s *terraform.State) error { + conn := acctest.Provider.Meta().(*conns.AWSClient).AppFabricClient(ctx) + + for _, rs := range s.RootModule().Resources { + if rs.Type != "aws_appfabric_app_bundle" { + continue + } + + _, err := conn.GetAppBundle(ctx, &appfabric.GetAppBundleInput{ + AppBundleIdentifier: aws.String(rs.Primary.Attributes["arn"]), + }) + if errs.IsA[*types.ResourceNotFoundException](err) { + return nil + } + if err != nil { + return create.Error(names.AppFabric, create.ErrActionCheckingDestroyed, tfappfabric.ResNameAppBundle, rs.Primary.ID, err) + } + + return create.Error(names.AppFabric, create.ErrActionCheckingDestroyed, tfappfabric.ResNameAppBundle, rs.Primary.ID, errors.New("not destroyed")) + } + + return nil + } +} + +func testAccCheckAppBundleExists(ctx context.Context, name string, appbundle *appfabric.GetAppBundleOutput) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + if !ok { + return create.Error(names.AppFabric, create.ErrActionCheckingExistence, tfappfabric.ResNameAppBundle, name, errors.New("not found")) + } + if rs.Primary.ID == "" { + return create.Error(names.AppFabric, create.ErrActionCheckingExistence, tfappfabric.ResNameAppBundle, name, errors.New("not set")) + } + conn := acctest.Provider.Meta().(*conns.AWSClient).AppFabricClient(ctx) + resp, err := conn.GetAppBundle(ctx, &appfabric.GetAppBundleInput{ + AppBundleIdentifier: aws.String(rs.Primary.Attributes["arn"]), + }) + if err != nil { + return create.Error(names.AppFabric, create.ErrActionCheckingExistence, tfappfabric.ResNameAppBundle, rs.Primary.ID, err) + } + *appbundle = *resp + return nil + } +} + +// leave default +func testAccPreCheck(ctx context.Context, t *testing.T) { + conn := acctest.Provider.Meta().(*conns.AWSClient).AppFabricClient(ctx) + input := &appfabric.ListAppBundlesInput{} + _, err := conn.ListAppBundles(ctx, input) + if acctest.PreCheckSkipError(err) { + t.Skipf("skipping acceptance testing: %s", err) + } + if err != nil { + t.Fatalf("unexpected PreCheck error: %s", err) + } +} +func testAccCheckAppBundleNotRecreated(before, after *appfabric.GetAppBundleOutput) resource.TestCheckFunc { + return func(s *terraform.State) error { + if before, after := aws.ToString(before.AppBundle.Arn), aws.ToString(after.AppBundle.Arn); before != after { + return create.Error(names.AppFabric, create.ErrActionCheckingNotRecreated, tfappfabric.ResNameAppBundle, before, errors.New("recreated")) + } + return nil + } +} + +func testAccAppBundleImportStateIDFunc(ctx context.Context, resourceName string) resource.ImportStateIdFunc { + return func(s *terraform.State) (string, error) { + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return "", fmt.Errorf("Not found: %s", resourceName) + } + + if rs.Primary.ID == "" { + return "", errors.New("No AppBundle ID set") + } + + conn := acctest.Provider.Meta().(*conns.AWSClient).AppFabricClient(ctx) + appBundleARN := rs.Primary.Attributes["arn"] + + _, err := conn.GetAppBundle(ctx, &appfabric.GetAppBundleInput{ + AppBundleIdentifier: aws.String(appBundleARN), + }) + + if err != nil { + return "", err + } + + return appBundleARN, nil + } +} + +// might need to change arn to app bundle identifier... not too sure here +// need to change to an actual arn +// not sure if needing customer managed key arn... +func testAccAppBundleConfig_basic(rName string) string { + return fmt.Sprintf(` +resource "aws_appfabric_app_bundle" "test" { + tags = { + Name = "AppFabricTesting" + } +} +`) +} diff --git a/internal/service/appfabric/exports_test.go b/internal/service/appfabric/exports_test.go new file mode 100644 index 00000000000..b8b39031b66 --- /dev/null +++ b/internal/service/appfabric/exports_test.go @@ -0,0 +1,9 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package appfabric + +// Exports for use in tests only. +var ( + ResourceAppBundle = newResourceAppBundle +) diff --git a/internal/service/appfabric/service_endpoints_gen_test.go b/internal/service/appfabric/service_endpoints_gen_test.go index 4d799b34836..046c92c52a2 100644 --- a/internal/service/appfabric/service_endpoints_gen_test.go +++ b/internal/service/appfabric/service_endpoints_gen_test.go @@ -25,7 +25,6 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/provider" - "github.com/hashicorp/terraform-provider-aws/names" ) type endpointTestCase struct { @@ -258,12 +257,12 @@ func withNoConfig(_ *caseSetup) { } func withPackageNameEndpointInConfig(setup *caseSetup) { - if _, ok := setup.config[names.AttrEndpoints]; !ok { - setup.config[names.AttrEndpoints] = []any{ + if _, ok := setup.config["endpoints"]; !ok { + setup.config["endpoints"] = []any{ map[string]any{}, } } - endpoints := setup.config[names.AttrEndpoints].([]any)[0].(map[string]any) + endpoints := setup.config["endpoints"].([]any)[0].(map[string]any) endpoints[packageName] = packageNameConfigEndpoint } @@ -334,17 +333,17 @@ func testEndpointCase(t *testing.T, region string, testcase endpointTestCase, ca } config := map[string]any{ - names.AttrAccessKey: servicemocks.MockStaticAccessKey, - names.AttrSecretKey: servicemocks.MockStaticSecretKey, - names.AttrRegion: region, - names.AttrSkipCredentialsValidation: true, - names.AttrSkipRequestingAccountID: true, + "access_key": servicemocks.MockStaticAccessKey, + "secret_key": servicemocks.MockStaticSecretKey, + "region": region, + "skip_credentials_validation": true, + "skip_requesting_account_id": true, } maps.Copy(config, setup.config) if setup.configFile.baseUrl != "" || setup.configFile.serviceUrl != "" { - config[names.AttrProfile] = "default" + config["profile"] = "default" tempDir := t.TempDir() writeSharedConfigFile(t, &config, tempDir, generateSharedConfigFile(setup.configFile)) } @@ -487,10 +486,10 @@ func writeSharedConfigFile(t *testing.T, config *map[string]any, tempDir, conten t.Fatalf(" writing shared configuration file: %s", err) } - if v, ok := (*config)[names.AttrSharedConfigFiles]; !ok { - (*config)[names.AttrSharedConfigFiles] = []any{file.Name()} + if v, ok := (*config)["shared_config_files"]; !ok { + (*config)["shared_config_files"] = []any{file.Name()} } else { - (*config)[names.AttrSharedConfigFiles] = append(v.([]any), file.Name()) + (*config)["shared_config_files"] = append(v.([]any), file.Name()) } return file.Name() diff --git a/internal/service/appfabric/service_package_gen.go b/internal/service/appfabric/service_package_gen.go index 1066d45117d..b543d8aa41e 100644 --- a/internal/service/appfabric/service_package_gen.go +++ b/internal/service/appfabric/service_package_gen.go @@ -19,7 +19,15 @@ func (p *servicePackage) FrameworkDataSources(ctx context.Context) []*types.Serv } func (p *servicePackage) FrameworkResources(ctx context.Context) []*types.ServicePackageFrameworkResource { - return []*types.ServicePackageFrameworkResource{} + return []*types.ServicePackageFrameworkResource{ + { + Factory: newResourceAppBundle, + Name: "AppBundle", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, + }, + } } func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePackageSDKDataSource { @@ -39,7 +47,7 @@ func (p *servicePackage) NewClient(ctx context.Context, config map[string]any) ( cfg := *(config["aws_sdkv2_config"].(*aws_sdkv2.Config)) return appfabric_sdkv2.NewFromConfig(cfg, func(o *appfabric_sdkv2.Options) { - if endpoint := config[names.AttrEndpoint].(string); endpoint != "" { + if endpoint := config["endpoint"].(string); endpoint != "" { o.BaseEndpoint = aws_sdkv2.String(endpoint) } }), nil diff --git a/internal/service/appfabric/tags_gen.go b/internal/service/appfabric/tags_gen.go new file mode 100644 index 00000000000..40bf0dbf729 --- /dev/null +++ b/internal/service/appfabric/tags_gen.go @@ -0,0 +1,94 @@ +// Code generated by internal/generate/tags/main.go; DO NOT EDIT. +package appfabric + +import ( + "context" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/appfabric" + awstypes "github.com/aws/aws-sdk-go-v2/service/appfabric/types" + "github.com/hashicorp/terraform-provider-aws/internal/conns" + tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" + "github.com/hashicorp/terraform-provider-aws/internal/types/option" +) + +// listTags lists appfabric service tags. +// The identifier is typically the Amazon Resource Name (ARN), although +// it may also be a different identifier depending on the service. +func listTags(ctx context.Context, conn *appfabric.Client, identifier string, optFns ...func(*appfabric.Options)) (tftags.KeyValueTags, error) { + input := &appfabric.ListTagsForResourceInput{ + ResourceArn: aws.String(identifier), + } + + output, err := conn.ListTagsForResource(ctx, input, optFns...) + + if err != nil { + return tftags.New(ctx, nil), err + } + + return KeyValueTags(ctx, output.Tags), nil +} + +// ListTags lists appfabric service tags and set them in Context. +// It is called from outside this package. +func (p *servicePackage) ListTags(ctx context.Context, meta any, identifier string) error { + tags, err := listTags(ctx, meta.(*conns.AWSClient).AppFabricClient(ctx), identifier) + + if err != nil { + return err + } + + if inContext, ok := tftags.FromContext(ctx); ok { + inContext.TagsOut = option.Some(tags) + } + + return nil +} + +// []*SERVICE.Tag handling + +// Tags returns appfabric service tags. +func Tags(tags tftags.KeyValueTags) []awstypes.Tag { + result := make([]awstypes.Tag, 0, len(tags)) + + for k, v := range tags.Map() { + tag := awstypes.Tag{ + Key: aws.String(k), + Value: aws.String(v), + } + + result = append(result, tag) + } + + return result +} + +// KeyValueTags creates tftags.KeyValueTags from appfabric service tags. +func KeyValueTags(ctx context.Context, tags []awstypes.Tag) tftags.KeyValueTags { + m := make(map[string]*string, len(tags)) + + for _, tag := range tags { + m[aws.ToString(tag.Key)] = tag.Value + } + + return tftags.New(ctx, m) +} + +// getTagsIn returns appfabric service tags from Context. +// nil is returned if there are no input tags. +func getTagsIn(ctx context.Context) []awstypes.Tag { + if inContext, ok := tftags.FromContext(ctx); ok { + if tags := Tags(inContext.TagsIn.UnwrapOrDefault()); len(tags) > 0 { + return tags + } + } + + return nil +} + +// setTagsOut sets appfabric service tags in Context. +func setTagsOut(ctx context.Context, tags []awstypes.Tag) { + if inContext, ok := tftags.FromContext(ctx); ok { + inContext.TagsOut = option.Some(KeyValueTags(ctx, tags)) + } +} From 1097acf3c73b1b3d3154419da088afa68cdfb3f5 Mon Sep 17 00:00:00 2001 From: Andrew Walko Date: Wed, 15 May 2024 11:58:36 -0500 Subject: [PATCH 02/29] AppBundle Tests Pass --- .go-version | 2 +- go.mod | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.go-version b/.go-version index 428abfd24fb..57807d6d0d0 100644 --- a/.go-version +++ b/.go-version @@ -1 +1 @@ -1.21.8 +1.22.0 diff --git a/go.mod b/go.mod index 02b3fa22d97..98b63d8000c 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/hashicorp/terraform-provider-aws -go 1.21 +go 1.22.0 require ( github.com/ProtonMail/go-crypto v1.1.0-alpha.2 From a44bd4c685f7c387f77bc1b4839350dc57e8f262 Mon Sep 17 00:00:00 2001 From: Andrew Walko Date: Wed, 15 May 2024 12:09:09 -0500 Subject: [PATCH 03/29] Final --- .go-version | 2 +- go.mod | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.go-version b/.go-version index 57807d6d0d0..6fee2fedb0a 100644 --- a/.go-version +++ b/.go-version @@ -1 +1 @@ -1.22.0 +1.22.2 diff --git a/go.mod b/go.mod index 98b63d8000c..c905a722c39 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/hashicorp/terraform-provider-aws -go 1.22.0 +go 1.22.2 require ( github.com/ProtonMail/go-crypto v1.1.0-alpha.2 From 233815fda9833a213eb32570b35995b975cd9adf Mon Sep 17 00:00:00 2001 From: Andrew Walko Date: Wed, 15 May 2024 13:05:06 -0500 Subject: [PATCH 04/29] All comments removed --- internal/service/appfabric/app_bundle.go | 5 -- internal/service/appfabric/app_bundle_test.go | 53 ------------------- internal/service/appfabric/exports_test.go | 1 - 3 files changed, 59 deletions(-) diff --git a/internal/service/appfabric/app_bundle.go b/internal/service/appfabric/app_bundle.go index 4389504354f..482d0cf3988 100644 --- a/internal/service/appfabric/app_bundle.go +++ b/internal/service/appfabric/app_bundle.go @@ -72,9 +72,6 @@ func (r *resourceAppBundle) Create(ctx context.Context, req resource.CreateReque Tags: getTagsIn(ctx), } - /*if !plan.CustomerManagedKeyArn.IsNull() { - in.CustomerManagedKeyIdentifier = aws.String(plan.CustomerManagedKeyArn.ValueString()) - }*/ out, err := conn.CreateAppBundle(ctx, in) if err != nil { resp.Diagnostics.AddError( @@ -129,7 +126,6 @@ func (r *resourceAppBundle) Read(ctx context.Context, req resource.ReadRequest, } func (r *resourceAppBundle) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { - //No update } func (r *resourceAppBundle) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { @@ -160,7 +156,6 @@ func (r *resourceAppBundle) Delete(ctx context.Context, req resource.DeleteReque } } -// change id to arn func (r *resourceAppBundle) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { resource.ImportStatePassthroughID(ctx, path.Root("arn"), req, resp) } diff --git a/internal/service/appfabric/app_bundle_test.go b/internal/service/appfabric/app_bundle_test.go index a275faf4a21..8659fb58ec5 100644 --- a/internal/service/appfabric/app_bundle_test.go +++ b/internal/service/appfabric/app_bundle_test.go @@ -3,36 +3,7 @@ package appfabric_test -// **PLEASE DELETE THIS AND ALL TIP COMMENTS BEFORE SUBMITTING A PR FOR REVIEW!** -// -// TIP: ==== INTRODUCTION ==== -// Thank you for trying the skaff tool! -// -// You have opted to include these helpful comments. They all include "TIP:" -// to help you find and remove them when you're done with them. -// -// While some aspects of this file are customized to your input, the -// scaffold tool does *not* look at the AWS API and ensure it has correct -// function, structure, and variable names. It makes guesses based on -// commonalities. You will need to make significant adjustments. -// -// In other words, as generated, this is a rough outline of the work you will -// need to do. If something doesn't make sense for your situation, get rid of -// it. - import ( - // TIP: ==== IMPORTS ==== - // This is a common set of imports but not customized to your code since - // your code hasn't been written yet. Make sure you, your IDE, or - // goimports -w fixes these imports. - // - // The provider linter wants your imports to be in two groups: first, - // standard library (i.e., "fmt" or "strings"), second, everything else. - // - // Also, AWS Go SDK v2 may handle nested structures differently than v1, - // using the services/appfabric/types package. If so, you'll - // need to import types and reference the nested types, e.g., as - // types.. "context" "errors" "fmt" @@ -50,23 +21,11 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/names" - // TIP: You will often need to import the package that this test file lives - // in. Since it is in the "test" context, it must import the package to use - // any normal context constants, variables, or functions. tfappfabric "github.com/hashicorp/terraform-provider-aws/internal/service/appfabric" ) -// TIP: ==== ACCEPTANCE TESTS ==== -// This is an example of a basic acceptance test. This should test as much of -// standard functionality of the resource as possible, and test importing, if -// applicable. We prefix its name with "TestAcc", the service, and the -// resource name. -// -// Acceptance test access AWS and cost money to run. func TestAccAppFabricAppBundle_basic(t *testing.T) { ctx := acctest.Context(t) - // TIP: This is a long-running test guard for tests that run longer than - // 300s (5 min) generally. if testing.Short() { t.Skip("skipping long-running test in short mode") } @@ -88,8 +47,6 @@ func TestAccAppFabricAppBundle_basic(t *testing.T) { Config: testAccAppBundleConfig_basic(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAppBundleExists(ctx, resourceName, &appbundle), - //resource.TestCheckResourceAttrSet(resourceName, "customer_managed_key_identifier"), - // Do we add client token here? ), }, { @@ -125,12 +82,6 @@ func TestAccAppFabricAppBundle_disappears(t *testing.T) { Config: testAccAppBundleConfig_basic(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAppBundleExists(ctx, resourceName, &appbundle), - // TIP: The Plugin-Framework disappears helper is similar to the Plugin-SDK version, - // but expects a new resource factory function as the third argument. To expose this - // private function to the testing package, you may need to add a line like the following - // to exports_test.go: - // - // var ResourceAppBundle = newResourceAppBundle acctest.CheckFrameworkResourceDisappears(ctx, acctest.Provider, tfappfabric.ResourceAppBundle, resourceName), ), ExpectNonEmptyPlan: true, @@ -186,7 +137,6 @@ func testAccCheckAppBundleExists(ctx context.Context, name string, appbundle *ap } } -// leave default func testAccPreCheck(ctx context.Context, t *testing.T) { conn := acctest.Provider.Meta().(*conns.AWSClient).AppFabricClient(ctx) input := &appfabric.ListAppBundlesInput{} @@ -233,9 +183,6 @@ func testAccAppBundleImportStateIDFunc(ctx context.Context, resourceName string) } } -// might need to change arn to app bundle identifier... not too sure here -// need to change to an actual arn -// not sure if needing customer managed key arn... func testAccAppBundleConfig_basic(rName string) string { return fmt.Sprintf(` resource "aws_appfabric_app_bundle" "test" { diff --git a/internal/service/appfabric/exports_test.go b/internal/service/appfabric/exports_test.go index b8b39031b66..d9e06aee345 100644 --- a/internal/service/appfabric/exports_test.go +++ b/internal/service/appfabric/exports_test.go @@ -3,7 +3,6 @@ package appfabric -// Exports for use in tests only. var ( ResourceAppBundle = newResourceAppBundle ) From d9c19d00483e69dc4f8d027401545a01efde5b63 Mon Sep 17 00:00:00 2001 From: Kait Healy Date: Wed, 29 May 2024 14:24:05 -0500 Subject: [PATCH 05/29] added framework resource and no op --- internal/service/appfabric/app_bundle.go | 4 ++++ internal/service/appfabric/app_bundle_test.go | 2 ++ 2 files changed, 6 insertions(+) diff --git a/internal/service/appfabric/app_bundle.go b/internal/service/appfabric/app_bundle.go index 482d0cf3988..af609d0e5c2 100644 --- a/internal/service/appfabric/app_bundle.go +++ b/internal/service/appfabric/app_bundle.go @@ -25,6 +25,9 @@ import ( "github.com/hashicorp/terraform-provider-aws/names" ) +// bedrock has this commented out... double check +@FrameworkResource(name="App Bundle") + func newResourceAppBundle(_ context.Context) (resource.ResourceWithConfigure, error) { r := &resourceAppBundle{} r.SetDefaultCreateTimeout(5 * time.Minute) @@ -125,6 +128,7 @@ func (r *resourceAppBundle) Read(ctx context.Context, req resource.ReadRequest, resp.Diagnostics.Append(resp.State.Set(ctx, &state)...) } +// There is no update API, so this method is a no-op func (r *resourceAppBundle) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { } diff --git a/internal/service/appfabric/app_bundle_test.go b/internal/service/appfabric/app_bundle_test.go index 8659fb58ec5..09d4b91914b 100644 --- a/internal/service/appfabric/app_bundle_test.go +++ b/internal/service/appfabric/app_bundle_test.go @@ -192,3 +192,5 @@ resource "aws_appfabric_app_bundle" "test" { } `) } + + From 7ffcb49eedfec2d67e0ea0494807897d8bf2b36a Mon Sep 17 00:00:00 2001 From: Kait Healy Date: Wed, 29 May 2024 15:00:11 -0500 Subject: [PATCH 06/29] added framework resource commented out --- internal/service/appfabric/app_bundle.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/service/appfabric/app_bundle.go b/internal/service/appfabric/app_bundle.go index af609d0e5c2..05042a0e038 100644 --- a/internal/service/appfabric/app_bundle.go +++ b/internal/service/appfabric/app_bundle.go @@ -25,8 +25,8 @@ import ( "github.com/hashicorp/terraform-provider-aws/names" ) -// bedrock has this commented out... double check -@FrameworkResource(name="App Bundle") +//@FrameworkResource(name="App Bundle") +// @Tags(identifierAttribute="arn") func newResourceAppBundle(_ context.Context) (resource.ResourceWithConfigure, error) { r := &resourceAppBundle{} From c4a4f55a9150b872a57b29c1590e6c732d3d2489 Mon Sep 17 00:00:00 2001 From: Kait Healy Date: Wed, 29 May 2024 15:10:00 -0500 Subject: [PATCH 07/29] adding endpointID --- internal/service/appfabric/app_bundle_test.go | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/internal/service/appfabric/app_bundle_test.go b/internal/service/appfabric/app_bundle_test.go index 09d4b91914b..2a5e2f05893 100644 --- a/internal/service/appfabric/app_bundle_test.go +++ b/internal/service/appfabric/app_bundle_test.go @@ -35,10 +35,8 @@ func TestAccAppFabricAppBundle_basic(t *testing.T) { resourceName := "aws_appfabric_app_bundle.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { - acctest.PreCheck(ctx, t) - testAccPreCheck(ctx, t) - }, + + PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, names.AppFabricEndpointID) }, ErrorCheck: acctest.ErrorCheck(t, names.AppFabricServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAppBundleDestroy(ctx), @@ -148,6 +146,7 @@ func testAccPreCheck(ctx context.Context, t *testing.T) { t.Fatalf("unexpected PreCheck error: %s", err) } } + func testAccCheckAppBundleNotRecreated(before, after *appfabric.GetAppBundleOutput) resource.TestCheckFunc { return func(s *terraform.State) error { if before, after := aws.ToString(before.AppBundle.Arn), aws.ToString(after.AppBundle.Arn); before != after { @@ -193,4 +192,15 @@ resource "aws_appfabric_app_bundle" "test" { `) } - +// env varaible for CMK? +/*func testAccAppBundleConfig_full(rName string) string { + return fmt.Sprintf(` +resource "aws_appfabric_app_bundle" "test" { + customer_managed_key = "customer-managed-key" + tags = { + Name = "AppFabricTesting" + } +} +`) +} +*/ From cdd2ebf01479498725fa22fb3a2efeb7b97b9666 Mon Sep 17 00:00:00 2001 From: Kait Healy Date: Wed, 29 May 2024 15:13:07 -0500 Subject: [PATCH 08/29] added precheck to other functions --- internal/service/appfabric/app_bundle_test.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/internal/service/appfabric/app_bundle_test.go b/internal/service/appfabric/app_bundle_test.go index 2a5e2f05893..3b8f16ff413 100644 --- a/internal/service/appfabric/app_bundle_test.go +++ b/internal/service/appfabric/app_bundle_test.go @@ -68,10 +68,7 @@ func TestAccAppFabricAppBundle_disappears(t *testing.T) { resourceName := "aws_appfabric_app_bundle.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { - acctest.PreCheck(ctx, t) - testAccPreCheck(ctx, t) - }, + PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, names.AppFabricEndpointID) }, ErrorCheck: acctest.ErrorCheck(t, names.AppFabricServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAppBundleDestroy(ctx), @@ -193,7 +190,7 @@ resource "aws_appfabric_app_bundle" "test" { } // env varaible for CMK? -/*func testAccAppBundleConfig_full(rName string) string { +func testAccAppBundleConfig_full(rName string) string { return fmt.Sprintf(` resource "aws_appfabric_app_bundle" "test" { customer_managed_key = "customer-managed-key" @@ -203,4 +200,4 @@ resource "aws_appfabric_app_bundle" "test" { } `) } -*/ + From 05ed84dfb3f50767351066932410bc28470b18f3 Mon Sep 17 00:00:00 2001 From: Kait Healy Date: Wed, 29 May 2024 15:13:45 -0500 Subject: [PATCH 09/29] delete basic --- internal/service/appfabric/app_bundle_test.go | 33 ------------------- 1 file changed, 33 deletions(-) diff --git a/internal/service/appfabric/app_bundle_test.go b/internal/service/appfabric/app_bundle_test.go index 3b8f16ff413..af36fedfe7f 100644 --- a/internal/service/appfabric/app_bundle_test.go +++ b/internal/service/appfabric/app_bundle_test.go @@ -24,39 +24,6 @@ import ( tfappfabric "github.com/hashicorp/terraform-provider-aws/internal/service/appfabric" ) -func TestAccAppFabricAppBundle_basic(t *testing.T) { - ctx := acctest.Context(t) - if testing.Short() { - t.Skip("skipping long-running test in short mode") - } - - var appbundle appfabric.GetAppBundleOutput - rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - resourceName := "aws_appfabric_app_bundle.test" - - resource.ParallelTest(t, resource.TestCase{ - - PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, names.AppFabricEndpointID) }, - ErrorCheck: acctest.ErrorCheck(t, names.AppFabricServiceID), - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - CheckDestroy: testAccCheckAppBundleDestroy(ctx), - Steps: []resource.TestStep{ - { - Config: testAccAppBundleConfig_basic(rName), - Check: resource.ComposeTestCheckFunc( - testAccCheckAppBundleExists(ctx, resourceName, &appbundle), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateIdFunc: testAccAppBundleImportStateIDFunc(ctx, resourceName), - ImportStateVerify: true, - }, - }, - }) -} - func TestAccAppFabricAppBundle_disappears(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { From f89fe1f8e7c2df97993fc03b82989bf5edbb1e95 Mon Sep 17 00:00:00 2001 From: Kait Healy Date: Wed, 29 May 2024 15:14:33 -0500 Subject: [PATCH 10/29] delete precheck function --- internal/service/appfabric/app_bundle_test.go | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/internal/service/appfabric/app_bundle_test.go b/internal/service/appfabric/app_bundle_test.go index af36fedfe7f..05fbbb635c3 100644 --- a/internal/service/appfabric/app_bundle_test.go +++ b/internal/service/appfabric/app_bundle_test.go @@ -99,18 +99,6 @@ func testAccCheckAppBundleExists(ctx context.Context, name string, appbundle *ap } } -func testAccPreCheck(ctx context.Context, t *testing.T) { - conn := acctest.Provider.Meta().(*conns.AWSClient).AppFabricClient(ctx) - input := &appfabric.ListAppBundlesInput{} - _, err := conn.ListAppBundles(ctx, input) - if acctest.PreCheckSkipError(err) { - t.Skipf("skipping acceptance testing: %s", err) - } - if err != nil { - t.Fatalf("unexpected PreCheck error: %s", err) - } -} - func testAccCheckAppBundleNotRecreated(before, after *appfabric.GetAppBundleOutput) resource.TestCheckFunc { return func(s *terraform.State) error { if before, after := aws.ToString(before.AppBundle.Arn), aws.ToString(after.AppBundle.Arn); before != after { From 7dc7a3066ed2e192eff0eb82df3fa7634ea2d57f Mon Sep 17 00:00:00 2001 From: Kait Healy Date: Wed, 29 May 2024 15:17:15 -0500 Subject: [PATCH 11/29] added full test --- internal/service/appfabric/app_bundle_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/service/appfabric/app_bundle_test.go b/internal/service/appfabric/app_bundle_test.go index 05fbbb635c3..e948ca3f0ea 100644 --- a/internal/service/appfabric/app_bundle_test.go +++ b/internal/service/appfabric/app_bundle_test.go @@ -144,7 +144,6 @@ resource "aws_appfabric_app_bundle" "test" { `) } -// env varaible for CMK? func testAccAppBundleConfig_full(rName string) string { return fmt.Sprintf(` resource "aws_appfabric_app_bundle" "test" { From 9ab3eded3d63dd54ab39cc56c47c5663c086059b Mon Sep 17 00:00:00 2001 From: Kait Healy Date: Wed, 29 May 2024 15:38:41 -0500 Subject: [PATCH 12/29] adding changelog --- .changelog/37542.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/37542.txt diff --git a/.changelog/37542.txt b/.changelog/37542.txt new file mode 100644 index 00000000000..66f64d2cdd9 --- /dev/null +++ b/.changelog/37542.txt @@ -0,0 +1,3 @@ +```release-note:new-resource +aws_appfabric_app_bundle +``` \ No newline at end of file From 9ac84ee7b3e38f9e5e6467797771ef389cf24e34 Mon Sep 17 00:00:00 2001 From: Andrew Walko Date: Wed, 29 May 2024 15:53:40 -0500 Subject: [PATCH 13/29] Update Tests, Added Documentation --- internal/service/appfabric/app_bundle_test.go | 8 ++- .../docs/r/appfabric_appbundle.html.markdown | 60 +++++++++++++++++++ 2 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 website/docs/r/appfabric_appbundle.html.markdown diff --git a/internal/service/appfabric/app_bundle_test.go b/internal/service/appfabric/app_bundle_test.go index e948ca3f0ea..9f3b12e513c 100644 --- a/internal/service/appfabric/app_bundle_test.go +++ b/internal/service/appfabric/app_bundle_test.go @@ -35,7 +35,10 @@ func TestAccAppFabricAppBundle_disappears(t *testing.T) { resourceName := "aws_appfabric_app_bundle.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, names.AppFabricEndpointID) }, + PreCheck: func() { + acctest.PreCheck(ctx, t); + //acctest.PreCheckPartitionHasService(t, names.AppFabricEndpointID) + }, ErrorCheck: acctest.ErrorCheck(t, names.AppFabricServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAppBundleDestroy(ctx), @@ -147,11 +150,10 @@ resource "aws_appfabric_app_bundle" "test" { func testAccAppBundleConfig_full(rName string) string { return fmt.Sprintf(` resource "aws_appfabric_app_bundle" "test" { - customer_managed_key = "customer-managed-key" + customer_managed_key = "arn:aws:kms:us-east-1:732859338261:key/c67081be-29a0-4049-a821-1436d27bde94" tags = { Name = "AppFabricTesting" } } `) } - diff --git a/website/docs/r/appfabric_appbundle.html.markdown b/website/docs/r/appfabric_appbundle.html.markdown new file mode 100644 index 00000000000..96d8d9f279b --- /dev/null +++ b/website/docs/r/appfabric_appbundle.html.markdown @@ -0,0 +1,60 @@ +--- +subcategory: "AppFabric" +layout: "aws" +page_title: "AWS: aws_appfabric_appbundle" +description: |- + Terraform resource for managing an AWS AppFabric AppBundle. +--- + +# Resource: aws_appfabric_appbundle + +Terraform resource for managing an AWS AppFabric AppBundle. + +## Example Usage + +### Basic Usage + +```terraform +resource "aws_appfabric_appbundle" "example" { + customer_managed_key_identifier = "[KMS CMK ARN]" + tags = { + Environment = "test" + } +} +``` + +## Argument Reference + +The following arguments are required: + +* There are no required arguments. + +## Attribute Reference + +This resource exports the following attributes in addition to the arguments above: + +* `arn` - ARN of the AppBundle. + +## Timeouts + +[Configuration options](https://developer.hashicorp.com/terraform/language/resources/syntax#operation-timeouts): + +* `create` - (Default `5m`) +* `update` - (Default `5m`) +* `delete` - (Default `5m`) + +## Import +In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import AppFabric AppBundle using the `arn`. For example: + +```terraform +import { + to = aws_appfabric_appbundle.example + id = "arn:aws:appfabric:[region]:[account]:appbundle/ee5587b4-5765-4288-a202-xxxxxxxxxx" +} +``` + +Using `terraform import`, import AppFabric AppBundle using the `arn`. For example: + +```console +% terraform import aws_appfabric_appbundle.example arn:aws:appfabric:[region]:[account]:appbundle/ee5587b4-5765-4288-a202-xxxxxxxxxx +``` \ No newline at end of file From 804a8a23b04f5cbda31994a9e35c76b8355c3807 Mon Sep 17 00:00:00 2001 From: Andrew Walko Date: Wed, 29 May 2024 16:01:22 -0500 Subject: [PATCH 14/29] All comments addressed --- internal/service/appfabric/app_bundle_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/service/appfabric/app_bundle_test.go b/internal/service/appfabric/app_bundle_test.go index 9f3b12e513c..39faa83c1a5 100644 --- a/internal/service/appfabric/app_bundle_test.go +++ b/internal/service/appfabric/app_bundle_test.go @@ -35,9 +35,9 @@ func TestAccAppFabricAppBundle_disappears(t *testing.T) { resourceName := "aws_appfabric_app_bundle.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { - acctest.PreCheck(ctx, t); - //acctest.PreCheckPartitionHasService(t, names.AppFabricEndpointID) + PreCheck: func() { + acctest.PreCheck(ctx, t) + //acctest.PreCheckPartitionHasService(t, names.AppFabricEndpointID) }, ErrorCheck: acctest.ErrorCheck(t, names.AppFabricServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, From 719792700fd5fc31fa4e2c849f240adfe5506b07 Mon Sep 17 00:00:00 2001 From: Andrew Walko Date: Fri, 31 May 2024 15:55:06 -0500 Subject: [PATCH 15/29] Added 3 tests: 1 for customer_managed_key and 2 for tags --- internal/service/appfabric/app_bundle_test.go | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/internal/service/appfabric/app_bundle_test.go b/internal/service/appfabric/app_bundle_test.go index 39faa83c1a5..19dfa595b16 100644 --- a/internal/service/appfabric/app_bundle_test.go +++ b/internal/service/appfabric/app_bundle_test.go @@ -147,6 +147,35 @@ resource "aws_appfabric_app_bundle" "test" { `) } +func testAccAppBundleConfig_customer_managed_key() string { + return fmt.Sprintf(` +resource "aws_appfabric_app_bundle" "test" { + customer_managed_key = "arn:aws:kms:us-east-1:732859338261:key/c67081be-29a0-4049-a821-1436d27bde94" +} +`) +} + +func testAccAppBundleConfig_tags1(tagKey1, tagValue1 string) string { + return fmt.Sprintf(` +resource "aws_appfabric_app_bundle" "test" { + tags = { + %[1]q = %[2]q + } +} +`, tagKey1, tagValue1) +} + +func testAccAppBundleConfig_tags2(tagKey1, tagValue1, tagKey2, tagValue2 string) string { + return fmt.Sprintf(` +resource "aws_appfabric_app_bundle" "test" { + tags = { + %[1]q = %[2]q + %[3]q = %[4]q + } +} +`, tagKey1, tagValue1, tagKey2, tagValue2) +} + func testAccAppBundleConfig_full(rName string) string { return fmt.Sprintf(` resource "aws_appfabric_app_bundle" "test" { From dbf75db716975bd3107e3cf3f8abe9a0958a89fc Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 11 Jun 2024 07:30:05 -0700 Subject: [PATCH 16/29] r/aws_appfabric_app_bundle: Tidy up. --- internal/service/appfabric/app_bundle.go | 210 +++++++++--------- internal/service/appfabric/app_bundle_test.go | 103 +++------ internal/service/appfabric/exports_test.go | 5 +- names/names.go | 1 + .../docs/r/appfabric_app_bundle.html.markdown | 54 +++++ .../docs/r/appfabric_appbundle.html.markdown | 60 ----- 6 files changed, 188 insertions(+), 245 deletions(-) create mode 100644 website/docs/r/appfabric_app_bundle.html.markdown delete mode 100644 website/docs/r/appfabric_appbundle.html.markdown diff --git a/internal/service/appfabric/app_bundle.go b/internal/service/appfabric/app_bundle.go index 05042a0e038..caafb806475 100644 --- a/internal/service/appfabric/app_bundle.go +++ b/internal/service/appfabric/app_bundle.go @@ -5,56 +5,56 @@ package appfabric import ( "context" - "errors" - "time" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/appfabric" awstypes "github.com/aws/aws-sdk-go-v2/service/appfabric/types" - "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/types" + sdkid "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" - "github.com/hashicorp/terraform-provider-aws/internal/create" "github.com/hashicorp/terraform-provider-aws/internal/errs" + "github.com/hashicorp/terraform-provider-aws/internal/errs/fwdiag" "github.com/hashicorp/terraform-provider-aws/internal/framework" - "github.com/hashicorp/terraform-provider-aws/internal/framework/flex" + fwflex "github.com/hashicorp/terraform-provider-aws/internal/framework/flex" + fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/names" ) -//@FrameworkResource(name="App Bundle") +// @FrameworkResource(name="App Bundle") // @Tags(identifierAttribute="arn") +func newAppBundleResource(context.Context) (resource.ResourceWithConfigure, error) { + r := &appBundleResource{} -func newResourceAppBundle(_ context.Context) (resource.ResourceWithConfigure, error) { - r := &resourceAppBundle{} - r.SetDefaultCreateTimeout(5 * time.Minute) - r.SetDefaultUpdateTimeout(5 * time.Minute) - r.SetDefaultDeleteTimeout(5 * time.Minute) return r, nil } -const ( - ResNameAppBundle = "AppBundle" -) - -type resourceAppBundle struct { +type appBundleResource struct { framework.ResourceWithConfigure - framework.WithTimeouts + framework.WithNoOpUpdate[appBundleResourceModel] + framework.WithImportByID } -func (r *resourceAppBundle) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { - resp.TypeName = "aws_appfabric_app_bundle" +func (*appBundleResource) Metadata(_ context.Context, request resource.MetadataRequest, response *resource.MetadataResponse) { + response.TypeName = "aws_appfabric_app_bundle" } -func (r *resourceAppBundle) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { - resp.Schema = schema.Schema{ +func (r *appBundleResource) Schema(ctx context.Context, request resource.SchemaRequest, response *resource.SchemaResponse) { + response.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ - "arn": framework.ARNAttributeComputedOnly(), - "customer_managed_key_identifier": schema.StringAttribute{ - Optional: true, + names.AttrARN: framework.ARNAttributeComputedOnly(), + "customer_managed_key_arn": schema.StringAttribute{ + CustomType: fwtypes.ARNType, + Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, }, names.AttrID: framework.IDAttribute(), names.AttrTags: tftags.TagsAttribute(), @@ -63,142 +63,136 @@ func (r *resourceAppBundle) Schema(ctx context.Context, req resource.SchemaReque } } -func (r *resourceAppBundle) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { - conn := r.Meta().AppFabricClient(ctx) - - var plan resourceAppBundleData - resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) - if resp.Diagnostics.HasError() { +func (r *appBundleResource) Create(ctx context.Context, request resource.CreateRequest, response *resource.CreateResponse) { + var data appBundleResourceModel + response.Diagnostics.Append(request.Plan.Get(ctx, &data)...) + if response.Diagnostics.HasError() { return } - in := &appfabric.CreateAppBundleInput{ - Tags: getTagsIn(ctx), + + conn := r.Meta().AppFabricClient(ctx) + + input := &appfabric.CreateAppBundleInput{ + ClientToken: aws.String(sdkid.UniqueId()), + CustomerManagedKeyIdentifier: fwflex.StringFromFramework(ctx, data.CustomerManagedKeyARN), + Tags: getTagsIn(ctx), } - out, err := conn.CreateAppBundle(ctx, in) + output, err := conn.CreateAppBundle(ctx, input) + if err != nil { - resp.Diagnostics.AddError( - create.ProblemStandardMessage(names.AppFabric, create.ErrActionCreating, ResNameAppBundle, plan.ARN.String(), err), - err.Error(), - ) - return - } - if out == nil || out.AppBundle == nil { - resp.Diagnostics.AddError( - create.ProblemStandardMessage(names.AppFabric, create.ErrActionCreating, ResNameAppBundle, plan.ARN.String(), nil), - errors.New("empty output").Error(), - ) + response.Diagnostics.AddError("creating AppFabric App Bundle", err.Error()) + return } - plan.ARN = flex.StringToFramework(ctx, out.AppBundle.Arn) - plan.CustomerManagedKeyArn = flex.StringToFramework(ctx, out.AppBundle.CustomerManagedKeyArn) - plan.ID = types.StringValue(string(*out.AppBundle.Arn)) + // Set values for unknowns. + data.ARN = fwflex.StringToFramework(ctx, output.AppBundle.Arn) + data.setID() - resp.Diagnostics.Append(resp.State.Set(ctx, plan)...) + response.Diagnostics.Append(response.State.Set(ctx, data)...) } -func (r *resourceAppBundle) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { - conn := r.Meta().AppFabricClient(ctx) +func (r *appBundleResource) Read(ctx context.Context, request resource.ReadRequest, response *resource.ReadResponse) { + var data appBundleResourceModel + response.Diagnostics.Append(request.State.Get(ctx, &data)...) + if response.Diagnostics.HasError() { + return + } + if err := data.InitFromID(); err != nil { + response.Diagnostics.AddError("parsing resource ID", err.Error()) - var state resourceAppBundleData - resp.Diagnostics.Append(req.State.Get(ctx, &state)...) - if resp.Diagnostics.HasError() { return } - out, err := findAppBundleByID(ctx, conn, state.ARN.ValueString()) + conn := r.Meta().AppFabricClient(ctx) + + appBundle, err := findAppBundleByID(ctx, conn, data.ID.ValueString()) if tfresource.NotFound(err) { - resp.State.RemoveResource(ctx) + response.Diagnostics.Append(fwdiag.NewResourceNotFoundWarningDiagnostic(err)) + response.State.RemoveResource(ctx) return } + if err != nil { - resp.Diagnostics.AddError( - create.ProblemStandardMessage(names.AppFabric, create.ErrActionSetting, ResNameAppBundle, state.ARN.String(), err), - err.Error(), - ) + response.Diagnostics.AddError(fmt.Sprintf("reading AppFabric App Bundle (%s)", data.ID.ValueString()), err.Error()) + return } - state.ARN = flex.StringToFramework(ctx, out.Arn) - state.CustomerManagedKeyArn = flex.StringToFramework(ctx, out.CustomerManagedKeyArn) - state.ID = types.StringValue(string(*out.Arn)) - - resp.Diagnostics.Append(resp.State.Set(ctx, &state)...) -} + // Set attributes for import. + response.Diagnostics.Append(fwflex.Flatten(ctx, appBundle, &data)...) + if response.Diagnostics.HasError() { + return + } -// There is no update API, so this method is a no-op -func (r *resourceAppBundle) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + response.Diagnostics.Append(response.State.Set(ctx, &data)...) } -func (r *resourceAppBundle) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { +func (r *appBundleResource) Delete(ctx context.Context, request resource.DeleteRequest, response *resource.DeleteResponse) { + var data appBundleResourceModel + response.Diagnostics.Append(request.State.Get(ctx, &data)...) + if response.Diagnostics.HasError() { + return + } conn := r.Meta().AppFabricClient(ctx) - var state resourceAppBundleData - resp.Diagnostics.Append(req.State.Get(ctx, &state)...) - if resp.Diagnostics.HasError() { - return - } + _, err := conn.DeleteAppBundle(ctx, &appfabric.DeleteAppBundleInput{ + AppBundleIdentifier: aws.String(data.ID.ValueString()), + }) - in := &appfabric.DeleteAppBundleInput{ - AppBundleIdentifier: aws.String(state.ARN.ValueString()), + if errs.IsA[*awstypes.ResourceNotFoundException](err) { + return } - _, err := conn.DeleteAppBundle(ctx, in) - if err != nil { - if errs.IsA[*awstypes.ResourceNotFoundException](err) { - return - } - resp.Diagnostics.AddError( - create.ProblemStandardMessage(names.AppFabric, create.ErrActionDeleting, ResNameAppBundle, state.ARN.String(), err), - err.Error(), - ) + response.Diagnostics.AddError(fmt.Sprintf("deleting AppFabric App Bundle (%s)", data.ID.ValueString()), err.Error()) + return } } -func (r *resourceAppBundle) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { - resource.ImportStatePassthroughID(ctx, path.Root("arn"), req, resp) -} - -const ( - statusChangePending = "Pending" - statusDeleting = "Deleting" - statusNormal = "Normal" - statusUpdated = "Updated" -) - func findAppBundleByID(ctx context.Context, conn *appfabric.Client, arn string) (*awstypes.AppBundle, error) { - in := &appfabric.GetAppBundleInput{ + input := &appfabric.GetAppBundleInput{ AppBundleIdentifier: aws.String(arn), } - out, err := conn.GetAppBundle(ctx, in) - if err != nil { - if errs.IsA[*awstypes.ResourceNotFoundException](err) { - return nil, &retry.NotFoundError{ - LastError: err, - LastRequest: in, - } + output, err := conn.GetAppBundle(ctx, input) + + if errs.IsA[*awstypes.ResourceNotFoundException](err) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: input, } + } + if err != nil { return nil, err } - if out == nil || out.AppBundle == nil { - return nil, tfresource.NewEmptyResultError(in) + if output == nil || output.AppBundle == nil { + return nil, tfresource.NewEmptyResultError(input) } - return out.AppBundle, nil + return output.AppBundle, nil } -type resourceAppBundleData struct { +type appBundleResourceModel struct { ARN types.String `tfsdk:"arn"` - CustomerManagedKeyArn types.String `tfsdk:"customer_managed_key_identifier"` + CustomerManagedKeyARN types.String `tfsdk:"customer_managed_key_arn"` ID types.String `tfsdk:"id"` Tags types.Map `tfsdk:"tags"` TagsAll types.Map `tfsdk:"tags_all"` } + +func (data *appBundleResourceModel) InitFromID() error { + data.ARN = data.ID + + return nil +} + +func (data *appBundleResourceModel) setID() { + data.ID = data.ARN +} diff --git a/internal/service/appfabric/app_bundle_test.go b/internal/service/appfabric/app_bundle_test.go index 19dfa595b16..67203a7a3bd 100644 --- a/internal/service/appfabric/app_bundle_test.go +++ b/internal/service/appfabric/app_bundle_test.go @@ -5,23 +5,17 @@ package appfabric_test import ( "context" - "errors" "fmt" "testing" - "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/service/appfabric" - "github.com/aws/aws-sdk-go-v2/service/appfabric/types" - sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" + awstypes "github.com/aws/aws-sdk-go-v2/service/appfabric/types" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-aws/internal/acctest" "github.com/hashicorp/terraform-provider-aws/internal/conns" - "github.com/hashicorp/terraform-provider-aws/internal/create" - "github.com/hashicorp/terraform-provider-aws/internal/errs" - "github.com/hashicorp/terraform-provider-aws/names" - tfappfabric "github.com/hashicorp/terraform-provider-aws/internal/service/appfabric" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + "github.com/hashicorp/terraform-provider-aws/names" ) func TestAccAppFabricAppBundle_disappears(t *testing.T) { @@ -29,22 +23,20 @@ func TestAccAppFabricAppBundle_disappears(t *testing.T) { if testing.Short() { t.Skip("skipping long-running test in short mode") } - - var appbundle appfabric.GetAppBundleOutput - rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + var appbundle awstypes.AppBundle resourceName := "aws_appfabric_app_bundle.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - //acctest.PreCheckPartitionHasService(t, names.AppFabricEndpointID) + acctest.PreCheckPartitionHasService(t, names.AppFabricEndpointID) }, ErrorCheck: acctest.ErrorCheck(t, names.AppFabricServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAppBundleDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccAppBundleConfig_basic(rName), + Config: testAccAppBundleConfig_basic, Check: resource.ComposeTestCheckFunc( testAccCheckAppBundleExists(ctx, resourceName, &appbundle), acctest.CheckFrameworkResourceDisappears(ctx, acctest.Provider, tfappfabric.ResourceAppBundle, resourceName), @@ -64,88 +56,47 @@ func testAccCheckAppBundleDestroy(ctx context.Context) resource.TestCheckFunc { continue } - _, err := conn.GetAppBundle(ctx, &appfabric.GetAppBundleInput{ - AppBundleIdentifier: aws.String(rs.Primary.Attributes["arn"]), - }) - if errs.IsA[*types.ResourceNotFoundException](err) { - return nil + _, err := tfappfabric.FindAppBundleByID(ctx, conn, rs.Primary.ID) + + if tfresource.NotFound(err) { + continue } + if err != nil { - return create.Error(names.AppFabric, create.ErrActionCheckingDestroyed, tfappfabric.ResNameAppBundle, rs.Primary.ID, err) + return err } - return create.Error(names.AppFabric, create.ErrActionCheckingDestroyed, tfappfabric.ResNameAppBundle, rs.Primary.ID, errors.New("not destroyed")) + return fmt.Errorf("AppFabric App Bundle %s still exists", rs.Primary.ID) } return nil } } -func testAccCheckAppBundleExists(ctx context.Context, name string, appbundle *appfabric.GetAppBundleOutput) resource.TestCheckFunc { +func testAccCheckAppBundleExists(ctx context.Context, n string, v *awstypes.AppBundle) resource.TestCheckFunc { return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[name] - if !ok { - return create.Error(names.AppFabric, create.ErrActionCheckingExistence, tfappfabric.ResNameAppBundle, name, errors.New("not found")) - } - if rs.Primary.ID == "" { - return create.Error(names.AppFabric, create.ErrActionCheckingExistence, tfappfabric.ResNameAppBundle, name, errors.New("not set")) - } - conn := acctest.Provider.Meta().(*conns.AWSClient).AppFabricClient(ctx) - resp, err := conn.GetAppBundle(ctx, &appfabric.GetAppBundleInput{ - AppBundleIdentifier: aws.String(rs.Primary.Attributes["arn"]), - }) - if err != nil { - return create.Error(names.AppFabric, create.ErrActionCheckingExistence, tfappfabric.ResNameAppBundle, rs.Primary.ID, err) - } - *appbundle = *resp - return nil - } -} - -func testAccCheckAppBundleNotRecreated(before, after *appfabric.GetAppBundleOutput) resource.TestCheckFunc { - return func(s *terraform.State) error { - if before, after := aws.ToString(before.AppBundle.Arn), aws.ToString(after.AppBundle.Arn); before != after { - return create.Error(names.AppFabric, create.ErrActionCheckingNotRecreated, tfappfabric.ResNameAppBundle, before, errors.New("recreated")) - } - return nil - } -} - -func testAccAppBundleImportStateIDFunc(ctx context.Context, resourceName string) resource.ImportStateIdFunc { - return func(s *terraform.State) (string, error) { - rs, ok := s.RootModule().Resources[resourceName] + rs, ok := s.RootModule().Resources[n] if !ok { - return "", fmt.Errorf("Not found: %s", resourceName) - } - - if rs.Primary.ID == "" { - return "", errors.New("No AppBundle ID set") + return fmt.Errorf("Not found: %s", n) } conn := acctest.Provider.Meta().(*conns.AWSClient).AppFabricClient(ctx) - appBundleARN := rs.Primary.Attributes["arn"] - _, err := conn.GetAppBundle(ctx, &appfabric.GetAppBundleInput{ - AppBundleIdentifier: aws.String(appBundleARN), - }) + output, err := tfappfabric.FindAppBundleByID(ctx, conn, rs.Primary.ID) if err != nil { - return "", err + return err } - return appBundleARN, nil - } -} + *v = *output -func testAccAppBundleConfig_basic(rName string) string { - return fmt.Sprintf(` -resource "aws_appfabric_app_bundle" "test" { - tags = { - Name = "AppFabricTesting" + return nil } } -`) -} + +const testAccAppBundleConfig_basic = ` +resource "aws_appfabric_app_bundle" "test" {} +` func testAccAppBundleConfig_customer_managed_key() string { return fmt.Sprintf(` @@ -158,9 +109,9 @@ resource "aws_appfabric_app_bundle" "test" { func testAccAppBundleConfig_tags1(tagKey1, tagValue1 string) string { return fmt.Sprintf(` resource "aws_appfabric_app_bundle" "test" { - tags = { - %[1]q = %[2]q - } + tags = { + %[1]q = %[2]q + } } `, tagKey1, tagValue1) } diff --git a/internal/service/appfabric/exports_test.go b/internal/service/appfabric/exports_test.go index d9e06aee345..dd4ba7c43b7 100644 --- a/internal/service/appfabric/exports_test.go +++ b/internal/service/appfabric/exports_test.go @@ -3,6 +3,9 @@ package appfabric +// Exports for use in tests only. var ( - ResourceAppBundle = newResourceAppBundle + ResourceAppBundle = newAppBundleResource + + FindAppBundleByID = findAppBundleByID ) diff --git a/names/names.go b/names/names.go index 2bfc30f0225..4bf45007319 100644 --- a/names/names.go +++ b/names/names.go @@ -30,6 +30,7 @@ const ( AMPEndpointID = "aps" AppStreamEndpointID = "appstream2" ApplicationAutoscalingEndpointID = "application-autoscaling" + AppFabricEndpointID = "appfabric" AppIntegrationsEndpointID = "app-integrations" AppConfigEndpointID = "appconfig" AmplifyEndpointID = "amplify" diff --git a/website/docs/r/appfabric_app_bundle.html.markdown b/website/docs/r/appfabric_app_bundle.html.markdown new file mode 100644 index 00000000000..e7e14c8060c --- /dev/null +++ b/website/docs/r/appfabric_app_bundle.html.markdown @@ -0,0 +1,54 @@ +--- +subcategory: "AppFabric" +layout: "aws" +page_title: "AWS: aws_appfabric_app_bundle" +description: |- + Terraform resource for managing an AWS AppFabric AppBundle. +--- + +# Resource: aws_appfabric_app_bundle + +Terraform resource for managing an AWS AppFabric AppBundle. + +## Example Usage + +### Basic Usage + +```terraform +resource "aws_appfabric_app_bundle" "example" { + customer_managed_key_arn = awms_kms_key.example.arn + tags = { + Environment = "test" + } +} +``` + +## Argument Reference + +This resource supports the following arguments: + +* `customer_managed_key_arn` - (Optional) The Amazon Resource Name (ARN) of the AWS Key Management Service (AWS KMS) key to use to encrypt the application data. If this is not specified, an AWS owned key is used for encryption. +* `tags` - (Optional) Map of tags to assign to the resource. If configured with a provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level. + +## Attribute Reference + +This resource exports the following attributes in addition to the arguments above: + +* `arn` - ARN of the AppBundle. +* `tags_all` - Map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block). + +## Import +In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import AppFabric AppBundle using the `arn`. For example: + +```terraform +import { + to = aws_appfabric_appbundle.example + id = "arn:aws:appfabric:[region]:[account]:appbundle/ee5587b4-5765-4288-a202-xxxxxxxxxx" +} +``` + +Using `terraform import`, import AppFabric AppBundle using the `arn`. For example: + +```console +% terraform import aws_appfabric_appbundle.example arn:aws:appfabric:[region]:[account]:appbundle/ee5587b4-5765-4288-a202-xxxxxxxxxx +``` \ No newline at end of file diff --git a/website/docs/r/appfabric_appbundle.html.markdown b/website/docs/r/appfabric_appbundle.html.markdown deleted file mode 100644 index 96d8d9f279b..00000000000 --- a/website/docs/r/appfabric_appbundle.html.markdown +++ /dev/null @@ -1,60 +0,0 @@ ---- -subcategory: "AppFabric" -layout: "aws" -page_title: "AWS: aws_appfabric_appbundle" -description: |- - Terraform resource for managing an AWS AppFabric AppBundle. ---- - -# Resource: aws_appfabric_appbundle - -Terraform resource for managing an AWS AppFabric AppBundle. - -## Example Usage - -### Basic Usage - -```terraform -resource "aws_appfabric_appbundle" "example" { - customer_managed_key_identifier = "[KMS CMK ARN]" - tags = { - Environment = "test" - } -} -``` - -## Argument Reference - -The following arguments are required: - -* There are no required arguments. - -## Attribute Reference - -This resource exports the following attributes in addition to the arguments above: - -* `arn` - ARN of the AppBundle. - -## Timeouts - -[Configuration options](https://developer.hashicorp.com/terraform/language/resources/syntax#operation-timeouts): - -* `create` - (Default `5m`) -* `update` - (Default `5m`) -* `delete` - (Default `5m`) - -## Import -In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import AppFabric AppBundle using the `arn`. For example: - -```terraform -import { - to = aws_appfabric_appbundle.example - id = "arn:aws:appfabric:[region]:[account]:appbundle/ee5587b4-5765-4288-a202-xxxxxxxxxx" -} -``` - -Using `terraform import`, import AppFabric AppBundle using the `arn`. For example: - -```console -% terraform import aws_appfabric_appbundle.example arn:aws:appfabric:[region]:[account]:appbundle/ee5587b4-5765-4288-a202-xxxxxxxxxx -``` \ No newline at end of file From 7d46e8fc8545184dd76355b59b9209431188c419 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 11 Jun 2024 07:44:09 -0700 Subject: [PATCH 17/29] r/aws_appfabric_app_bundle: Additional acceptance tests. --- internal/service/appfabric/app_bundle_test.go | 109 +++++++++++++----- 1 file changed, 83 insertions(+), 26 deletions(-) diff --git a/internal/service/appfabric/app_bundle_test.go b/internal/service/appfabric/app_bundle_test.go index 67203a7a3bd..560b4690463 100644 --- a/internal/service/appfabric/app_bundle_test.go +++ b/internal/service/appfabric/app_bundle_test.go @@ -18,11 +18,39 @@ import ( "github.com/hashicorp/terraform-provider-aws/names" ) +func TestAccAppFabricAppBundle_basic(t *testing.T) { + ctx := acctest.Context(t) + var appbundle awstypes.AppBundle + resourceName := "aws_appfabric_app_bundle.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, names.AppFabricEndpointID) + }, + ErrorCheck: acctest.ErrorCheck(t, names.AppFabricServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckAppBundleDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccAppBundleConfig_basic, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckAppBundleExists(ctx, resourceName, &appbundle), + resource.TestCheckNoResourceAttr(resourceName, "customer_managed_key_arn"), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, acctest.Ct0), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccAppFabricAppBundle_disappears(t *testing.T) { ctx := acctest.Context(t) - if testing.Short() { - t.Skip("skipping long-running test in short mode") - } var appbundle awstypes.AppBundle resourceName := "aws_appfabric_app_bundle.test" @@ -47,6 +75,54 @@ func TestAccAppFabricAppBundle_disappears(t *testing.T) { }) } +func TestAccAppFabricAppBundle_tags(t *testing.T) { + ctx := acctest.Context(t) + var appbundle awstypes.AppBundle + resourceName := "aws_appfabric_app_bundle.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, names.AppFabricEndpointID) + }, + ErrorCheck: acctest.ErrorCheck(t, names.AppFabricServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckAppBundleDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccAppBundleConfig_tags1(acctest.CtKey1, acctest.CtValue1), + Check: resource.ComposeTestCheckFunc( + testAccCheckAppBundleExists(ctx, resourceName, &appbundle), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, acctest.Ct1), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey1, acctest.CtValue1), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccAppBundleConfig_tags2(acctest.CtKey1, acctest.CtValue1Updated, acctest.CtKey2, acctest.CtValue2), + Check: resource.ComposeTestCheckFunc( + testAccCheckAppBundleExists(ctx, resourceName, &appbundle), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, acctest.Ct2), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey1, acctest.CtValue1Updated), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey2, acctest.CtValue2), + ), + }, + { + Config: testAccAppBundleConfig_tags1(acctest.CtKey2, acctest.CtValue2), + Check: resource.ComposeTestCheckFunc( + testAccCheckAppBundleExists(ctx, resourceName, &appbundle), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, acctest.Ct1), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey2, acctest.CtValue2), + ), + }, + }, + }) +} + func testAccCheckAppBundleDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { conn := acctest.Provider.Meta().(*conns.AWSClient).AppFabricClient(ctx) @@ -98,14 +174,6 @@ const testAccAppBundleConfig_basic = ` resource "aws_appfabric_app_bundle" "test" {} ` -func testAccAppBundleConfig_customer_managed_key() string { - return fmt.Sprintf(` -resource "aws_appfabric_app_bundle" "test" { - customer_managed_key = "arn:aws:kms:us-east-1:732859338261:key/c67081be-29a0-4049-a821-1436d27bde94" -} -`) -} - func testAccAppBundleConfig_tags1(tagKey1, tagValue1 string) string { return fmt.Sprintf(` resource "aws_appfabric_app_bundle" "test" { @@ -119,21 +187,10 @@ resource "aws_appfabric_app_bundle" "test" { func testAccAppBundleConfig_tags2(tagKey1, tagValue1, tagKey2, tagValue2 string) string { return fmt.Sprintf(` resource "aws_appfabric_app_bundle" "test" { - tags = { - %[1]q = %[2]q - %[3]q = %[4]q - } + tags = { + %[1]q = %[2]q + %[3]q = %[4]q + } } `, tagKey1, tagValue1, tagKey2, tagValue2) } - -func testAccAppBundleConfig_full(rName string) string { - return fmt.Sprintf(` -resource "aws_appfabric_app_bundle" "test" { - customer_managed_key = "arn:aws:kms:us-east-1:732859338261:key/c67081be-29a0-4049-a821-1436d27bde94" - tags = { - Name = "AppFabricTesting" - } -} -`) -} From 720565ed7126a937da4d13b7893fd0261dbc149c Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 11 Jun 2024 07:46:07 -0700 Subject: [PATCH 18/29] Fix markdown-lint 'MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below]'. --- website/docs/r/appfabric_app_bundle.html.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/website/docs/r/appfabric_app_bundle.html.markdown b/website/docs/r/appfabric_app_bundle.html.markdown index e7e14c8060c..11d2421f57d 100644 --- a/website/docs/r/appfabric_app_bundle.html.markdown +++ b/website/docs/r/appfabric_app_bundle.html.markdown @@ -38,6 +38,7 @@ This resource exports the following attributes in addition to the arguments abov * `tags_all` - Map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block). ## Import + In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import AppFabric AppBundle using the `arn`. For example: ```terraform From 8e1a95ab343a7b2cbbf4bb512f9c1727d347b8c0 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 11 Jun 2024 07:46:58 -0700 Subject: [PATCH 19/29] Fix markdown-lint 'MD047/single-trailing-newline Files should end with a single newline character'. --- website/docs/r/appfabric_app_bundle.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/appfabric_app_bundle.html.markdown b/website/docs/r/appfabric_app_bundle.html.markdown index 11d2421f57d..cc4a1c4e360 100644 --- a/website/docs/r/appfabric_app_bundle.html.markdown +++ b/website/docs/r/appfabric_app_bundle.html.markdown @@ -52,4 +52,4 @@ Using `terraform import`, import AppFabric AppBundle using the `arn`. For exampl ```console % terraform import aws_appfabric_appbundle.example arn:aws:appfabric:[region]:[account]:appbundle/ee5587b4-5765-4288-a202-xxxxxxxxxx -``` \ No newline at end of file +``` From 9cc2cd58d31d22e85629e7441c8eea12d7bf539f Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 11 Jun 2024 07:50:33 -0700 Subject: [PATCH 20/29] Fix documentation terrafmt errors. --- website/docs/r/appfabric_app_bundle.html.markdown | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/website/docs/r/appfabric_app_bundle.html.markdown b/website/docs/r/appfabric_app_bundle.html.markdown index cc4a1c4e360..b58703077e1 100644 --- a/website/docs/r/appfabric_app_bundle.html.markdown +++ b/website/docs/r/appfabric_app_bundle.html.markdown @@ -16,8 +16,8 @@ Terraform resource for managing an AWS AppFabric AppBundle. ```terraform resource "aws_appfabric_app_bundle" "example" { - customer_managed_key_arn = awms_kms_key.example.arn - tags = { + customer_managed_key_arn = awms_kms_key.example.arn + tags = { Environment = "test" } } @@ -43,7 +43,7 @@ In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashico ```terraform import { - to = aws_appfabric_appbundle.example + to = aws_appfabric_app_bundle.example id = "arn:aws:appfabric:[region]:[account]:appbundle/ee5587b4-5765-4288-a202-xxxxxxxxxx" } ``` @@ -51,5 +51,5 @@ import { Using `terraform import`, import AppFabric AppBundle using the `arn`. For example: ```console -% terraform import aws_appfabric_appbundle.example arn:aws:appfabric:[region]:[account]:appbundle/ee5587b4-5765-4288-a202-xxxxxxxxxx +% terraform import aws_appfabric_app_bundle.example arn:aws:appfabric:[region]:[account]:appbundle/ee5587b4-5765-4288-a202-xxxxxxxxxx ``` From e00c8a5240b3bec26d1b09de1b50afb98816643a Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 11 Jun 2024 08:23:11 -0700 Subject: [PATCH 21/29] Add 'TestAccAppFabricAppBundle_cmk'. --- internal/service/appfabric/app_bundle_test.go | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/internal/service/appfabric/app_bundle_test.go b/internal/service/appfabric/app_bundle_test.go index 560b4690463..1664d68b0bc 100644 --- a/internal/service/appfabric/app_bundle_test.go +++ b/internal/service/appfabric/app_bundle_test.go @@ -9,6 +9,7 @@ import ( "testing" awstypes "github.com/aws/aws-sdk-go-v2/service/appfabric/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" "github.com/hashicorp/terraform-provider-aws/internal/acctest" @@ -75,6 +76,37 @@ func TestAccAppFabricAppBundle_disappears(t *testing.T) { }) } +func TestAccAppFabricAppBundle_cmk(t *testing.T) { + ctx := acctest.Context(t) + var appbundle awstypes.AppBundle + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_appfabric_app_bundle.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, names.AppFabricEndpointID) + }, + ErrorCheck: acctest.ErrorCheck(t, names.AppFabricServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckAppBundleDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccAppBundleConfig_cmk(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAppBundleExists(ctx, resourceName, &appbundle), + resource.TestCheckResourceAttrSet(resourceName, "customer_managed_key_arn"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccAppFabricAppBundle_tags(t *testing.T) { ctx := acctest.Context(t) var appbundle awstypes.AppBundle @@ -174,6 +206,18 @@ const testAccAppBundleConfig_basic = ` resource "aws_appfabric_app_bundle" "test" {} ` +func testAccAppBundleConfig_cmk(rName string) string { + return fmt.Sprintf(` +resource "aws_kms_key" "test" { + description = %[1]q +} + +resource "aws_appfabric_app_bundle" "test" { + customer_managed_key_arn = aws_kms_key.test.arn +} +`, rName) +} + func testAccAppBundleConfig_tags1(tagKey1, tagValue1 string) string { return fmt.Sprintf(` resource "aws_appfabric_app_bundle" "test" { From 100c6e65982423f51e4dba1e001206e1f6b6ee05 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 11 Jun 2024 08:29:22 -0700 Subject: [PATCH 22/29] appfabric: Remove partition-has-service checks. --- internal/service/appfabric/app_bundle_test.go | 20 ++++--------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/internal/service/appfabric/app_bundle_test.go b/internal/service/appfabric/app_bundle_test.go index 1664d68b0bc..65e932f4be7 100644 --- a/internal/service/appfabric/app_bundle_test.go +++ b/internal/service/appfabric/app_bundle_test.go @@ -25,10 +25,7 @@ func TestAccAppFabricAppBundle_basic(t *testing.T) { resourceName := "aws_appfabric_app_bundle.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { - acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, names.AppFabricEndpointID) - }, + PreCheck: func() { acctest.PreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, names.AppFabricServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAppBundleDestroy(ctx), @@ -56,10 +53,7 @@ func TestAccAppFabricAppBundle_disappears(t *testing.T) { resourceName := "aws_appfabric_app_bundle.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { - acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, names.AppFabricEndpointID) - }, + PreCheck: func() { acctest.PreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, names.AppFabricServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAppBundleDestroy(ctx), @@ -83,10 +77,7 @@ func TestAccAppFabricAppBundle_cmk(t *testing.T) { resourceName := "aws_appfabric_app_bundle.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { - acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, names.AppFabricEndpointID) - }, + PreCheck: func() { acctest.PreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, names.AppFabricServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAppBundleDestroy(ctx), @@ -113,10 +104,7 @@ func TestAccAppFabricAppBundle_tags(t *testing.T) { resourceName := "aws_appfabric_app_bundle.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { - acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, names.AppFabricEndpointID) - }, + PreCheck: func() { acctest.PreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, names.AppFabricServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAppBundleDestroy(ctx), From 4124326d1932d85618801d12720d217c571fd92e Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 11 Jun 2024 08:32:26 -0700 Subject: [PATCH 23/29] appfabric: Correct generation. --- internal/service/appfabric/app_bundle.go | 2 +- internal/service/appfabric/generate.go | 1 - internal/service/appfabric/service_package_gen.go | 10 +++++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/internal/service/appfabric/app_bundle.go b/internal/service/appfabric/app_bundle.go index caafb806475..14649228629 100644 --- a/internal/service/appfabric/app_bundle.go +++ b/internal/service/appfabric/app_bundle.go @@ -28,7 +28,7 @@ import ( ) // @FrameworkResource(name="App Bundle") -// @Tags(identifierAttribute="arn") +// @Tags(identifierAttribute="id") func newAppBundleResource(context.Context) (resource.ResourceWithConfigure, error) { r := &appBundleResource{} diff --git a/internal/service/appfabric/generate.go b/internal/service/appfabric/generate.go index 526ccf4d4df..0973d63e475 100644 --- a/internal/service/appfabric/generate.go +++ b/internal/service/appfabric/generate.go @@ -3,7 +3,6 @@ //go:generate go run ../../generate/tags/main.go -ServiceTagsSlice -AWSSDKVersion=2 -ListTags -UpdateTags //go:generate go run ../../generate/servicepackage/main.go -//go:generate go run ../../generate/tagstests/main.go // ONLY generate directives and package declaration! Do not add anything else to this file. package appfabric diff --git a/internal/service/appfabric/service_package_gen.go b/internal/service/appfabric/service_package_gen.go index d3bb6eaf3e4..7df508456c0 100644 --- a/internal/service/appfabric/service_package_gen.go +++ b/internal/service/appfabric/service_package_gen.go @@ -20,7 +20,15 @@ func (p *servicePackage) FrameworkDataSources(ctx context.Context) []*types.Serv } func (p *servicePackage) FrameworkResources(ctx context.Context) []*types.ServicePackageFrameworkResource { - return []*types.ServicePackageFrameworkResource{} + return []*types.ServicePackageFrameworkResource{ + { + Factory: newAppBundleResource, + Name: "App Bundle", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: names.AttrID, + }, + }, + } } func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePackageSDKDataSource { From 62a7959883a0e14d6b3625ca9705b0730d11e009 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 11 Jun 2024 08:36:05 -0700 Subject: [PATCH 24/29] Use 'fwtypes.ARN' for 'customer_managed_key_arn'. --- internal/service/appfabric/app_bundle.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/appfabric/app_bundle.go b/internal/service/appfabric/app_bundle.go index 14649228629..52232eb8c15 100644 --- a/internal/service/appfabric/app_bundle.go +++ b/internal/service/appfabric/app_bundle.go @@ -181,7 +181,7 @@ func findAppBundleByID(ctx context.Context, conn *appfabric.Client, arn string) type appBundleResourceModel struct { ARN types.String `tfsdk:"arn"` - CustomerManagedKeyARN types.String `tfsdk:"customer_managed_key_arn"` + CustomerManagedKeyARN fwtypes.ARN `tfsdk:"customer_managed_key_arn"` ID types.String `tfsdk:"id"` Tags types.Map `tfsdk:"tags"` TagsAll types.Map `tfsdk:"tags_all"` From 7246d460358be836e4a2b3c9f0d6b7f8cf1de4fd Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 11 Jun 2024 08:38:45 -0700 Subject: [PATCH 25/29] appfabric: Region check for acceptance tests. --- internal/service/appfabric/app_bundle_test.go | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/internal/service/appfabric/app_bundle_test.go b/internal/service/appfabric/app_bundle_test.go index 65e932f4be7..d22167b8ddc 100644 --- a/internal/service/appfabric/app_bundle_test.go +++ b/internal/service/appfabric/app_bundle_test.go @@ -25,7 +25,10 @@ func TestAccAppFabricAppBundle_basic(t *testing.T) { resourceName := "aws_appfabric_app_bundle.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckRegion(t, names.USEast1RegionID, names.APNortheast1RegionID, names.EUWest1RegionID) + }, ErrorCheck: acctest.ErrorCheck(t, names.AppFabricServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAppBundleDestroy(ctx), @@ -53,7 +56,10 @@ func TestAccAppFabricAppBundle_disappears(t *testing.T) { resourceName := "aws_appfabric_app_bundle.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckRegion(t, names.USEast1RegionID, names.APNortheast1RegionID, names.EUWest1RegionID) + }, ErrorCheck: acctest.ErrorCheck(t, names.AppFabricServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAppBundleDestroy(ctx), @@ -77,7 +83,10 @@ func TestAccAppFabricAppBundle_cmk(t *testing.T) { resourceName := "aws_appfabric_app_bundle.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckRegion(t, names.USEast1RegionID, names.APNortheast1RegionID, names.EUWest1RegionID) + }, ErrorCheck: acctest.ErrorCheck(t, names.AppFabricServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAppBundleDestroy(ctx), @@ -104,7 +113,10 @@ func TestAccAppFabricAppBundle_tags(t *testing.T) { resourceName := "aws_appfabric_app_bundle.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckRegion(t, names.USEast1RegionID, names.APNortheast1RegionID, names.EUWest1RegionID) + }, ErrorCheck: acctest.ErrorCheck(t, names.AppFabricServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckAppBundleDestroy(ctx), From c84d24cc46a8ad3564b21e60e3c8db0e863fbf00 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 11 Jun 2024 08:43:18 -0700 Subject: [PATCH 26/29] ClientToken should be a UUID. --- internal/service/appfabric/app_bundle.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/service/appfabric/app_bundle.go b/internal/service/appfabric/app_bundle.go index 52232eb8c15..4ba1003abd6 100644 --- a/internal/service/appfabric/app_bundle.go +++ b/internal/service/appfabric/app_bundle.go @@ -10,12 +10,12 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/appfabric" awstypes "github.com/aws/aws-sdk-go-v2/service/appfabric/types" + uuid "github.com/hashicorp/go-uuid" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/types" - sdkid "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/fwdiag" @@ -73,7 +73,7 @@ func (r *appBundleResource) Create(ctx context.Context, request resource.CreateR conn := r.Meta().AppFabricClient(ctx) input := &appfabric.CreateAppBundleInput{ - ClientToken: aws.String(sdkid.UniqueId()), + ClientToken: aws.String(errs.Must(uuid.GenerateUUID())), CustomerManagedKeyIdentifier: fwflex.StringFromFramework(ctx, data.CustomerManagedKeyARN), Tags: getTagsIn(ctx), } From 3f4d3c1f5ec8710b9f266b62210150509948ca4e Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 11 Jun 2024 08:47:05 -0700 Subject: [PATCH 27/29] r/aws_appfabric_app_bundle: Add PlanModifier for 'tags_all'. --- internal/service/appfabric/app_bundle.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/service/appfabric/app_bundle.go b/internal/service/appfabric/app_bundle.go index 4ba1003abd6..98a55920b82 100644 --- a/internal/service/appfabric/app_bundle.go +++ b/internal/service/appfabric/app_bundle.go @@ -154,6 +154,10 @@ func (r *appBundleResource) Delete(ctx context.Context, request resource.DeleteR } } +func (r *appBundleResource) ModifyPlan(ctx context.Context, request resource.ModifyPlanRequest, response *resource.ModifyPlanResponse) { + r.SetTagsAll(ctx, request, response) +} + func findAppBundleByID(ctx context.Context, conn *appfabric.Client, arn string) (*awstypes.AppBundle, error) { input := &appfabric.GetAppBundleInput{ AppBundleIdentifier: aws.String(arn), From bf2bc2261934367c3e19f76f491e5f2c9902b01f Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 11 Jun 2024 08:52:05 -0700 Subject: [PATCH 28/29] appfabric: Serialize acceptance tests. --- internal/service/appfabric/app_bundle_test.go | 16 +++++----- internal/service/appfabric/appfabric_test.go | 29 +++++++++++++++++++ 2 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 internal/service/appfabric/appfabric_test.go diff --git a/internal/service/appfabric/app_bundle_test.go b/internal/service/appfabric/app_bundle_test.go index d22167b8ddc..b1791d7aa89 100644 --- a/internal/service/appfabric/app_bundle_test.go +++ b/internal/service/appfabric/app_bundle_test.go @@ -19,12 +19,12 @@ import ( "github.com/hashicorp/terraform-provider-aws/names" ) -func TestAccAppFabricAppBundle_basic(t *testing.T) { +func testAccAppBundle_basic(t *testing.T) { ctx := acctest.Context(t) var appbundle awstypes.AppBundle resourceName := "aws_appfabric_app_bundle.test" - resource.ParallelTest(t, resource.TestCase{ + resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) acctest.PreCheckRegion(t, names.USEast1RegionID, names.APNortheast1RegionID, names.EUWest1RegionID) @@ -50,12 +50,12 @@ func TestAccAppFabricAppBundle_basic(t *testing.T) { }) } -func TestAccAppFabricAppBundle_disappears(t *testing.T) { +func testAccAppBundle_disappears(t *testing.T) { ctx := acctest.Context(t) var appbundle awstypes.AppBundle resourceName := "aws_appfabric_app_bundle.test" - resource.ParallelTest(t, resource.TestCase{ + resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) acctest.PreCheckRegion(t, names.USEast1RegionID, names.APNortheast1RegionID, names.EUWest1RegionID) @@ -76,13 +76,13 @@ func TestAccAppFabricAppBundle_disappears(t *testing.T) { }) } -func TestAccAppFabricAppBundle_cmk(t *testing.T) { +func testAccAppBundle_cmk(t *testing.T) { ctx := acctest.Context(t) var appbundle awstypes.AppBundle rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_appfabric_app_bundle.test" - resource.ParallelTest(t, resource.TestCase{ + resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) acctest.PreCheckRegion(t, names.USEast1RegionID, names.APNortheast1RegionID, names.EUWest1RegionID) @@ -107,12 +107,12 @@ func TestAccAppFabricAppBundle_cmk(t *testing.T) { }) } -func TestAccAppFabricAppBundle_tags(t *testing.T) { +func testAccAppBundle_tags(t *testing.T) { ctx := acctest.Context(t) var appbundle awstypes.AppBundle resourceName := "aws_appfabric_app_bundle.test" - resource.ParallelTest(t, resource.TestCase{ + resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) acctest.PreCheckRegion(t, names.USEast1RegionID, names.APNortheast1RegionID, names.EUWest1RegionID) diff --git a/internal/service/appfabric/appfabric_test.go b/internal/service/appfabric/appfabric_test.go new file mode 100644 index 00000000000..ff1261386ee --- /dev/null +++ b/internal/service/appfabric/appfabric_test.go @@ -0,0 +1,29 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package appfabric_test + +import ( + "testing" + "time" + + "github.com/hashicorp/terraform-provider-aws/internal/acctest" +) + +const serializeDelay = 10 * time.Second + +// Serialize to limit API rate-limit exceeded errors (ServiceQuotaExceededException). +func TestAccAppFabric_serial(t *testing.T) { + t.Parallel() + + testCases := map[string]map[string]func(t *testing.T){ + "AppBundle": { + acctest.CtBasic: testAccAppBundle_basic, + acctest.CtDisappears: testAccAppBundle_disappears, + "cmk": testAccAppBundle_cmk, + "tags": testAccAppBundle_tags, + }, + } + + acctest.RunSerialTests2Levels(t, testCases, serializeDelay) +} From b5f59f5cc68a92a81e6387574f5b73c7ced950cc Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 11 Jun 2024 09:06:13 -0700 Subject: [PATCH 29/29] Run 'make gen'. --- .../appfabric/service_endpoints_gen_test.go | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/internal/service/appfabric/service_endpoints_gen_test.go b/internal/service/appfabric/service_endpoints_gen_test.go index 3d817b34b15..dd9bd9f6a23 100644 --- a/internal/service/appfabric/service_endpoints_gen_test.go +++ b/internal/service/appfabric/service_endpoints_gen_test.go @@ -26,6 +26,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/provider" + "github.com/hashicorp/terraform-provider-aws/names" ) type endpointTestCase struct { @@ -305,12 +306,12 @@ func withNoConfig(_ *caseSetup) { } func withPackageNameEndpointInConfig(setup *caseSetup) { - if _, ok := setup.config["endpoints"]; !ok { - setup.config["endpoints"] = []any{ + if _, ok := setup.config[names.AttrEndpoints]; !ok { + setup.config[names.AttrEndpoints] = []any{ map[string]any{}, } } - endpoints := setup.config["endpoints"].([]any)[0].(map[string]any) + endpoints := setup.config[names.AttrEndpoints].([]any)[0].(map[string]any) endpoints[packageName] = packageNameConfigEndpoint } @@ -398,17 +399,17 @@ func testEndpointCase(t *testing.T, region string, testcase endpointTestCase, ca } config := map[string]any{ - "access_key": servicemocks.MockStaticAccessKey, - "secret_key": servicemocks.MockStaticSecretKey, - "region": region, - "skip_credentials_validation": true, - "skip_requesting_account_id": true, + names.AttrAccessKey: servicemocks.MockStaticAccessKey, + names.AttrSecretKey: servicemocks.MockStaticSecretKey, + names.AttrRegion: region, + names.AttrSkipCredentialsValidation: true, + names.AttrSkipRequestingAccountID: true, } maps.Copy(config, setup.config) if setup.configFile.baseUrl != "" || setup.configFile.serviceUrl != "" { - config["profile"] = "default" + config[names.AttrProfile] = "default" tempDir := t.TempDir() writeSharedConfigFile(t, &config, tempDir, generateSharedConfigFile(setup.configFile)) } @@ -575,10 +576,10 @@ func writeSharedConfigFile(t *testing.T, config *map[string]any, tempDir, conten t.Fatalf(" writing shared configuration file: %s", err) } - if v, ok := (*config)["shared_config_files"]; !ok { - (*config)["shared_config_files"] = []any{file.Name()} + if v, ok := (*config)[names.AttrSharedConfigFiles]; !ok { + (*config)[names.AttrSharedConfigFiles] = []any{file.Name()} } else { - (*config)["shared_config_files"] = append(v.([]any), file.Name()) + (*config)[names.AttrSharedConfigFiles] = append(v.([]any), file.Name()) } return file.Name()