Skip to content

Commit

Permalink
Merge pull request #38243 from drewtul/f-sc-appregistry-application-u…
Browse files Browse the repository at this point in the history
…pdates

Add tags to application resource and datasource
  • Loading branch information
ewbankkit authored Dec 6, 2024
2 parents 622c1b5 + 5e14f8b commit e7b7dd0
Show file tree
Hide file tree
Showing 19 changed files with 2,745 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .changelog/38243.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/aws_servicecatalogappregistry_application: Add `tags` argument and `tags_all` attribute
```

```release-note:enhancement
data-source/aws_servicecatalogappregistry_application: Add `tags` attribute
```
17 changes: 16 additions & 1 deletion internal/service/servicecatalogappregistry/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"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/mapplanmodifier"
"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"
Expand All @@ -21,12 +22,13 @@ import (
"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"
)

// @FrameworkResource("aws_servicecatalogappregistry_application", name="Application")
// @Testing(tagsTest=false)
// @Tags(identifierAttribute="arn")
func newResourceApplication(_ context.Context) (resource.ResourceWithConfigure, error) {
return &resourceApplication{}, nil
}
Expand Down Expand Up @@ -63,7 +65,12 @@ func (r *resourceApplication) Schema(ctx context.Context, req resource.SchemaReq
"application_tag": schema.MapAttribute{
ElementType: types.StringType,
Computed: true,
PlanModifiers: []planmodifier.Map{
mapplanmodifier.UseStateForUnknown(),
},
},
names.AttrTags: tftags.TagsAttribute(),
names.AttrTagsAll: tftags.TagsAttributeComputedOnly(),
},
}
}
Expand All @@ -83,6 +90,8 @@ func (r *resourceApplication) Create(ctx context.Context, req resource.CreateReq
return
}

in.Tags = getTagsIn(ctx)

out, err := conn.CreateApplication(ctx, in)
if err != nil {
resp.Diagnostics.AddError(
Expand Down Expand Up @@ -199,6 +208,10 @@ func (r *resourceApplication) ImportState(ctx context.Context, req resource.Impo
resource.ImportStatePassthroughID(ctx, path.Root(names.AttrID), req, resp)
}

func (r *resourceApplication) ModifyPlan(ctx context.Context, request resource.ModifyPlanRequest, response *resource.ModifyPlanResponse) {
r.SetTagsAll(ctx, request, response)
}

func findApplicationByID(ctx context.Context, conn *servicecatalogappregistry.Client, id string) (*servicecatalogappregistry.GetApplicationOutput, error) {
in := &servicecatalogappregistry.GetApplicationInput{
Application: aws.String(id),
Expand Down Expand Up @@ -229,4 +242,6 @@ type resourceApplicationData struct {
ID types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
ApplicationTag types.Map `tfsdk:"application_tag"`
Tags tftags.Map `tfsdk:"tags"`
TagsAll tftags.Map `tfsdk:"tags_all"`
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import (
"github.com/hashicorp/terraform-provider-aws/internal/create"
"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/names"
)

// @FrameworkDataSource("aws_servicecatalogappregistry_application", name="Application")
// @Testing(tagsTest=false)
// @Tags(identifierAttribute="arn")
func newDataSourceApplication(context.Context) (datasource.DataSourceWithConfigure, error) {
return &dataSourceApplication{}, nil
}
Expand Down Expand Up @@ -50,11 +51,13 @@ func (d *dataSourceApplication) Schema(ctx context.Context, req datasource.Schem
ElementType: types.StringType,
Computed: true,
},
names.AttrTags: tftags.TagsAttributeComputedOnly(),
},
}
}
func (d *dataSourceApplication) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
conn := d.Meta().ServiceCatalogAppRegistryClient(ctx)
ignoreTagsConfig := d.Meta().IgnoreTagsConfig(ctx)

var data dataSourceApplicationData
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
Expand All @@ -72,6 +75,10 @@ func (d *dataSourceApplication) Read(ctx context.Context, req datasource.ReadReq
}

resp.Diagnostics.Append(flex.Flatten(ctx, out, &data)...)

// Transparent tagging doesn't work for DataSource yet
data.Tags = tftags.NewMapFromMapValue(flex.FlattenFrameworkStringValueMapLegacy(ctx, KeyValueTags(ctx, out.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()))

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

Expand All @@ -81,4 +88,5 @@ type dataSourceApplicationData struct {
ID types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
ApplicationTag types.Map `tfsdk:"application_tag"`
Tags tftags.Map `tfsdk:"tags"`
}

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

Loading

0 comments on commit e7b7dd0

Please sign in to comment.