Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

add aws_appfabric_app_bundle resource #37542

Merged
merged 31 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
8eee0d4
adding all files from gitlab
kaitheal May 14, 2024
1097acf
AppBundle Tests Pass
walkoaw May 15, 2024
a44bd4c
Final
walkoaw May 15, 2024
233815f
All comments removed
walkoaw May 15, 2024
d9c19d0
added framework resource and no op
kaitheal May 29, 2024
7ffcb49
added framework resource commented out
kaitheal May 29, 2024
c4a4f55
adding endpointID
kaitheal May 29, 2024
cdd2ebf
added precheck to other functions
kaitheal May 29, 2024
05ed84d
delete basic
kaitheal May 29, 2024
f89fe1f
delete precheck function
kaitheal May 29, 2024
7dc7a30
added full test
kaitheal May 29, 2024
9ab3ede
adding changelog
kaitheal May 29, 2024
9ac84ee
Update Tests, Added Documentation
walkoaw May 29, 2024
43d8992
Merge branch 'main' of https://github.com/kaitheal/terraform-provider…
walkoaw May 29, 2024
804a8a2
All comments addressed
walkoaw May 29, 2024
7197927
Added 3 tests: 1 for customer_managed_key and 2 for tags
walkoaw May 31, 2024
33e8c56
Merge branch 'main' into HEAD
ewbankkit Jun 10, 2024
dbf75db
r/aws_appfabric_app_bundle: Tidy up.
ewbankkit Jun 11, 2024
7d46e8f
r/aws_appfabric_app_bundle: Additional acceptance tests.
ewbankkit Jun 11, 2024
720565e
Fix markdown-lint 'MD022/blanks-around-headings/blanks-around-headers…
ewbankkit Jun 11, 2024
8e1a95a
Fix markdown-lint 'MD047/single-trailing-newline Files should end wit…
ewbankkit Jun 11, 2024
9cc2cd5
Fix documentation terrafmt errors.
ewbankkit Jun 11, 2024
e00c8a5
Add 'TestAccAppFabricAppBundle_cmk'.
ewbankkit Jun 11, 2024
100c6e6
appfabric: Remove partition-has-service checks.
ewbankkit Jun 11, 2024
4124326
appfabric: Correct generation.
ewbankkit Jun 11, 2024
62a7959
Use 'fwtypes.ARN' for 'customer_managed_key_arn'.
ewbankkit Jun 11, 2024
7246d46
appfabric: Region check for acceptance tests.
ewbankkit Jun 11, 2024
c84d24c
ClientToken should be a UUID.
ewbankkit Jun 11, 2024
3f4d3c1
r/aws_appfabric_app_bundle: Add PlanModifier for 'tags_all'.
ewbankkit Jun 11, 2024
bf2bc22
appfabric: Serialize acceptance tests.
ewbankkit Jun 11, 2024
b5f59f5
Run 'make gen'.
ewbankkit Jun 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/37542.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
aws_appfabric_app_bundle
```
202 changes: 202 additions & 0 deletions internal/service/appfabric/app_bundle.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package appfabric

import (
"context"
"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"
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"
"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"
"github.com/hashicorp/terraform-provider-aws/internal/framework"
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")
// @Tags(identifierAttribute="id")
func newAppBundleResource(context.Context) (resource.ResourceWithConfigure, error) {
r := &appBundleResource{}

return r, nil
}

type appBundleResource struct {
framework.ResourceWithConfigure
framework.WithNoOpUpdate[appBundleResourceModel]
framework.WithImportByID
}

func (*appBundleResource) Metadata(_ context.Context, request resource.MetadataRequest, response *resource.MetadataResponse) {
response.TypeName = "aws_appfabric_app_bundle"
}

func (r *appBundleResource) Schema(ctx context.Context, request resource.SchemaRequest, response *resource.SchemaResponse) {
response.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
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(),
names.AttrTagsAll: tftags.TagsAttributeComputedOnly(),
},
}
}

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
}

conn := r.Meta().AppFabricClient(ctx)

input := &appfabric.CreateAppBundleInput{
ClientToken: aws.String(errs.Must(uuid.GenerateUUID())),
CustomerManagedKeyIdentifier: fwflex.StringFromFramework(ctx, data.CustomerManagedKeyARN),
Tags: getTagsIn(ctx),
}

output, err := conn.CreateAppBundle(ctx, input)

if err != nil {
response.Diagnostics.AddError("creating AppFabric App Bundle", err.Error())

return
}

// Set values for unknowns.
data.ARN = fwflex.StringToFramework(ctx, output.AppBundle.Arn)
data.setID()

response.Diagnostics.Append(response.State.Set(ctx, data)...)
}

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())

return
}

conn := r.Meta().AppFabricClient(ctx)

appBundle, err := findAppBundleByID(ctx, conn, data.ID.ValueString())

if tfresource.NotFound(err) {
response.Diagnostics.Append(fwdiag.NewResourceNotFoundWarningDiagnostic(err))
response.State.RemoveResource(ctx)
return
}

if err != nil {
response.Diagnostics.AddError(fmt.Sprintf("reading AppFabric App Bundle (%s)", data.ID.ValueString()), err.Error())

return
}

// Set attributes for import.
response.Diagnostics.Append(fwflex.Flatten(ctx, appBundle, &data)...)
if response.Diagnostics.HasError() {
return
}

response.Diagnostics.Append(response.State.Set(ctx, &data)...)
}

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)

_, err := conn.DeleteAppBundle(ctx, &appfabric.DeleteAppBundleInput{
AppBundleIdentifier: aws.String(data.ID.ValueString()),
})

if errs.IsA[*awstypes.ResourceNotFoundException](err) {
return
}

if err != nil {
response.Diagnostics.AddError(fmt.Sprintf("deleting AppFabric App Bundle (%s)", data.ID.ValueString()), err.Error())

return
}
}

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),
}

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 output == nil || output.AppBundle == nil {
return nil, tfresource.NewEmptyResultError(input)
}

return output.AppBundle, nil
}

type appBundleResourceModel struct {
ARN types.String `tfsdk:"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"`
}

func (data *appBundleResourceModel) InitFromID() error {
data.ARN = data.ID

return nil
}

func (data *appBundleResourceModel) setID() {
data.ID = data.ARN
}
Loading
Loading