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

feat: Add tags support to aws_cur_report_definition resource and data source #38483

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changelog/38483.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/aws_cur_report_definition: Add `tags` argument and `tags_all` attribute
```

```release-note:enhancement
data-source/aws_cur_report_definition: Add `tags` attribute
```
1 change: 1 addition & 0 deletions internal/service/cur/cur_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func TestAccCUR_serial(t *testing.T) {
testCases := map[string]map[string]func(t *testing.T){
"ReportDefinition": {
acctest.CtBasic: testAccReportDefinition_basic,
"tags": testAccReportDefinition_tags,
acctest.CtDisappears: testAccReportDefinition_disappears,
"textOrCsv": testAccReportDefinition_textOrCSV,
"parquet": testAccReportDefinition_parquet,
Expand Down
1 change: 1 addition & 0 deletions internal/service/cur/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: MPL-2.0

//go:generate go run ../../generate/servicepackage/main.go
//go:generate go run ../../generate/tags/main.go -AWSSDKVersion=2 -ServiceTagsSlice -ListTags -ListTagsInIDElem=ReportName -UpdateTags -TagInIDElem=ReportName -KVTValues
// ONLY generate directives and package declaration! Do not add anything else to this file.

package cur
78 changes: 44 additions & 34 deletions internal/service/cur/report_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ import (
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
"github.com/hashicorp/terraform-provider-aws/internal/flex"
tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
"github.com/hashicorp/terraform-provider-aws/names"
)

// @SDKResource("aws_cur_report_definition", name="Report Definition")
// @Tags(identifierAttribute="report_name")
func resourceReportDefinition() *schema.Resource {
return &schema.Resource{
CreateWithoutTimeout: resourceReportDefinitionCreate,
Expand Down Expand Up @@ -111,7 +114,11 @@ func resourceReportDefinition() *schema.Resource {
ForceNew: true,
ValidateDiagFunc: enum.Validate[types.TimeUnit](),
},
names.AttrTags: tftags.TagsSchema(),
names.AttrTagsAll: tftags.TagsSchemaComputed(),
},

CustomizeDiff: verify.SetTagsDiff,
}
}

Expand Down Expand Up @@ -150,6 +157,7 @@ func resourceReportDefinitionCreate(ctx context.Context, d *schema.ResourceData,
S3Region: types.AWSRegion(d.Get("s3_region").(string)),
TimeUnit: types.TimeUnit(d.Get("time_unit").(string)),
},
Tags: getTagsIn(ctx),
}

_, err := conn.PutReportDefinition(ctx, input)
Expand Down Expand Up @@ -208,43 +216,45 @@ func resourceReportDefinitionUpdate(ctx context.Context, d *schema.ResourceData,
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).CURClient(ctx)

additionalArtifacts := flex.ExpandStringyValueSet[types.AdditionalArtifact](d.Get("additional_artifacts").(*schema.Set))
compression := types.CompressionFormat(d.Get("compression").(string))
format := types.ReportFormat(d.Get(names.AttrFormat).(string))
prefix := d.Get("s3_prefix").(string)
reportVersioning := types.ReportVersioning(d.Get("report_versioning").(string))

if err := checkReportDefinitionPropertyCombination(
additionalArtifacts,
compression,
format,
prefix,
reportVersioning,
); err != nil {
return sdkdiag.AppendFromErr(diags, err)
}
if d.HasChangesExcept(names.AttrTags, names.AttrTagsAll) {
additionalArtifacts := flex.ExpandStringyValueSet[types.AdditionalArtifact](d.Get("additional_artifacts").(*schema.Set))
compression := types.CompressionFormat(d.Get("compression").(string))
format := types.ReportFormat(d.Get(names.AttrFormat).(string))
prefix := d.Get("s3_prefix").(string)
reportVersioning := types.ReportVersioning(d.Get("report_versioning").(string))

if err := checkReportDefinitionPropertyCombination(
additionalArtifacts,
compression,
format,
prefix,
reportVersioning,
); err != nil {
return sdkdiag.AppendFromErr(diags, err)
}

input := &cur.ModifyReportDefinitionInput{
ReportDefinition: &types.ReportDefinition{
AdditionalArtifacts: additionalArtifacts,
AdditionalSchemaElements: flex.ExpandStringyValueSet[types.SchemaElement](d.Get("additional_schema_elements").(*schema.Set)),
Compression: compression,
Format: format,
RefreshClosedReports: aws.Bool(d.Get("refresh_closed_reports").(bool)),
ReportName: aws.String(d.Id()),
ReportVersioning: reportVersioning,
S3Bucket: aws.String(d.Get(names.AttrS3Bucket).(string)),
S3Prefix: aws.String(prefix),
S3Region: types.AWSRegion(d.Get("s3_region").(string)),
TimeUnit: types.TimeUnit(d.Get("time_unit").(string)),
},
ReportName: aws.String(d.Id()),
}
input := &cur.ModifyReportDefinitionInput{
ReportDefinition: &types.ReportDefinition{
AdditionalArtifacts: additionalArtifacts,
AdditionalSchemaElements: flex.ExpandStringyValueSet[types.SchemaElement](d.Get("additional_schema_elements").(*schema.Set)),
Compression: compression,
Format: format,
RefreshClosedReports: aws.Bool(d.Get("refresh_closed_reports").(bool)),
ReportName: aws.String(d.Id()),
ReportVersioning: reportVersioning,
S3Bucket: aws.String(d.Get(names.AttrS3Bucket).(string)),
S3Prefix: aws.String(prefix),
S3Region: types.AWSRegion(d.Get("s3_region").(string)),
TimeUnit: types.TimeUnit(d.Get("time_unit").(string)),
},
ReportName: aws.String(d.Id()),
}

_, err := conn.ModifyReportDefinition(ctx, input)
_, err := conn.ModifyReportDefinition(ctx, input)

if err != nil {
return sdkdiag.AppendErrorf(diags, "updating Cost And Usage Report Definition (%s): %s", d.Id(), err)
if err != nil {
return sdkdiag.AppendErrorf(diags, "updating Cost And Usage Report Definition (%s): %s", d.Id(), err)
}
}

return append(diags, resourceReportDefinitionRead(ctx, d, meta)...)
Expand Down
3 changes: 3 additions & 0 deletions internal/service/cur/report_definition_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/names"
)

// @SDKDataSource("aws_cur_report_definition", name="Report Definition")
// @Tags(identifierAttribute="report_name")
func dataSourceReportDefinition() *schema.Resource {
return &schema.Resource{
ReadWithoutTimeout: dataSourceReportDefinitionRead,
Expand Down Expand Up @@ -62,6 +64,7 @@ func dataSourceReportDefinition() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
names.AttrTags: tftags.TagsSchemaComputed(),
"time_unit": {
Type: schema.TypeString,
Computed: true,
Expand Down
52 changes: 32 additions & 20 deletions internal/service/cur/report_definition_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
func testAccReportDefinitionDataSource_basic(t *testing.T) {
ctx := acctest.Context(t)
resourceName := "aws_cur_report_definition.test"
datasourceName := "data.aws_cur_report_definition.test"
dataSourceName := "data.aws_cur_report_definition.test"
reportName := sdkacctest.RandomWithPrefix("tf_acc_test")
bucketName := fmt.Sprintf("tf-test-bucket-%d", sdkacctest.RandInt())

Expand All @@ -29,14 +29,16 @@ func testAccReportDefinitionDataSource_basic(t *testing.T) {
{
Config: testAccReportDefinitionDataSourceConfig_basic(reportName, bucketName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(datasourceName, "report_name", resourceName, "report_name"),
resource.TestCheckResourceAttrPair(datasourceName, "time_unit", resourceName, "time_unit"),
resource.TestCheckResourceAttrPair(datasourceName, "compression", resourceName, "compression"),
resource.TestCheckResourceAttrPair(datasourceName, "additional_schema_elements.#", resourceName, "additional_schema_elements.#"),
resource.TestCheckResourceAttrPair(datasourceName, names.AttrS3Bucket, resourceName, names.AttrS3Bucket),
resource.TestCheckResourceAttrPair(datasourceName, "s3_prefix", resourceName, "s3_prefix"),
resource.TestCheckResourceAttrPair(datasourceName, "s3_region", resourceName, "s3_region"),
resource.TestCheckResourceAttrPair(datasourceName, "additional_artifacts.#", resourceName, "additional_artifacts.#"),
resource.TestCheckResourceAttrPair(dataSourceName, "report_name", resourceName, "report_name"),
resource.TestCheckResourceAttrPair(dataSourceName, "time_unit", resourceName, "time_unit"),
resource.TestCheckResourceAttrPair(dataSourceName, "compression", resourceName, "compression"),
resource.TestCheckResourceAttrPair(dataSourceName, "additional_schema_elements.#", resourceName, "additional_schema_elements.#"),
resource.TestCheckResourceAttrPair(dataSourceName, names.AttrS3Bucket, resourceName, names.AttrS3Bucket),
resource.TestCheckResourceAttrPair(dataSourceName, "s3_prefix", resourceName, "s3_prefix"),
resource.TestCheckResourceAttrPair(dataSourceName, "s3_region", resourceName, "s3_region"),
resource.TestCheckResourceAttrPair(dataSourceName, "additional_artifacts.#", resourceName, "additional_artifacts.#"),
resource.TestCheckResourceAttrPair(dataSourceName, acctest.CtTagsPercent, resourceName, acctest.CtTagsPercent),
resource.TestCheckResourceAttrPair(dataSourceName, acctest.CtTagsKey1, resourceName, acctest.CtTagsKey1),
),
},
},
Expand All @@ -46,7 +48,7 @@ func testAccReportDefinitionDataSource_basic(t *testing.T) {
func testAccReportDefinitionDataSource_additional(t *testing.T) {
ctx := acctest.Context(t)
resourceName := "aws_cur_report_definition.test"
datasourceName := "data.aws_cur_report_definition.test"
dataSourceName := "data.aws_cur_report_definition.test"
reportName := sdkacctest.RandomWithPrefix("tf_acc_test")
bucketName := fmt.Sprintf("tf-test-bucket-%d", sdkacctest.RandInt())

Expand All @@ -59,16 +61,19 @@ func testAccReportDefinitionDataSource_additional(t *testing.T) {
{
Config: testAccReportDefinitionDataSourceConfig_additional(reportName, bucketName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(datasourceName, "report_name", resourceName, "report_name"),
resource.TestCheckResourceAttrPair(datasourceName, "time_unit", resourceName, "time_unit"),
resource.TestCheckResourceAttrPair(datasourceName, "compression", resourceName, "compression"),
resource.TestCheckResourceAttrPair(datasourceName, "additional_schema_elements.#", resourceName, "additional_schema_elements.#"),
resource.TestCheckResourceAttrPair(datasourceName, names.AttrS3Bucket, resourceName, names.AttrS3Bucket),
resource.TestCheckResourceAttrPair(datasourceName, "s3_prefix", resourceName, "s3_prefix"),
resource.TestCheckResourceAttrPair(datasourceName, "s3_region", resourceName, "s3_region"),
resource.TestCheckResourceAttrPair(datasourceName, "additional_artifacts.#", resourceName, "additional_artifacts.#"),
resource.TestCheckResourceAttrPair(datasourceName, "refresh_closed_reports", resourceName, "refresh_closed_reports"),
resource.TestCheckResourceAttrPair(datasourceName, "report_versioning", resourceName, "report_versioning"),
resource.TestCheckResourceAttrPair(dataSourceName, "report_name", resourceName, "report_name"),
resource.TestCheckResourceAttrPair(dataSourceName, "time_unit", resourceName, "time_unit"),
resource.TestCheckResourceAttrPair(dataSourceName, "compression", resourceName, "compression"),
resource.TestCheckResourceAttrPair(dataSourceName, "additional_schema_elements.#", resourceName, "additional_schema_elements.#"),
resource.TestCheckResourceAttrPair(dataSourceName, names.AttrS3Bucket, resourceName, names.AttrS3Bucket),
resource.TestCheckResourceAttrPair(dataSourceName, "s3_prefix", resourceName, "s3_prefix"),
resource.TestCheckResourceAttrPair(dataSourceName, "s3_region", resourceName, "s3_region"),
resource.TestCheckResourceAttrPair(dataSourceName, "additional_artifacts.#", resourceName, "additional_artifacts.#"),
resource.TestCheckResourceAttrPair(dataSourceName, "refresh_closed_reports", resourceName, "refresh_closed_reports"),
resource.TestCheckResourceAttrPair(dataSourceName, "report_versioning", resourceName, "report_versioning"),
resource.TestCheckResourceAttrPair(dataSourceName, acctest.CtTagsPercent, resourceName, acctest.CtTagsPercent),
resource.TestCheckResourceAttrPair(dataSourceName, acctest.CtTagsKey1, resourceName, acctest.CtTagsKey1),
resource.TestCheckResourceAttrPair(dataSourceName, acctest.CtTagsKey2, resourceName, acctest.CtTagsKey2),
),
},
},
Expand Down Expand Up @@ -132,6 +137,9 @@ resource "aws_cur_report_definition" "test" {
s3_prefix = ""
s3_region = aws_s3_bucket.test.region
additional_artifacts = ["REDSHIFT", "QUICKSIGHT"]
tags = {
key1 = "value1"
}
}

data "aws_cur_report_definition" "test" {
Expand Down Expand Up @@ -199,6 +207,10 @@ resource "aws_cur_report_definition" "test" {
additional_artifacts = ["REDSHIFT", "QUICKSIGHT"]
refresh_closed_reports = true
report_versioning = "CREATE_NEW_REPORT"
tags = {
key1 = "value1"
key2 = "value2"
}
}

data "aws_cur_report_definition" "test" {
Expand Down
Loading
Loading