Skip to content

Commit

Permalink
Merge pull request #41192 from acwwat/f-aws_rekognition_project-add_t…
Browse files Browse the repository at this point in the history
…agging_support

feat: Add tagging support for aws_rekognition_project
  • Loading branch information
ewbankkit authored Feb 3, 2025
2 parents 2a3e17f + db30ba0 commit 0a61fa0
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .changelog/41192.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_rekognition_project: Add `tags` argument and `tags_all` attribute
```
14 changes: 13 additions & 1 deletion internal/service/rekognition/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ import (
"github.com/hashicorp/terraform-provider-aws/internal/framework"
"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("aws_rekognition_project", name="Project")
// @Tags(identifierAttribute="arn")
func newResourceProject(_ context.Context) (resource.ResourceWithConfigure, error) {
r := &resourceProject{}

Expand Down Expand Up @@ -78,6 +80,8 @@ func (r *resourceProject) Schema(ctx context.Context, req resource.SchemaRequest
stringplanmodifier.RequiresReplace(),
},
},
names.AttrTags: tftags.TagsAttribute(),
names.AttrTagsAll: tftags.TagsAttributeComputedOnly(),
},
Blocks: map[string]schema.Block{
names.AttrTimeouts: timeouts.Block(ctx, timeouts.Opts{
Expand All @@ -97,7 +101,9 @@ func (r *resourceProject) Create(ctx context.Context, req resource.CreateRequest
return
}

in := rekognition.CreateProjectInput{}
in := rekognition.CreateProjectInput{
Tags: getTagsIn(ctx),
}

resp.Diagnostics.Append(flex.Expand(ctx, plan, &in)...)
if resp.Diagnostics.HasError() {
Expand Down Expand Up @@ -247,6 +253,10 @@ func (r *resourceProject) Delete(ctx context.Context, req resource.DeleteRequest
}
}

func (r *resourceProject) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) {
r.SetTagsAll(ctx, req, resp)
}

func waitProjectCreated(ctx context.Context, conn *rekognition.Client, name string, feature awstypes.CustomizationFeature, timeout time.Duration) (*awstypes.ProjectDescription, error) {
stateConf := &retry.StateChangeConf{
Pending: enum.Slice(awstypes.ProjectStatusCreating),
Expand Down Expand Up @@ -340,5 +350,7 @@ type resourceProjectData struct {
Feature fwtypes.StringEnum[awstypes.CustomizationFeature] `tfsdk:"feature"`
ID types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
Tags tftags.Map `tfsdk:"tags"`
TagsAll tftags.Map `tfsdk:"tags_all"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
}
76 changes: 76 additions & 0 deletions internal/service/rekognition/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ func TestAccRekognitionProject_basic(t *testing.T) {
resource.TestCheckResourceAttrSet(resourceName, names.AttrARN),
resource.TestCheckResourceAttr(resourceName, "auto_update", autoUpdate),
resource.TestCheckResourceAttr(resourceName, "feature", feature),
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "0"),
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsAllPercent, "0"),
),
},
{
Expand Down Expand Up @@ -168,6 +170,69 @@ func TestAccRekognitionProject_disappears(t *testing.T) {
})
}

func TestAccRekognitionProject_tags(t *testing.T) {
ctx := acctest.Context(t)

rProjectId := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_rekognition_project.test"
feature := "CUSTOM_LABELS"

tags1 := `
tags = {
key1 = "value1"
}
`
tags2 := `
tags = {
key1 = "value1"
key2 = "value2"
}
`
tags3 := `
tags = {
key2 = "value2"
}
`

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.RekognitionEndpointID)
testAccProjectPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.RekognitionServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckProjectDestroy(ctx, feature, rProjectId),
Steps: []resource.TestStep{
{
Config: testAccProjectConfig_tags(rProjectId, tags1),
Check: resource.ComposeTestCheckFunc(
testAccCheckProjectExists(ctx, resourceName),
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "1"),
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey1, acctest.CtValue1),
),
},
{
Config: testAccProjectConfig_tags(rProjectId, tags2),
Check: resource.ComposeTestCheckFunc(
testAccCheckProjectExists(ctx, resourceName),
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "2"),
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey1, acctest.CtValue1),
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey2, acctest.CtValue2),
),
},
{
Config: testAccProjectConfig_tags(rProjectId, tags3),
Check: resource.ComposeTestCheckFunc(
testAccCheckProjectExists(ctx, resourceName),
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "1"),
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey2, acctest.CtValue2),
),
},
},
})
}

func testAccCheckProjectExists(ctx context.Context, name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[name]
Expand Down Expand Up @@ -248,3 +313,14 @@ resource "aws_rekognition_project" "test" {
}
`, rProjectId)
}

func testAccProjectConfig_tags(rName, tags string) string {
return fmt.Sprintf(`
resource "aws_rekognition_project" "test" {
name = %[1]q
feature = "CUSTOM_LABELS"
%[2]s
}
`, rName, tags)
}
3 changes: 3 additions & 0 deletions internal/service/rekognition/service_package_gen.go

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

8 changes: 5 additions & 3 deletions website/docs/r/rekognition_project.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,20 @@ resource "aws_rekognition_project" "example" {

The following arguments are required:

* `name` - (Required) Desired name of the project
* `name` - (Required) Desired name of the project.

The following arguments are optional:

* `auto_update` - (Optional) Specify if automatic retraining should occur. Valid values are `ENABLED` or `DISABLED`. Defaults to `DISABLED`
* `feature` - (Optional) Specify the feature being customized. Valid values are `CONTENT_MODERATION` or `CUSTOM_LABELS`. Defaults to `CUSTOM_LABELS`
* `auto_update` - (Optional) Specify if automatic retraining should occur. Valid values are `ENABLED` or `DISABLED`. Defaults to `DISABLED`.
* `feature` - (Optional) Specify the feature being customized. Valid values are `CONTENT_MODERATION` or `CUSTOM_LABELS`. Defaults to `CUSTOM_LABELS`.
* `tags` - (Optional) Map of tags assigned to the resource. If configured with a provider [`default_tags` configuration block](/docs/providers/aws/index.html#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 Project.
* `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).

## Timeouts

Expand Down

0 comments on commit 0a61fa0

Please sign in to comment.