From 24ca784d550561b573f0f62286a569b2e2d86e92 Mon Sep 17 00:00:00 2001 From: Sasi Date: Mon, 20 Oct 2025 23:18:25 -0400 Subject: [PATCH 01/21] feat: added monitor and scope resources for networkflowmonitor service --- .../networkflowmonitor/exports_test.go | 13 + .../service/networkflowmonitor/monitor.go | 338 +++++++++++++++ .../networkflowmonitor/monitor_test.go | 282 ++++++++++++ internal/service/networkflowmonitor/scope.go | 402 ++++++++++++++++++ .../service/networkflowmonitor/scope_test.go | 230 ++++++++++ .../networkflowmonitor/service_package_gen.go | 13 +- internal/service/networkflowmonitor/sweep.go | 113 +++++ internal/sweep/register_gen_test.go | 2 + .../networkflowmonitor_monitor.html.markdown | 95 +++++ .../r/networkflowmonitor_scope.html.markdown | 117 +++++ 10 files changed, 1604 insertions(+), 1 deletion(-) create mode 100644 internal/service/networkflowmonitor/exports_test.go create mode 100644 internal/service/networkflowmonitor/monitor.go create mode 100644 internal/service/networkflowmonitor/monitor_test.go create mode 100644 internal/service/networkflowmonitor/scope.go create mode 100644 internal/service/networkflowmonitor/scope_test.go create mode 100644 internal/service/networkflowmonitor/sweep.go create mode 100644 website/docs/r/networkflowmonitor_monitor.html.markdown create mode 100644 website/docs/r/networkflowmonitor_scope.html.markdown diff --git a/internal/service/networkflowmonitor/exports_test.go b/internal/service/networkflowmonitor/exports_test.go new file mode 100644 index 000000000000..458b6ede9dfa --- /dev/null +++ b/internal/service/networkflowmonitor/exports_test.go @@ -0,0 +1,13 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package networkflowmonitor + +// Exports for use in tests only. +var ( + ResourceMonitor = newMonitorResource + ResourceScope = newScopeResource + + FindMonitorByName = findMonitorByName + FindScopeByID = findScopeByID +) diff --git a/internal/service/networkflowmonitor/monitor.go b/internal/service/networkflowmonitor/monitor.go new file mode 100644 index 000000000000..86ba75456a2b --- /dev/null +++ b/internal/service/networkflowmonitor/monitor.go @@ -0,0 +1,338 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package networkflowmonitor + +import ( + "context" + "fmt" + "time" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/networkflowmonitor" + awstypes "github.com/aws/aws-sdk-go-v2/service/networkflowmonitor/types" + "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" + "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" + "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/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-provider-aws/internal/enum" + "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("aws_networkflowmonitor_monitor", name="Monitor") +// @Tags(identifierAttribute="arn") +func newMonitorResource(_ context.Context) (resource.ResourceWithConfigure, error) { + r := &monitorResource{} + + r.SetDefaultCreateTimeout(30 * time.Minute) + r.SetDefaultUpdateTimeout(30 * time.Minute) + r.SetDefaultDeleteTimeout(30 * time.Minute) + + return r, nil +} + +type monitorResource struct { + framework.ResourceWithConfigure + framework.ResourceWithModel[monitorResourceModel] + framework.WithImportByID + framework.WithTimeouts +} + +func (r *monitorResource) Metadata(_ context.Context, request resource.MetadataRequest, response *resource.MetadataResponse) { + response.TypeName = request.ProviderTypeName + "_networkflowmonitor_monitor" +} + +func (r *monitorResource) Schema(ctx context.Context, request resource.SchemaRequest, response *resource.SchemaResponse) { + response.Schema = schema.Schema{ + Attributes: map[string]schema.Attribute{ + names.AttrARN: framework.ARNAttributeComputedOnly(), + names.AttrID: framework.IDAttribute(), + "monitor_name": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + }, + "scope_arn": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + }, + "monitor_status": schema.StringAttribute{ + Computed: true, + }, + names.AttrTags: tftags.TagsAttribute(), + names.AttrTagsAll: tftags.TagsAttributeComputedOnly(), + }, + Blocks: map[string]schema.Block{ + "local_resources": schema.ListNestedBlock{ + CustomType: fwtypes.NewListNestedObjectTypeOf[monitorResourceConfigModel](ctx), + Validators: []validator.List{ + listvalidator.SizeAtMost(1), + }, + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "type": schema.StringAttribute{ + Required: true, + }, + "identifier": schema.StringAttribute{ + Required: true, + }, + }, + }, + }, + "remote_resources": schema.ListNestedBlock{ + CustomType: fwtypes.NewListNestedObjectTypeOf[monitorResourceConfigModel](ctx), + Validators: []validator.List{ + listvalidator.SizeAtMost(1), + }, + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "type": schema.StringAttribute{ + Required: true, + }, + "identifier": schema.StringAttribute{ + Required: true, + }, + }, + }, + }, + names.AttrTimeouts: timeouts.Block(ctx, timeouts.Opts{ + Create: true, + Update: true, + Delete: true, + }), + }, + } +} + +type monitorResourceModel struct { + ARN types.String `tfsdk:"arn"` + ID types.String `tfsdk:"id"` + MonitorName types.String `tfsdk:"monitor_name"` + ScopeArn types.String `tfsdk:"scope_arn"` + MonitorStatus types.String `tfsdk:"monitor_status"` + LocalResources fwtypes.ListNestedObjectValueOf[monitorResourceConfigModel] `tfsdk:"local_resources"` + RemoteResources fwtypes.ListNestedObjectValueOf[monitorResourceConfigModel] `tfsdk:"remote_resources"` + Tags tftags.Map `tfsdk:"tags"` + TagsAll tftags.Map `tfsdk:"tags_all"` + Timeouts timeouts.Value `tfsdk:"timeouts"` +} + +type monitorResourceConfigModel struct { + Type types.String `tfsdk:"type"` + Identifier types.String `tfsdk:"identifier"` +} + +func (r *monitorResource) Create(ctx context.Context, request resource.CreateRequest, response *resource.CreateResponse) { + var data monitorResourceModel + response.Diagnostics.Append(request.Plan.Get(ctx, &data)...) + if response.Diagnostics.HasError() { + return + } + + conn := r.Meta().NetworkFlowMonitorClient(ctx) + + input := &networkflowmonitor.CreateMonitorInput{} + response.Diagnostics.Append(fwflex.Expand(ctx, data, input)...) + if response.Diagnostics.HasError() { + return + } + + // Set additional fields that need special handling + input.Tags = getTagsIn(ctx) + + output, err := conn.CreateMonitor(ctx, input) + + if err != nil { + response.Diagnostics.AddError("creating Network Flow Monitor Monitor", err.Error()) + return + } + + data.ID = types.StringValue(aws.ToString(output.MonitorArn)) + data.ARN = types.StringValue(aws.ToString(output.MonitorArn)) + + monitor, err := waitMonitorCreated(ctx, conn, data.MonitorName.ValueString(), r.CreateTimeout(ctx, data.Timeouts)) + if err != nil { + response.Diagnostics.AddError(fmt.Sprintf("waiting for Network Flow Monitor Monitor (%s) create", data.ID.ValueString()), err.Error()) + return + } + + // Set computed attributes + data.MonitorStatus = types.StringValue(string(monitor.MonitorStatus)) + + response.Diagnostics.Append(response.State.Set(ctx, data)...) +} + +func (r *monitorResource) Read(ctx context.Context, request resource.ReadRequest, response *resource.ReadResponse) { + var data monitorResourceModel + response.Diagnostics.Append(request.State.Get(ctx, &data)...) + if response.Diagnostics.HasError() { + return + } + + conn := r.Meta().NetworkFlowMonitorClient(ctx) + + monitor, err := findMonitorByName(ctx, conn, data.MonitorName.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 Network Flow Monitor Monitor (%s)", data.ID.ValueString()), err.Error()) + return + } + + // Use flex.Flatten to automatically map API response to model + response.Diagnostics.Append(fwflex.Flatten(ctx, monitor, &data)...) + if response.Diagnostics.HasError() { + return + } + + // Set tags from API response + setTagsOut(ctx, monitor.Tags) + + response.Diagnostics.Append(response.State.Set(ctx, data)...) +} + +func (r *monitorResource) Update(ctx context.Context, request resource.UpdateRequest, response *resource.UpdateResponse) { + var old, new monitorResourceModel + response.Diagnostics.Append(request.State.Get(ctx, &old)...) + if response.Diagnostics.HasError() { + return + } + response.Diagnostics.Append(request.Plan.Get(ctx, &new)...) + if response.Diagnostics.HasError() { + return + } + + conn := r.Meta().NetworkFlowMonitorClient(ctx) + + if !new.Tags.Equal(old.Tags) { + if err := updateTags(ctx, conn, new.ID.ValueString(), old.Tags, new.Tags); err != nil { + response.Diagnostics.AddError(fmt.Sprintf("updating Network Flow Monitor Monitor (%s) tags", new.ID.ValueString()), err.Error()) + return + } + } + + response.Diagnostics.Append(response.State.Set(ctx, &new)...) +} + +func (r *monitorResource) Delete(ctx context.Context, request resource.DeleteRequest, response *resource.DeleteResponse) { + var data monitorResourceModel + response.Diagnostics.Append(request.State.Get(ctx, &data)...) + if response.Diagnostics.HasError() { + return + } + + conn := r.Meta().NetworkFlowMonitorClient(ctx) + + _, err := conn.DeleteMonitor(ctx, &networkflowmonitor.DeleteMonitorInput{ + MonitorName: aws.String(data.MonitorName.ValueString()), + }) + + if errs.IsA[*awstypes.ResourceNotFoundException](err) { + return + } + + if err != nil { + response.Diagnostics.AddError(fmt.Sprintf("deleting Network Flow Monitor Monitor (%s)", data.ID.ValueString()), err.Error()) + return + } + + if _, err := waitMonitorDeleted(ctx, conn, data.MonitorName.ValueString(), r.DeleteTimeout(ctx, data.Timeouts)); err != nil { + response.Diagnostics.AddError(fmt.Sprintf("waiting for Network Flow Monitor Monitor (%s) delete", data.ID.ValueString()), err.Error()) + return + } +} + +func findMonitorByName(ctx context.Context, conn *networkflowmonitor.Client, name string) (*networkflowmonitor.GetMonitorOutput, error) { + input := &networkflowmonitor.GetMonitorInput{ + MonitorName: aws.String(name), + } + + output, err := conn.GetMonitor(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 { + return nil, tfresource.NewEmptyResultError(input) + } + + return output, nil +} + +func statusMonitor(ctx context.Context, conn *networkflowmonitor.Client, name string) retry.StateRefreshFunc { + return func() (interface{}, string, error) { + output, err := findMonitorByName(ctx, conn, name) + + if tfresource.NotFound(err) { + return nil, "", nil + } + + if err != nil { + return nil, "", err + } + + return output, string(output.MonitorStatus), nil + } +} + +func waitMonitorCreated(ctx context.Context, conn *networkflowmonitor.Client, name string, timeout time.Duration) (*networkflowmonitor.GetMonitorOutput, error) { + stateConf := &retry.StateChangeConf{ + Pending: enum.Slice(awstypes.MonitorStatusPending), + Target: enum.Slice(awstypes.MonitorStatusActive), + Refresh: statusMonitor(ctx, conn, name), + Timeout: timeout, + } + + outputRaw, err := stateConf.WaitForStateContext(ctx) + + if output, ok := outputRaw.(*networkflowmonitor.GetMonitorOutput); ok { + return output, err + } + + return nil, err +} + +func waitMonitorDeleted(ctx context.Context, conn *networkflowmonitor.Client, name string, timeout time.Duration) (*networkflowmonitor.GetMonitorOutput, error) { + stateConf := &retry.StateChangeConf{ + Pending: enum.Slice(awstypes.MonitorStatusDeleting), + Target: []string{}, + Refresh: statusMonitor(ctx, conn, name), + Timeout: timeout, + } + + outputRaw, err := stateConf.WaitForStateContext(ctx) + + if output, ok := outputRaw.(*networkflowmonitor.GetMonitorOutput); ok { + return output, err + } + + return nil, err +} diff --git a/internal/service/networkflowmonitor/monitor_test.go b/internal/service/networkflowmonitor/monitor_test.go new file mode 100644 index 000000000000..8444c49b945b --- /dev/null +++ b/internal/service/networkflowmonitor/monitor_test.go @@ -0,0 +1,282 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package networkflowmonitor_test + +import ( + "context" + "fmt" + "testing" + + "github.com/aws/aws-sdk-go-v2/service/networkflowmonitor" + awstypes "github.com/aws/aws-sdk-go-v2/service/networkflowmonitor/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/errs" + tfnetworkflowmonitor "github.com/hashicorp/terraform-provider-aws/internal/service/networkflowmonitor" + "github.com/hashicorp/terraform-provider-aws/names" +) + +func TestAccNetworkFlowMonitorMonitor_basic(t *testing.T) { + ctx := acctest.Context(t) + var monitor networkflowmonitor.GetMonitorOutput + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_networkflowmonitor_monitor.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + testAccPreCheck(ctx, t) + }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckMonitorDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccMonitorConfig_basic(rName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName, &monitor), + resource.TestCheckResourceAttr(resourceName, "monitor_name", rName), + resource.TestCheckResourceAttrSet(resourceName, names.AttrARN), + resource.TestCheckResourceAttrSet(resourceName, "monitor_status"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorMonitor_disappears(t *testing.T) { + ctx := acctest.Context(t) + var monitor networkflowmonitor.GetMonitorOutput + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_networkflowmonitor_monitor.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + testAccPreCheck(ctx, t) + }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckMonitorDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccMonitorConfig_basic(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName, &monitor), + acctest.CheckFrameworkResourceDisappears(ctx, acctest.Provider, tfnetworkflowmonitor.ResourceMonitor, resourceName), + ), + ExpectNonEmptyPlan: true, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorMonitor_tags(t *testing.T) { + ctx := acctest.Context(t) + var monitor networkflowmonitor.GetMonitorOutput + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_networkflowmonitor_monitor.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + testAccPreCheck(ctx, t) + }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckMonitorDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccMonitorConfig_tags1(rName, "key1", "value1"), + Check: resource.ComposeTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName, &monitor), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccMonitorConfig_tags2(rName, "key1", "value1updated", "key2", "value2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName, &monitor), + resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1updated"), + resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), + ), + }, + { + Config: testAccMonitorConfig_tags1(rName, "key2", "value2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName, &monitor), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), + ), + }, + }, + }) +} + +func testAccCheckMonitorExists(ctx context.Context, n string, v *networkflowmonitor.GetMonitorOutput) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("Not found: %s", n) + } + + conn := acctest.Provider.Meta().(*conns.AWSClient).NetworkFlowMonitorClient(ctx) + + output, err := tfnetworkflowmonitor.FindMonitorByName(ctx, conn, rs.Primary.Attributes["monitor_name"]) + + if err != nil { + return err + } + + *v = *output + + return nil + } +} + +func testAccCheckMonitorDestroy(ctx context.Context) resource.TestCheckFunc { + return func(s *terraform.State) error { + conn := acctest.Provider.Meta().(*conns.AWSClient).NetworkFlowMonitorClient(ctx) + + for _, rs := range s.RootModule().Resources { + if rs.Type != "aws_networkflowmonitor_monitor" { + continue + } + + _, err := tfnetworkflowmonitor.FindMonitorByName(ctx, conn, rs.Primary.Attributes["monitor_name"]) + + if errs.IsA[*awstypes.ResourceNotFoundException](err) { + continue + } + + if err != nil { + return err + } + + return fmt.Errorf("Network Flow Monitor Monitor %s still exists", rs.Primary.ID) + } + + return nil + } +} + +func testAccMonitorConfig_basic(rName string) string { + return fmt.Sprintf(` +resource "aws_vpc" "test" { + cidr_block = "10.0.0.0/16" + + tags = { + Name = %[1]q + } +} + +resource "aws_networkflowmonitor_monitor" "test" { + monitor_name = %[1]q + scope_arn = "arn:aws:networkflowmonitor:us-east-1:123456789012:scope/test-scope" + + local_resources { + type = "AWS::EC2::VPC" + identifier = aws_vpc.test.arn + } + + remote_resources { + type = "AWS::EC2::VPC" + identifier = aws_vpc.test.arn + } +} +`, rName) +} + +func testAccMonitorConfig_tags1(rName, tagKey1, tagValue1 string) string { + return fmt.Sprintf(` +resource "aws_vpc" "test" { + cidr_block = "10.0.0.0/16" + + tags = { + Name = %[1]q + } +} + +resource "aws_networkflowmonitor_monitor" "test" { + monitor_name = %[1]q + scope_arn = "arn:aws:networkflowmonitor:us-east-1:123456789012:scope/test-scope" + + local_resources { + type = "AWS::EC2::VPC" + identifier = aws_vpc.test.arn + } + + remote_resources { + type = "AWS::EC2::VPC" + identifier = aws_vpc.test.arn + } + + tags = { + %[2]q = %[3]q + } +} +`, rName, tagKey1, tagValue1) +} + +func testAccMonitorConfig_tags2(rName, tagKey1, tagValue1, tagKey2, tagValue2 string) string { + return fmt.Sprintf(` +resource "aws_vpc" "test" { + cidr_block = "10.0.0.0/16" + + tags = { + Name = %[1]q + } +} + +resource "aws_networkflowmonitor_monitor" "test" { + monitor_name = %[1]q + scope_arn = "arn:aws:networkflowmonitor:us-east-1:123456789012:scope/test-scope" + + local_resources { + type = "AWS::EC2::VPC" + identifier = aws_vpc.test.arn + } + + remote_resources { + type = "AWS::EC2::VPC" + identifier = aws_vpc.test.arn + } + + tags = { + %[2]q = %[3]q + %[4]q = %[5]q + } +} +`, rName, tagKey1, tagValue1, tagKey2, tagValue2) +} +func testAccPreCheck(ctx context.Context, t *testing.T) { + conn := acctest.Provider.Meta().(*conns.AWSClient).NetworkFlowMonitorClient(ctx) + + input := &networkflowmonitor.ListMonitorsInput{} + + _, err := conn.ListMonitors(ctx, input) + + if acctest.PreCheckSkipError(err) { + t.Skipf("skipping acceptance testing: %s", err) + } + + if err != nil { + t.Fatalf("unexpected PreCheck error: %s", err) + } +} diff --git a/internal/service/networkflowmonitor/scope.go b/internal/service/networkflowmonitor/scope.go new file mode 100644 index 000000000000..f3dcb391f1ad --- /dev/null +++ b/internal/service/networkflowmonitor/scope.go @@ -0,0 +1,402 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package networkflowmonitor + +import ( + "context" + "fmt" + "time" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/networkflowmonitor" + awstypes "github.com/aws/aws-sdk-go-v2/service/networkflowmonitor/types" + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" + "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-provider-aws/internal/enum" + "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("aws_networkflowmonitor_scope", name="Scope") +// @Tags(identifierAttribute="arn") +func newScopeResource(_ context.Context) (resource.ResourceWithConfigure, error) { + r := &scopeResource{} + + r.SetDefaultCreateTimeout(30 * time.Minute) + r.SetDefaultUpdateTimeout(30 * time.Minute) + r.SetDefaultDeleteTimeout(30 * time.Minute) + + return r, nil +} + +type scopeResource struct { + framework.ResourceWithConfigure + framework.ResourceWithModel[scopeResourceModel] + framework.WithImportByID + framework.WithTimeouts +} + +func (r *scopeResource) Metadata(_ context.Context, request resource.MetadataRequest, response *resource.MetadataResponse) { + response.TypeName = request.ProviderTypeName + "_networkflowmonitor_scope" +} + +func (r *scopeResource) Schema(ctx context.Context, request resource.SchemaRequest, response *resource.SchemaResponse) { + response.Schema = schema.Schema{ + Attributes: map[string]schema.Attribute{ + names.AttrARN: framework.ARNAttributeComputedOnly(), + names.AttrID: framework.IDAttribute(), + "scope_id": schema.StringAttribute{ + Computed: true, + }, + names.AttrStatus: schema.StringAttribute{ + Computed: true, + }, + names.AttrTags: tftags.TagsAttribute(), + names.AttrTagsAll: tftags.TagsAttributeComputedOnly(), + }, + Blocks: map[string]schema.Block{ + "targets": schema.ListNestedBlock{ + CustomType: fwtypes.NewListNestedObjectTypeOf[targetResourceModel](ctx), + Validators: []validator.List{ + listvalidator.SizeAtLeast(1), + }, + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + names.AttrRegion: schema.StringAttribute{ + Required: true, + }, + }, + Blocks: map[string]schema.Block{ + "target_identifier": schema.ListNestedBlock{ + CustomType: fwtypes.NewListNestedObjectTypeOf[targetIdentifierModel](ctx), + Validators: []validator.List{ + listvalidator.SizeAtMost(1), + listvalidator.IsRequired(), + }, + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "target_id": schema.StringAttribute{ + Required: true, + }, + "target_type": schema.StringAttribute{ + Required: true, + }, + }, + }, + }, + }, + }, + }, + names.AttrTimeouts: timeouts.Block(ctx, timeouts.Opts{ + Create: true, + Update: true, + Delete: true, + }), + }, + } +} + +type scopeResourceModel struct { + ARN types.String `tfsdk:"arn"` + ID types.String `tfsdk:"id"` + ScopeId types.String `tfsdk:"scope_id"` + Status types.String `tfsdk:"status"` + Targets fwtypes.ListNestedObjectValueOf[targetResourceModel] `tfsdk:"targets"` + Tags tftags.Map `tfsdk:"tags"` + TagsAll tftags.Map `tfsdk:"tags_all"` + Timeouts timeouts.Value `tfsdk:"timeouts"` +} + +type targetResourceModel struct { + Region types.String `tfsdk:"region"` + TargetIdentifier fwtypes.ListNestedObjectValueOf[targetIdentifierModel] `tfsdk:"target_identifier"` +} + +type targetIdentifierModel struct { + TargetId types.String `tfsdk:"target_id"` + TargetType types.String `tfsdk:"target_type"` +} + +func (r *scopeResource) Create(ctx context.Context, request resource.CreateRequest, response *resource.CreateResponse) { + var data scopeResourceModel + response.Diagnostics.Append(request.Plan.Get(ctx, &data)...) + if response.Diagnostics.HasError() { + return + } + + conn := r.Meta().NetworkFlowMonitorClient(ctx) + + // MANDATORY: Use fwflex.Expand for automatic parameter mapping + input := &networkflowmonitor.CreateScopeInput{} + response.Diagnostics.Append(fwflex.Expand(ctx, data, input)...) + if response.Diagnostics.HasError() { + return + } + + // Handle union types that fwflex can't handle automatically + if !data.Targets.IsNull() && !data.Targets.IsUnknown() { + targets, diags := data.Targets.ToSlice(ctx) + response.Diagnostics.Append(diags...) + if response.Diagnostics.HasError() { + return + } + + input.Targets = make([]awstypes.TargetResource, len(targets)) + for i, target := range targets { + input.Targets[i].Region = aws.String(target.Region.ValueString()) + + if !target.TargetIdentifier.IsNull() && !target.TargetIdentifier.IsUnknown() { + targetIds, diags := target.TargetIdentifier.ToSlice(ctx) + response.Diagnostics.Append(diags...) + if response.Diagnostics.HasError() { + return + } + + if len(targetIds) > 0 { + targetId := targetIds[0] + input.Targets[i].TargetIdentifier = &awstypes.TargetIdentifier{ + TargetId: &awstypes.TargetIdMemberAccountId{ + Value: targetId.TargetId.ValueString(), + }, + TargetType: awstypes.TargetType(targetId.TargetType.ValueString()), + } + } + } + } + } + + // Set additional fields that need special handling + input.ClientToken = aws.String(uuid.New().String()) + input.Tags = getTagsIn(ctx) + + output, err := conn.CreateScope(ctx, input) + if err != nil { + response.Diagnostics.AddError("creating Network Flow Monitor Scope", err.Error()) + return + } + + // Set ID and computed attributes + data.ID = types.StringValue(aws.ToString(output.ScopeArn)) + data.ARN = types.StringValue(aws.ToString(output.ScopeArn)) + + // Wait for scope to be ready + scope, err := waitScopeCreated(ctx, conn, aws.ToString(output.ScopeId), r.CreateTimeout(ctx, data.Timeouts)) + if err != nil { + response.Diagnostics.AddError(fmt.Sprintf("waiting for Network Flow Monitor Scope (%s) create", data.ID.ValueString()), err.Error()) + return + } + + // Set computed attributes + data.ScopeId = types.StringValue(aws.ToString(scope.ScopeId)) + data.Status = types.StringValue(string(scope.Status)) + + response.Diagnostics.Append(response.State.Set(ctx, data)...) +} + +func (r *scopeResource) Read(ctx context.Context, request resource.ReadRequest, response *resource.ReadResponse) { + var data scopeResourceModel + response.Diagnostics.Append(request.State.Get(ctx, &data)...) + if response.Diagnostics.HasError() { + return + } + + conn := r.Meta().NetworkFlowMonitorClient(ctx) + + output, err := findScopeByID(ctx, conn, data.ScopeId.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 Network Flow Monitor Scope (%s)", data.ID.ValueString()), err.Error()) + return + } + + // MANDATORY: Use fwflex.Flatten for automatic parameter mapping + response.Diagnostics.Append(fwflex.Flatten(ctx, output, &data)...) + if response.Diagnostics.HasError() { + return + } + + // Handle union types that fwflex can't handle automatically + if len(output.Targets) > 0 { + targetModels := make([]targetResourceModel, len(output.Targets)) + for i, target := range output.Targets { + targetModels[i].Region = types.StringValue(aws.ToString(target.Region)) + + if target.TargetIdentifier != nil { + var targetIdValue string + if accountId, ok := target.TargetIdentifier.TargetId.(*awstypes.TargetIdMemberAccountId); ok { + targetIdValue = accountId.Value + } + + targetIdModel := targetIdentifierModel{ + TargetId: types.StringValue(targetIdValue), + TargetType: types.StringValue(string(target.TargetIdentifier.TargetType)), + } + + targetIdentifierList, diags := fwtypes.NewListNestedObjectValueOfValueSlice(ctx, []targetIdentifierModel{targetIdModel}) + response.Diagnostics.Append(diags...) + if response.Diagnostics.HasError() { + return + } + targetModels[i].TargetIdentifier = targetIdentifierList + } + } + + targetsList, diags := fwtypes.NewListNestedObjectValueOfValueSlice(ctx, targetModels) + response.Diagnostics.Append(diags...) + if response.Diagnostics.HasError() { + return + } + data.Targets = targetsList + } + + // Set tags from API response + setTagsOut(ctx, output.Tags) + + response.Diagnostics.Append(response.State.Set(ctx, &data)...) +} + +func (r *scopeResource) Update(ctx context.Context, request resource.UpdateRequest, response *resource.UpdateResponse) { + var old, new scopeResourceModel + response.Diagnostics.Append(request.State.Get(ctx, &old)...) + if response.Diagnostics.HasError() { + return + } + response.Diagnostics.Append(request.Plan.Get(ctx, &new)...) + if response.Diagnostics.HasError() { + return + } + + conn := r.Meta().NetworkFlowMonitorClient(ctx) + + // Handle tag updates + if !new.Tags.Equal(old.Tags) { + if err := updateTags(ctx, conn, new.ID.ValueString(), old.Tags, new.Tags); err != nil { + response.Diagnostics.AddError(fmt.Sprintf("updating Network Flow Monitor Scope (%s) tags", new.ID.ValueString()), err.Error()) + return + } + } + + response.Diagnostics.Append(response.State.Set(ctx, &new)...) +} + +func (r *scopeResource) Delete(ctx context.Context, request resource.DeleteRequest, response *resource.DeleteResponse) { + var data scopeResourceModel + response.Diagnostics.Append(request.State.Get(ctx, &data)...) + if response.Diagnostics.HasError() { + return + } + + conn := r.Meta().NetworkFlowMonitorClient(ctx) + + _, err := conn.DeleteScope(ctx, &networkflowmonitor.DeleteScopeInput{ + ScopeId: aws.String(data.ScopeId.ValueString()), + }) + + if errs.IsA[*awstypes.ResourceNotFoundException](err) { + return + } + + if err != nil { + response.Diagnostics.AddError(fmt.Sprintf("deleting Network Flow Monitor Scope (%s)", data.ID.ValueString()), err.Error()) + return + } + + if _, err := waitScopeDeleted(ctx, conn, data.ScopeId.ValueString(), r.DeleteTimeout(ctx, data.Timeouts)); err != nil { + response.Diagnostics.AddError(fmt.Sprintf("waiting for Network Flow Monitor Scope (%s) delete", data.ID.ValueString()), err.Error()) + return + } +} + +func findScopeByID(ctx context.Context, conn *networkflowmonitor.Client, id string) (*networkflowmonitor.GetScopeOutput, error) { + input := &networkflowmonitor.GetScopeInput{ + ScopeId: aws.String(id), + } + + output, err := conn.GetScope(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 { + return nil, tfresource.NewEmptyResultError(input) + } + + return output, nil +} + +func statusScope(ctx context.Context, conn *networkflowmonitor.Client, id string) retry.StateRefreshFunc { + return func() (interface{}, string, error) { + output, err := findScopeByID(ctx, conn, id) + + if tfresource.NotFound(err) { + return nil, "", nil + } + + if err != nil { + return nil, "", err + } + + return output, string(output.Status), nil + } +} + +func waitScopeCreated(ctx context.Context, conn *networkflowmonitor.Client, id string, timeout time.Duration) (*networkflowmonitor.GetScopeOutput, error) { + stateConf := &retry.StateChangeConf{ + Pending: enum.Slice(awstypes.ScopeStatusInProgress), + Target: enum.Slice(awstypes.ScopeStatusSucceeded), + Refresh: statusScope(ctx, conn, id), + Timeout: timeout, + } + + outputRaw, err := stateConf.WaitForStateContext(ctx) + + if output, ok := outputRaw.(*networkflowmonitor.GetScopeOutput); ok { + return output, err + } + + return nil, err +} + +func waitScopeDeleted(ctx context.Context, conn *networkflowmonitor.Client, id string, timeout time.Duration) (*networkflowmonitor.GetScopeOutput, error) { + stateConf := &retry.StateChangeConf{ + Pending: enum.Slice(awstypes.ScopeStatusDeactivating), + Target: []string{}, + Refresh: statusScope(ctx, conn, id), + Timeout: timeout, + } + + outputRaw, err := stateConf.WaitForStateContext(ctx) + + if output, ok := outputRaw.(*networkflowmonitor.GetScopeOutput); ok { + return output, err + } + + return nil, err +} diff --git a/internal/service/networkflowmonitor/scope_test.go b/internal/service/networkflowmonitor/scope_test.go new file mode 100644 index 000000000000..c4ff96d31f5c --- /dev/null +++ b/internal/service/networkflowmonitor/scope_test.go @@ -0,0 +1,230 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package networkflowmonitor_test + +import ( + "context" + "fmt" + "testing" + + "github.com/aws/aws-sdk-go-v2/service/networkflowmonitor" + awstypes "github.com/aws/aws-sdk-go-v2/service/networkflowmonitor/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/errs" + tfnetworkflowmonitor "github.com/hashicorp/terraform-provider-aws/internal/service/networkflowmonitor" + "github.com/hashicorp/terraform-provider-aws/names" +) + +func TestAccNetworkFlowMonitorScope_basic(t *testing.T) { + ctx := acctest.Context(t) + var scope networkflowmonitor.GetScopeOutput + resourceName := "aws_networkflowmonitor_scope.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + testAccPreCheck(ctx, t) + }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckScopeDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccScopeConfig_basic(), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName, &scope), + resource.TestCheckResourceAttrSet(resourceName, names.AttrARN), + resource.TestCheckResourceAttrSet(resourceName, "scope_id"), + resource.TestCheckResourceAttrSet(resourceName, names.AttrStatus), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorScope_disappears(t *testing.T) { + ctx := acctest.Context(t) + var scope networkflowmonitor.GetScopeOutput + resourceName := "aws_networkflowmonitor_scope.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + testAccPreCheck(ctx, t) + }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckScopeDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccScopeConfig_basic(), + Check: resource.ComposeTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName, &scope), + acctest.CheckFrameworkResourceDisappears(ctx, acctest.Provider, tfnetworkflowmonitor.ResourceScope, resourceName), + ), + ExpectNonEmptyPlan: true, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorScope_tags(t *testing.T) { + ctx := acctest.Context(t) + var scope networkflowmonitor.GetScopeOutput + resourceName := "aws_networkflowmonitor_scope.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + testAccPreCheck(ctx, t) + }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckScopeDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccScopeConfig_tags1("key1", "value1"), + Check: resource.ComposeTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName, &scope), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccScopeConfig_tags2("key1", "value1updated", "key2", "value2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName, &scope), + resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1updated"), + resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), + ), + }, + { + Config: testAccScopeConfig_tags1("key2", "value2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName, &scope), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), + ), + }, + }, + }) +} + +func testAccCheckScopeExists(ctx context.Context, n string, v *networkflowmonitor.GetScopeOutput) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("Not found: %s", n) + } + + conn := acctest.Provider.Meta().(*conns.AWSClient).NetworkFlowMonitorClient(ctx) + + output, err := tfnetworkflowmonitor.FindScopeByID(ctx, conn, rs.Primary.Attributes["scope_id"]) + + if err != nil { + return err + } + + *v = *output + + return nil + } +} + +func testAccCheckScopeDestroy(ctx context.Context) resource.TestCheckFunc { + return func(s *terraform.State) error { + conn := acctest.Provider.Meta().(*conns.AWSClient).NetworkFlowMonitorClient(ctx) + + for _, rs := range s.RootModule().Resources { + if rs.Type != "aws_networkflowmonitor_scope" { + continue + } + + _, err := tfnetworkflowmonitor.FindScopeByID(ctx, conn, rs.Primary.Attributes["scope_id"]) + + if errs.IsA[*awstypes.ResourceNotFoundException](err) { + continue + } + + if err != nil { + return err + } + + return fmt.Errorf("Network Flow Monitor Scope %s still exists", rs.Primary.ID) + } + + return nil + } +} + +func testAccScopeConfig_basic() string { + return ` +data "aws_caller_identity" "current" {} + +resource "aws_networkflowmonitor_scope" "test" { + targets { + region = "us-east-1" + target_identifier { + target_id = data.aws_caller_identity.current.account_id + target_type = "ACCOUNT" + } + } +} +` +} + +func testAccScopeConfig_tags1(tagKey1, tagValue1 string) string { + return fmt.Sprintf(` +data "aws_caller_identity" "current" {} + +resource "aws_networkflowmonitor_scope" "test" { + targets { + region = "us-east-1" + target_identifier { + target_id = data.aws_caller_identity.current.account_id + target_type = "ACCOUNT" + } + } + + tags = { + %[1]q = %[2]q + } +} +`, tagKey1, tagValue1) +} + +func testAccScopeConfig_tags2(tagKey1, tagValue1, tagKey2, tagValue2 string) string { + return fmt.Sprintf(` +data "aws_caller_identity" "current" {} + +resource "aws_networkflowmonitor_scope" "test" { + targets { + region = "us-east-1" + target_identifier { + target_id = data.aws_caller_identity.current.account_id + target_type = "ACCOUNT" + } + } + + tags = { + %[1]q = %[2]q + %[3]q = %[4]q + } +} +`, tagKey1, tagValue1, tagKey2, tagValue2) +} diff --git a/internal/service/networkflowmonitor/service_package_gen.go b/internal/service/networkflowmonitor/service_package_gen.go index f0c06407b5b7..c695ee9bf032 100644 --- a/internal/service/networkflowmonitor/service_package_gen.go +++ b/internal/service/networkflowmonitor/service_package_gen.go @@ -21,7 +21,18 @@ func (p *servicePackage) FrameworkDataSources(ctx context.Context) []*inttypes.S } func (p *servicePackage) FrameworkResources(ctx context.Context) []*inttypes.ServicePackageFrameworkResource { - return []*inttypes.ServicePackageFrameworkResource{} + return []*inttypes.ServicePackageFrameworkResource{ + { + Factory: newMonitorResource, + TypeName: "aws_networkflowmonitor_monitor", + Name: "Monitor", + }, + { + Factory: newScopeResource, + TypeName: "aws_networkflowmonitor_scope", + Name: "Scope", + }, + } } func (p *servicePackage) SDKDataSources(ctx context.Context) []*inttypes.ServicePackageSDKDataSource { diff --git a/internal/service/networkflowmonitor/sweep.go b/internal/service/networkflowmonitor/sweep.go new file mode 100644 index 000000000000..f6c9377c328b --- /dev/null +++ b/internal/service/networkflowmonitor/sweep.go @@ -0,0 +1,113 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package networkflowmonitor + +import ( + "fmt" + "log" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/networkflowmonitor" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-provider-aws/internal/sweep" + "github.com/hashicorp/terraform-provider-aws/internal/sweep/awsv2" + "github.com/hashicorp/terraform-provider-aws/internal/sweep/framework" +) + +func RegisterSweepers() { + resource.AddTestSweepers("aws_networkflowmonitor_monitor", &resource.Sweeper{ + Name: "aws_networkflowmonitor_monitor", + F: sweepMonitors, + }) + + resource.AddTestSweepers("aws_networkflowmonitor_scope", &resource.Sweeper{ + Name: "aws_networkflowmonitor_scope", + F: sweepScopes, + }) +} + +func sweepMonitors(region string) error { + ctx := sweep.Context(region) + client, err := sweep.SharedRegionalSweepClient(ctx, region) + if err != nil { + return fmt.Errorf("error getting client: %s", err) + } + conn := client.NetworkFlowMonitorClient(ctx) + input := &networkflowmonitor.ListMonitorsInput{} + sweepResources := make([]sweep.Sweepable, 0) + + pages := networkflowmonitor.NewListMonitorsPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if awsv2.SkipSweepError(err) { + log.Printf("[WARN] Skipping Network Flow Monitor Monitor sweep for %s: %s", region, err) + return nil + } + + if err != nil { + return fmt.Errorf("error listing Network Flow Monitor Monitors (%s): %w", region, err) + } + + for _, v := range page.Monitors { + arn := aws.ToString(v.MonitorArn) + name := aws.ToString(v.MonitorName) + + sweepResources = append(sweepResources, framework.NewSweepResource(newMonitorResource, client, + framework.NewAttribute("id", arn), + framework.NewAttribute("monitor_name", name), + )) + } + } + + err = sweep.SweepOrchestrator(ctx, sweepResources) + + if err != nil { + return fmt.Errorf("error sweeping Network Flow Monitor Monitors (%s): %w", region, err) + } + + return nil +} +func sweepScopes(region string) error { + ctx := sweep.Context(region) + client, err := sweep.SharedRegionalSweepClient(ctx, region) + if err != nil { + return fmt.Errorf("error getting client: %s", err) + } + conn := client.NetworkFlowMonitorClient(ctx) + input := &networkflowmonitor.ListScopesInput{} + sweepResources := make([]sweep.Sweepable, 0) + + pages := networkflowmonitor.NewListScopesPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if awsv2.SkipSweepError(err) { + log.Printf("[WARN] Skipping Network Flow Monitor Scope sweep for %s: %s", region, err) + return nil + } + + if err != nil { + return fmt.Errorf("error listing Network Flow Monitor Scopes (%s): %w", region, err) + } + + for _, v := range page.Scopes { + scopeId := aws.ToString(v.ScopeId) + scopeArn := aws.ToString(v.ScopeArn) + + sweepResources = append(sweepResources, framework.NewSweepResource(newScopeResource, client, + framework.NewAttribute("id", scopeArn), + framework.NewAttribute("scope_id", scopeId), + )) + } + } + + err = sweep.SweepOrchestrator(ctx, sweepResources) + + if err != nil { + return fmt.Errorf("error sweeping Network Flow Monitor Scopes (%s): %w", region, err) + } + + return nil +} diff --git a/internal/sweep/register_gen_test.go b/internal/sweep/register_gen_test.go index 9d948704d3b5..3ea4eda45708 100644 --- a/internal/sweep/register_gen_test.go +++ b/internal/sweep/register_gen_test.go @@ -119,6 +119,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/service/neptune" "github.com/hashicorp/terraform-provider-aws/internal/service/neptunegraph" "github.com/hashicorp/terraform-provider-aws/internal/service/networkfirewall" + "github.com/hashicorp/terraform-provider-aws/internal/service/networkflowmonitor" "github.com/hashicorp/terraform-provider-aws/internal/service/networkmanager" "github.com/hashicorp/terraform-provider-aws/internal/service/notifications" "github.com/hashicorp/terraform-provider-aws/internal/service/notificationscontacts" @@ -300,6 +301,7 @@ func registerSweepers() { neptune.RegisterSweepers() neptunegraph.RegisterSweepers() networkfirewall.RegisterSweepers() + networkflowmonitor.RegisterSweepers() networkmanager.RegisterSweepers() notifications.RegisterSweepers() notificationscontacts.RegisterSweepers() diff --git a/website/docs/r/networkflowmonitor_monitor.html.markdown b/website/docs/r/networkflowmonitor_monitor.html.markdown new file mode 100644 index 000000000000..4f601a5aadc9 --- /dev/null +++ b/website/docs/r/networkflowmonitor_monitor.html.markdown @@ -0,0 +1,95 @@ +--- +subcategory: "Network Flow Monitor" +layout: "aws" +page_title: "AWS: aws_networkflowmonitor_monitor" +description: |- + Manages a Network Flow Monitor Monitor. +--- + +# Resource: aws_networkflowmonitor_monitor + +Manages a Network Flow Monitor Monitor. + +## Example Usage + +### Basic Usage + +```terraform +resource "aws_vpc" "example" { + cidr_block = "10.0.0.0/16" + + tags = { + Name = "example" + } +} + +resource "aws_networkflowmonitor_monitor" "example" { + monitor_name = "example-monitor" + scope_arn = aws_networkflowmonitor_scope.example.arn + + local_resources { + type = "AWS::EC2::VPC" + identifier = aws_vpc.example.arn + } + + remote_resources { + type = "AWS::EC2::VPC" + identifier = aws_vpc.example.arn + } + + tags = { + Name = "example" + } +} +``` + +## Argument Reference + +This resource supports the following arguments: + +* `monitor_name` - (Required) The name of the monitor. Cannot be changed after creation. +* `scope_arn` - (Required) The Amazon Resource Name (ARN) of the scope for the monitor. Cannot be changed after creation. +* `local_resources` - (Optional) The local resources to monitor. A local resource in a workload is the location of the hosts where the Network Flow Monitor agent is installed. +* `remote_resources` - (Optional) The remote resources to monitor. A remote resource is the other endpoint specified for the network flow of a workload, with a local resource. +* `tags` - (Optional) A 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. + +### local_resources and remote_resources + +The `local_resources` and `remote_resources` blocks support the following: + +* `type` - (Required) The type of the resource. Valid values are `AWS::EC2::VPC`, `AWS::EC2::Subnet`, `AWS::EC2::AvailabilityZone`, `AWS::EC2::Region`. +* `identifier` - (Required) The identifier of the resource. For VPC resources, this is the VPC ARN. + +## Attribute Reference + +This resource exports the following attributes in addition to the arguments above: + +* `arn` - The Amazon Resource Name (ARN) of the monitor. +* `id` - The Amazon Resource Name (ARN) of the monitor. +* `monitor_status` - The status of the monitor. Can be `PENDING`, `ACTIVE`, `INACTIVE`, `ERROR`, or `DELETING`. +* `tags_all` - A 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 + +[Configuration options](https://developer.hashicorp.com/terraform/language/resources/syntax#operation-timeouts): + +* `create` - (Default `30m`) +* `update` - (Default `30m`) +* `delete` - (Default `30m`) + +## Import + +In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import Network Flow Monitor Monitor using the monitor ARN. For example: + +```terraform +import { + to = aws_networkflowmonitor_monitor.example + id = "arn:aws:networkflowmonitor:us-west-2:123456789012:monitor/example-monitor" +} +``` + +Using `terraform import`, import Network Flow Monitor Monitor using the monitor ARN. For example: + +```console +% terraform import aws_networkflowmonitor_monitor.example arn:aws:networkflowmonitor:us-west-2:123456789012:monitor/example-monitor +``` \ No newline at end of file diff --git a/website/docs/r/networkflowmonitor_scope.html.markdown b/website/docs/r/networkflowmonitor_scope.html.markdown new file mode 100644 index 000000000000..54d817162dad --- /dev/null +++ b/website/docs/r/networkflowmonitor_scope.html.markdown @@ -0,0 +1,117 @@ +--- +subcategory: "Network Flow Monitor" +layout: "aws" +page_title: "AWS: aws_networkflowmonitor_scope" +description: |- + Manages a Network Flow Monitor Scope. +--- + +# Resource: aws_networkflowmonitor_scope + +Manages a Network Flow Monitor Scope. + +## Example Usage + +### Basic Usage + +```terraform +data "aws_caller_identity" "current" {} + +resource "aws_networkflowmonitor_scope" "example" { + targets { + region = "us-east-1" + target_identifier { + target_id = data.aws_caller_identity.current.account_id + target_type = "ACCOUNT" + } + } + + tags = { + Name = "example" + } +} +``` + +### Multiple Targets + +```terraform +data "aws_caller_identity" "current" {} + +resource "aws_networkflowmonitor_scope" "example" { + targets { + region = "us-east-1" + target_identifier { + target_id = data.aws_caller_identity.current.account_id + target_type = "ACCOUNT" + } + } + + targets { + region = "us-west-2" + target_identifier { + target_id = data.aws_caller_identity.current.account_id + target_type = "ACCOUNT" + } + } + + tags = { + Name = "example" + } +} +``` + +## Argument Reference + +This resource supports the following arguments: + +* `targets` - (Required) The targets to define the scope to be monitored. A target is an array of target resources, which are currently Region-account pairs. +* `tags` - (Optional) A 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. + +### targets + +The `targets` block supports the following: + +* `region` - (Required) The AWS Region for the scope. +* `target_identifier` - (Required) A target identifier is a pair of identifying information for a scope. + +### target_identifier + +The `target_identifier` block supports the following: + +* `target_id` - (Required) The identifier for a target, which is currently always an account ID. +* `target_type` - (Required) The type of a target. A target type is currently always `ACCOUNT`. + +## Attribute Reference + +This resource exports the following attributes in addition to the arguments above: + +* `arn` - The Amazon Resource Name (ARN) of the scope. +* `id` - The Amazon Resource Name (ARN) of the scope. +* `scope_id` - The identifier for the scope that includes the resources you want to get data results for. +* `status` - The status for a scope. The status can be one of the following: `SUCCEEDED`, `IN_PROGRESS`, `FAILED`, `DEACTIVATING`, or `DEACTIVATED`. +* `tags_all` - A 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 + +[Configuration options](https://developer.hashicorp.com/terraform/language/resources/syntax#operation-timeouts): + +* `create` - (Default `30m`) +* `update` - (Default `30m`) +* `delete` - (Default `30m`) + +## Import + +In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import Network Flow Monitor Scope using the scope ARN. For example: + +```terraform +import { + to = aws_networkflowmonitor_scope.example + id = "arn:aws:networkflowmonitor:us-east-1:123456789012:scope/example-scope-id" +} +``` + +Using `terraform import`, import Network Flow Monitor Scope using the scope ARN. For example: + +```console +% terraform import aws_networkflowmonitor_scope.example arn:aws:networkflowmonitor:us-east-1:123456789012:scope/example-scope-id +``` \ No newline at end of file From 2a1f001265e918fd06340467eb2953c16b0ed2b5 Mon Sep 17 00:00:00 2001 From: Sasi Date: Tue, 21 Oct 2025 23:17:43 -0400 Subject: [PATCH 02/21] feat: added monitor and scope resources for networkflowmonitor service --- .../service/networkflowmonitor/monitor.go | 250 ++++++++++++-- .../networkflowmonitor/monitor_test.go | 177 +++++++++- internal/service/networkflowmonitor/scope.go | 317 +++++++++++++++++- .../service/networkflowmonitor/scope_test.go | 26 +- .../networkflowmonitor/service_package_gen.go | 7 + .../r/networkflowmonitor_scope.html.markdown | 27 -- 6 files changed, 715 insertions(+), 89 deletions(-) diff --git a/internal/service/networkflowmonitor/monitor.go b/internal/service/networkflowmonitor/monitor.go index 86ba75456a2b..0dfe1bfe586b 100644 --- a/internal/service/networkflowmonitor/monitor.go +++ b/internal/service/networkflowmonitor/monitor.go @@ -6,13 +6,15 @@ package networkflowmonitor import ( "context" "fmt" + "strings" "time" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/networkflowmonitor" awstypes "github.com/aws/aws-sdk-go-v2/service/networkflowmonitor/types" "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" - "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" + "github.com/hashicorp/terraform-plugin-framework-validators/setvalidator" + "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" @@ -46,7 +48,6 @@ func newMonitorResource(_ context.Context) (resource.ResourceWithConfigure, erro type monitorResource struct { framework.ResourceWithConfigure framework.ResourceWithModel[monitorResourceModel] - framework.WithImportByID framework.WithTimeouts } @@ -73,15 +74,18 @@ func (r *monitorResource) Schema(ctx context.Context, request resource.SchemaReq }, "monitor_status": schema.StringAttribute{ Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, }, names.AttrTags: tftags.TagsAttribute(), names.AttrTagsAll: tftags.TagsAttributeComputedOnly(), }, Blocks: map[string]schema.Block{ - "local_resources": schema.ListNestedBlock{ - CustomType: fwtypes.NewListNestedObjectTypeOf[monitorResourceConfigModel](ctx), - Validators: []validator.List{ - listvalidator.SizeAtMost(1), + "local_resources": schema.SetNestedBlock{ + CustomType: fwtypes.NewSetNestedObjectTypeOf[monitorResourceConfigModel](ctx), + Validators: []validator.Set{ + setvalidator.SizeAtLeast(1), }, NestedObject: schema.NestedBlockObject{ Attributes: map[string]schema.Attribute{ @@ -94,11 +98,8 @@ func (r *monitorResource) Schema(ctx context.Context, request resource.SchemaReq }, }, }, - "remote_resources": schema.ListNestedBlock{ - CustomType: fwtypes.NewListNestedObjectTypeOf[monitorResourceConfigModel](ctx), - Validators: []validator.List{ - listvalidator.SizeAtMost(1), - }, + "remote_resources": schema.SetNestedBlock{ + CustomType: fwtypes.NewSetNestedObjectTypeOf[monitorResourceConfigModel](ctx), NestedObject: schema.NestedBlockObject{ Attributes: map[string]schema.Attribute{ "type": schema.StringAttribute{ @@ -120,16 +121,16 @@ func (r *monitorResource) Schema(ctx context.Context, request resource.SchemaReq } type monitorResourceModel struct { - ARN types.String `tfsdk:"arn"` - ID types.String `tfsdk:"id"` - MonitorName types.String `tfsdk:"monitor_name"` - ScopeArn types.String `tfsdk:"scope_arn"` - MonitorStatus types.String `tfsdk:"monitor_status"` - LocalResources fwtypes.ListNestedObjectValueOf[monitorResourceConfigModel] `tfsdk:"local_resources"` - RemoteResources fwtypes.ListNestedObjectValueOf[monitorResourceConfigModel] `tfsdk:"remote_resources"` - Tags tftags.Map `tfsdk:"tags"` - TagsAll tftags.Map `tfsdk:"tags_all"` - Timeouts timeouts.Value `tfsdk:"timeouts"` + ARN types.String `tfsdk:"arn"` + ID types.String `tfsdk:"id"` + MonitorName types.String `tfsdk:"monitor_name"` + ScopeArn types.String `tfsdk:"scope_arn"` + MonitorStatus types.String `tfsdk:"monitor_status"` + LocalResources fwtypes.SetNestedObjectValueOf[monitorResourceConfigModel] `tfsdk:"local_resources"` + RemoteResources fwtypes.SetNestedObjectValueOf[monitorResourceConfigModel] `tfsdk:"remote_resources"` + Tags tftags.Map `tfsdk:"tags"` + TagsAll tftags.Map `tfsdk:"tags_all"` + Timeouts timeouts.Value `tfsdk:"timeouts"` } type monitorResourceConfigModel struct { @@ -171,8 +172,11 @@ func (r *monitorResource) Create(ctx context.Context, request resource.CreateReq return } - // Set computed attributes - data.MonitorStatus = types.StringValue(string(monitor.MonitorStatus)) + // Use fwflex.Flatten to set all attributes including tags_all + response.Diagnostics.Append(fwflex.Flatten(ctx, monitor, &data)...) + if response.Diagnostics.HasError() { + return + } response.Diagnostics.Append(response.State.Set(ctx, data)...) } @@ -199,14 +203,19 @@ func (r *monitorResource) Read(ctx context.Context, request resource.ReadRequest return } - // Use flex.Flatten to automatically map API response to model + // Use fwflex.Flatten to automatically map API response to model response.Diagnostics.Append(fwflex.Flatten(ctx, monitor, &data)...) if response.Diagnostics.HasError() { return } - // Set tags from API response - setTagsOut(ctx, monitor.Tags) + // Ensure ID and ARN are set properly (especially important for import) + if data.ID.IsNull() || data.ID.IsUnknown() { + data.ID = types.StringValue(aws.ToString(monitor.MonitorArn)) + } + if data.ARN.IsNull() || data.ARN.IsUnknown() { + data.ARN = types.StringValue(aws.ToString(monitor.MonitorArn)) + } response.Diagnostics.Append(response.State.Set(ctx, data)...) } @@ -224,11 +233,153 @@ func (r *monitorResource) Update(ctx context.Context, request resource.UpdateReq conn := r.Meta().NetworkFlowMonitorClient(ctx) - if !new.Tags.Equal(old.Tags) { - if err := updateTags(ctx, conn, new.ID.ValueString(), old.Tags, new.Tags); err != nil { - response.Diagnostics.AddError(fmt.Sprintf("updating Network Flow Monitor Monitor (%s) tags", new.ID.ValueString()), err.Error()) + // Check if local_resources or remote_resources have changed + if !new.LocalResources.Equal(old.LocalResources) || !new.RemoteResources.Equal(old.RemoteResources) { + input := &networkflowmonitor.UpdateMonitorInput{ + MonitorName: aws.String(new.MonitorName.ValueString()), + } + + // Calculate local resources diff + oldLocalResources := make(map[string]awstypes.MonitorLocalResource) + newLocalResources := make(map[string]awstypes.MonitorLocalResource) + + // Build map of old local resources + if !old.LocalResources.IsNull() && !old.LocalResources.IsUnknown() { + oldLocalSlice, diags := old.LocalResources.ToSlice(ctx) + response.Diagnostics.Append(diags...) + if response.Diagnostics.HasError() { + return + } + for _, resource := range oldLocalSlice { + key := resource.Type.ValueString() + "|" + resource.Identifier.ValueString() + oldLocalResources[key] = awstypes.MonitorLocalResource{ + Type: awstypes.MonitorLocalResourceType(resource.Type.ValueString()), + Identifier: aws.String(resource.Identifier.ValueString()), + } + } + } + + // Build map of new local resources + if !new.LocalResources.IsNull() && !new.LocalResources.IsUnknown() { + newLocalSlice, diags := new.LocalResources.ToSlice(ctx) + response.Diagnostics.Append(diags...) + if response.Diagnostics.HasError() { + return + } + for _, resource := range newLocalSlice { + key := resource.Type.ValueString() + "|" + resource.Identifier.ValueString() + newLocalResources[key] = awstypes.MonitorLocalResource{ + Type: awstypes.MonitorLocalResourceType(resource.Type.ValueString()), + Identifier: aws.String(resource.Identifier.ValueString()), + } + } + } + + // Find resources to add (in new but not in old) + var localResourcesToAdd []awstypes.MonitorLocalResource + for key, resource := range newLocalResources { + if _, exists := oldLocalResources[key]; !exists { + localResourcesToAdd = append(localResourcesToAdd, resource) + } + } + + // Find resources to remove (in old but not in new) + var localResourcesToRemove []awstypes.MonitorLocalResource + for key, resource := range oldLocalResources { + if _, exists := newLocalResources[key]; !exists { + localResourcesToRemove = append(localResourcesToRemove, resource) + } + } + + // Calculate remote resources diff + oldRemoteResources := make(map[string]awstypes.MonitorRemoteResource) + newRemoteResources := make(map[string]awstypes.MonitorRemoteResource) + + // Build map of old remote resources + if !old.RemoteResources.IsNull() && !old.RemoteResources.IsUnknown() { + oldRemoteSlice, diags := old.RemoteResources.ToSlice(ctx) + response.Diagnostics.Append(diags...) + if response.Diagnostics.HasError() { + return + } + for _, resource := range oldRemoteSlice { + key := resource.Type.ValueString() + "|" + resource.Identifier.ValueString() + oldRemoteResources[key] = awstypes.MonitorRemoteResource{ + Type: awstypes.MonitorRemoteResourceType(resource.Type.ValueString()), + Identifier: aws.String(resource.Identifier.ValueString()), + } + } + } + + // Build map of new remote resources + if !new.RemoteResources.IsNull() && !new.RemoteResources.IsUnknown() { + newRemoteSlice, diags := new.RemoteResources.ToSlice(ctx) + response.Diagnostics.Append(diags...) + if response.Diagnostics.HasError() { + return + } + for _, resource := range newRemoteSlice { + key := resource.Type.ValueString() + "|" + resource.Identifier.ValueString() + newRemoteResources[key] = awstypes.MonitorRemoteResource{ + Type: awstypes.MonitorRemoteResourceType(resource.Type.ValueString()), + Identifier: aws.String(resource.Identifier.ValueString()), + } + } + } + + // Find resources to add (in new but not in old) + var remoteResourcesToAdd []awstypes.MonitorRemoteResource + for key, resource := range newRemoteResources { + if _, exists := oldRemoteResources[key]; !exists { + remoteResourcesToAdd = append(remoteResourcesToAdd, resource) + } + } + + // Find resources to remove (in old but not in new) + var remoteResourcesToRemove []awstypes.MonitorRemoteResource + for key, resource := range oldRemoteResources { + if _, exists := newRemoteResources[key]; !exists { + remoteResourcesToRemove = append(remoteResourcesToRemove, resource) + } + } + + // Set the calculated diffs in the input + if len(localResourcesToAdd) > 0 { + input.LocalResourcesToAdd = localResourcesToAdd + } + if len(localResourcesToRemove) > 0 { + input.LocalResourcesToRemove = localResourcesToRemove + } + if len(remoteResourcesToAdd) > 0 { + input.RemoteResourcesToAdd = remoteResourcesToAdd + } + if len(remoteResourcesToRemove) > 0 { + input.RemoteResourcesToRemove = remoteResourcesToRemove + } + + _, err := conn.UpdateMonitor(ctx, input) + if err != nil { + response.Diagnostics.AddError(fmt.Sprintf("updating Network Flow Monitor Monitor (%s)", new.ID.ValueString()), err.Error()) + return + } + + // Wait for the update to complete + monitor, err := waitMonitorUpdated(ctx, conn, new.MonitorName.ValueString(), r.UpdateTimeout(ctx, new.Timeouts)) + if err != nil { + response.Diagnostics.AddError(fmt.Sprintf("waiting for Network Flow Monitor Monitor (%s) update", new.ID.ValueString()), err.Error()) return } + + // Update only the computed attributes, preserve the order of resources from configuration + new.MonitorStatus = types.StringValue(string(monitor.MonitorStatus)) + + // Ensure ID and ARN are set properly + if new.ID.IsNull() || new.ID.IsUnknown() { + new.ID = types.StringValue(aws.ToString(monitor.MonitorArn)) + } + if new.ARN.IsNull() || new.ARN.IsUnknown() { + new.ARN = types.StringValue(aws.ToString(monitor.MonitorArn)) + } } response.Diagnostics.Append(response.State.Set(ctx, &new)...) @@ -262,6 +413,30 @@ func (r *monitorResource) Delete(ctx context.Context, request resource.DeleteReq } } +func (r *monitorResource) ImportState(ctx context.Context, request resource.ImportStateRequest, response *resource.ImportStateResponse) { + // The import ID can be either an ARN or a monitor name + id := request.ID + + // If it's an ARN, extract the monitor name + if strings.HasPrefix(id, "arn:aws:networkflowmonitor:") { + // ARN format: arn:aws:networkflowmonitor:region:account:monitor/monitor-name + parts := strings.Split(id, "/") + if len(parts) != 2 { + response.Diagnostics.AddError("Invalid import ID", fmt.Sprintf("Expected ARN format 'arn:aws:networkflowmonitor:region:account:monitor/monitor-name', got: %s", id)) + return + } + monitorName := parts[1] + + // Set both ID (ARN) and monitor_name + response.Diagnostics.Append(response.State.SetAttribute(ctx, path.Root("id"), id)...) + response.Diagnostics.Append(response.State.SetAttribute(ctx, path.Root("monitor_name"), monitorName)...) + } else { + // Assume it's a monitor name, we'll need to construct the ARN during read + response.Diagnostics.Append(response.State.SetAttribute(ctx, path.Root("monitor_name"), id)...) + // ID will be set during the subsequent Read operation + } +} + func findMonitorByName(ctx context.Context, conn *networkflowmonitor.Client, name string) (*networkflowmonitor.GetMonitorOutput, error) { input := &networkflowmonitor.GetMonitorInput{ MonitorName: aws.String(name), @@ -320,6 +495,23 @@ func waitMonitorCreated(ctx context.Context, conn *networkflowmonitor.Client, na return nil, err } +func waitMonitorUpdated(ctx context.Context, conn *networkflowmonitor.Client, name string, timeout time.Duration) (*networkflowmonitor.GetMonitorOutput, error) { + stateConf := &retry.StateChangeConf{ + Pending: enum.Slice(awstypes.MonitorStatusPending), + Target: enum.Slice(awstypes.MonitorStatusActive), + Refresh: statusMonitor(ctx, conn, name), + Timeout: timeout, + } + + outputRaw, err := stateConf.WaitForStateContext(ctx) + + if output, ok := outputRaw.(*networkflowmonitor.GetMonitorOutput); ok { + return output, err + } + + return nil, err +} + func waitMonitorDeleted(ctx context.Context, conn *networkflowmonitor.Client, name string, timeout time.Duration) (*networkflowmonitor.GetMonitorOutput, error) { stateConf := &retry.StateChangeConf{ Pending: enum.Slice(awstypes.MonitorStatusDeleting), diff --git a/internal/service/networkflowmonitor/monitor_test.go b/internal/service/networkflowmonitor/monitor_test.go index 8444c49b945b..2afd281b4f6c 100644 --- a/internal/service/networkflowmonitor/monitor_test.go +++ b/internal/service/networkflowmonitor/monitor_test.go @@ -45,9 +45,10 @@ func TestAccNetworkFlowMonitorMonitor_basic(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"scope_arn"}, }, }, }) @@ -104,9 +105,10 @@ func TestAccNetworkFlowMonitorMonitor_tags(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"scope_arn"}, }, { Config: testAccMonitorConfig_tags2(rName, "key1", "value1updated", "key2", "value2"), @@ -129,6 +131,75 @@ func TestAccNetworkFlowMonitorMonitor_tags(t *testing.T) { }) } +func TestAccNetworkFlowMonitorMonitor_update(t *testing.T) { + ctx := acctest.Context(t) + var monitor networkflowmonitor.GetMonitorOutput + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_networkflowmonitor_monitor.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + testAccPreCheck(ctx, t) + }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckMonitorDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccMonitorConfig_basic(rName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName, &monitor), + resource.TestCheckResourceAttr(resourceName, "monitor_name", rName), + resource.TestCheckResourceAttr(resourceName, "local_resources.0.type", "AWS::EC2::VPC"), + ), + }, + //adding one more local resource to monitor + { + Config: testAccMonitorConfig_updated1(rName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName, &monitor), + resource.TestCheckResourceAttr(resourceName, "monitor_name", rName), + resource.TestCheckResourceAttr(resourceName, "local_resources.#", "2"), + resource.TestCheckResourceAttr(resourceName, "remote_resources.#", "1"), + ), + }, + //reverting local resources to single resource. + { + Config: testAccMonitorConfig_basic(rName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName, &monitor), + resource.TestCheckResourceAttr(resourceName, "monitor_name", rName), + resource.TestCheckResourceAttr(resourceName, "local_resources.#", "1"), + resource.TestCheckResourceAttr(resourceName, "remote_resources.#", "1"), + resource.TestCheckResourceAttr(resourceName, "local_resources.0.type", "AWS::EC2::VPC"), + ), + }, + //adding 2 local resources and 2 remote resources + { + Config: testAccMonitorConfig_updated2(rName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName, &monitor), + resource.TestCheckResourceAttr(resourceName, "monitor_name", rName), + resource.TestCheckResourceAttr(resourceName, "local_resources.#", "2"), + resource.TestCheckResourceAttr(resourceName, "remote_resources.#", "2"), + ), + }, + //reverting local resources to single resource. + { + Config: testAccMonitorConfig_basic(rName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName, &monitor), + resource.TestCheckResourceAttr(resourceName, "monitor_name", rName), + resource.TestCheckResourceAttr(resourceName, "local_resources.#", "1"), + resource.TestCheckResourceAttr(resourceName, "remote_resources.#", "1"), + resource.TestCheckResourceAttr(resourceName, "local_resources.0.type", "AWS::EC2::VPC"), + ), + }, + }, + }) +} + func testAccCheckMonitorExists(ctx context.Context, n string, v *networkflowmonitor.GetMonitorOutput) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -188,7 +259,7 @@ resource "aws_vpc" "test" { resource "aws_networkflowmonitor_monitor" "test" { monitor_name = %[1]q - scope_arn = "arn:aws:networkflowmonitor:us-east-1:123456789012:scope/test-scope" + scope_arn = "arn:aws:networkflowmonitor:us-east-1:664418989480:scope/cd8df3fd-8ffa-4bfa-bdce-8bb1afaa0f83" local_resources { type = "AWS::EC2::VPC" @@ -215,7 +286,7 @@ resource "aws_vpc" "test" { resource "aws_networkflowmonitor_monitor" "test" { monitor_name = %[1]q - scope_arn = "arn:aws:networkflowmonitor:us-east-1:123456789012:scope/test-scope" + scope_arn = "arn:aws:networkflowmonitor:us-east-1:664418989480:scope/cd8df3fd-8ffa-4bfa-bdce-8bb1afaa0f83" local_resources { type = "AWS::EC2::VPC" @@ -246,7 +317,7 @@ resource "aws_vpc" "test" { resource "aws_networkflowmonitor_monitor" "test" { monitor_name = %[1]q - scope_arn = "arn:aws:networkflowmonitor:us-east-1:123456789012:scope/test-scope" + scope_arn = "arn:aws:networkflowmonitor:us-east-1:664418989480:scope/cd8df3fd-8ffa-4bfa-bdce-8bb1afaa0f83" local_resources { type = "AWS::EC2::VPC" @@ -265,6 +336,94 @@ resource "aws_networkflowmonitor_monitor" "test" { } `, rName, tagKey1, tagValue1, tagKey2, tagValue2) } + +func testAccMonitorConfig_updated1(rName string) string { + return fmt.Sprintf(` +resource "aws_vpc" "test" { + cidr_block = "10.0.0.0/16" + + tags = { + Name = %[1]q + } +} + +resource "aws_subnet" "test" { + vpc_id = aws_vpc.test.id + cidr_block = "10.0.1.0/24" + + tags = { + Name = %[1]q + } +} + +resource "aws_networkflowmonitor_monitor" "test" { + monitor_name = %[1]q + scope_arn = "arn:aws:networkflowmonitor:us-east-1:664418989480:scope/cd8df3fd-8ffa-4bfa-bdce-8bb1afaa0f83" + + local_resources { + type = "AWS::EC2::VPC" + identifier = aws_vpc.test.arn + } + + local_resources { + type = "AWS::EC2::Subnet" + identifier = aws_subnet.test.arn + } + + remote_resources { + type = "AWS::EC2::VPC" + identifier = aws_vpc.test.arn + } +} +`, rName) +} + +func testAccMonitorConfig_updated2(rName string) string { + return fmt.Sprintf(` +resource "aws_vpc" "test" { + cidr_block = "10.0.0.0/16" + + tags = { + Name = %[1]q + } +} + +resource "aws_subnet" "test" { + vpc_id = aws_vpc.test.id + cidr_block = "10.0.1.0/24" + + tags = { + Name = %[1]q + } +} + +resource "aws_networkflowmonitor_monitor" "test" { + monitor_name = %[1]q + scope_arn = "arn:aws:networkflowmonitor:us-east-1:664418989480:scope/cd8df3fd-8ffa-4bfa-bdce-8bb1afaa0f83" + + local_resources { + type = "AWS::EC2::VPC" + identifier = aws_vpc.test.arn + } + + local_resources { + type = "AWS::EC2::Subnet" + identifier = aws_subnet.test.arn + } + + remote_resources { + type = "AWS::EC2::VPC" + identifier = aws_vpc.test.arn + } + + remote_resources { + type = "AWS::EC2::Subnet" + identifier = aws_subnet.test.arn + } +} +`, rName) +} + func testAccPreCheck(ctx context.Context, t *testing.T) { conn := acctest.Provider.Meta().(*conns.AWSClient).NetworkFlowMonitorClient(ctx) diff --git a/internal/service/networkflowmonitor/scope.go b/internal/service/networkflowmonitor/scope.go index f3dcb391f1ad..7f66323fd10e 100644 --- a/internal/service/networkflowmonitor/scope.go +++ b/internal/service/networkflowmonitor/scope.go @@ -6,6 +6,7 @@ package networkflowmonitor import ( "context" "fmt" + "strings" "time" "github.com/aws/aws-sdk-go-v2/aws" @@ -14,6 +15,8 @@ import ( "github.com/google/uuid" "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" + "github.com/hashicorp/terraform-plugin-framework/diag" + "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/schema/validator" @@ -23,7 +26,6 @@ import ( "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" @@ -45,7 +47,6 @@ func newScopeResource(_ context.Context) (resource.ResourceWithConfigure, error) type scopeResource struct { framework.ResourceWithConfigure framework.ResourceWithModel[scopeResourceModel] - framework.WithImportByID framework.WithTimeouts } @@ -139,14 +140,10 @@ func (r *scopeResource) Create(ctx context.Context, request resource.CreateReque conn := r.Meta().NetworkFlowMonitorClient(ctx) - // MANDATORY: Use fwflex.Expand for automatic parameter mapping + // Manual parameter mapping (AutoFlex can't handle union types) input := &networkflowmonitor.CreateScopeInput{} - response.Diagnostics.Append(fwflex.Expand(ctx, data, input)...) - if response.Diagnostics.HasError() { - return - } - // Handle union types that fwflex can't handle automatically + // Map targets manually since they contain union types if !data.Targets.IsNull() && !data.Targets.IsUnknown() { targets, diags := data.Targets.ToSlice(ctx) response.Diagnostics.Append(diags...) @@ -188,7 +185,7 @@ func (r *scopeResource) Create(ctx context.Context, request resource.CreateReque return } - // Set ID and computed attributes + // Set ID and computed attributes from create output data.ID = types.StringValue(aws.ToString(output.ScopeArn)) data.ARN = types.StringValue(aws.ToString(output.ScopeArn)) @@ -199,10 +196,54 @@ func (r *scopeResource) Create(ctx context.Context, request resource.CreateReque return } - // Set computed attributes + // Set all attributes from final scope state manually data.ScopeId = types.StringValue(aws.ToString(scope.ScopeId)) data.Status = types.StringValue(string(scope.Status)) + // Handle targets with union types manually + if len(scope.Targets) > 0 { + targetModels := make([]targetResourceModel, len(scope.Targets)) + for i, target := range scope.Targets { + targetModels[i].Region = types.StringValue(aws.ToString(target.Region)) + + if target.TargetIdentifier != nil { + var targetIdValue string + if accountId, ok := target.TargetIdentifier.TargetId.(*awstypes.TargetIdMemberAccountId); ok { + targetIdValue = accountId.Value + } + + targetIdModel := targetIdentifierModel{ + TargetId: types.StringValue(targetIdValue), + TargetType: types.StringValue(string(target.TargetIdentifier.TargetType)), + } + + targetIdentifierList, diags := fwtypes.NewListNestedObjectValueOfValueSlice(ctx, []targetIdentifierModel{targetIdModel}) + response.Diagnostics.Append(diags...) + if response.Diagnostics.HasError() { + return + } + targetModels[i].TargetIdentifier = targetIdentifierList + } + } + + targetsList, diags := fwtypes.NewListNestedObjectValueOfValueSlice(ctx, targetModels) + response.Diagnostics.Append(diags...) + if response.Diagnostics.HasError() { + return + } + data.Targets = targetsList + } + + // Set tags - preserve the original plan's tags state + // If tags were null in the plan, keep them null in the state + if !data.Tags.IsNull() { + tags := tftags.New(ctx, scope.Tags) + data.Tags = tftags.FlattenStringValueMap(ctx, tags.Map()) + } + // TagsAll should always reflect the actual AWS state + tags := tftags.New(ctx, scope.Tags) + data.TagsAll = tftags.FlattenStringValueMap(ctx, tags.Map()) + response.Diagnostics.Append(response.State.Set(ctx, data)...) } @@ -228,13 +269,14 @@ func (r *scopeResource) Read(ctx context.Context, request resource.ReadRequest, return } - // MANDATORY: Use fwflex.Flatten for automatic parameter mapping - response.Diagnostics.Append(fwflex.Flatten(ctx, output, &data)...) - if response.Diagnostics.HasError() { - return - } + // Manual parameter mapping (AutoFlex can't handle union types) + // Set basic attributes + data.ID = types.StringValue(aws.ToString(output.ScopeArn)) + data.ARN = types.StringValue(aws.ToString(output.ScopeArn)) + data.ScopeId = types.StringValue(aws.ToString(output.ScopeId)) + data.Status = types.StringValue(string(output.Status)) - // Handle union types that fwflex can't handle automatically + // Handle targets with union types manually if len(output.Targets) > 0 { targetModels := make([]targetResourceModel, len(output.Targets)) for i, target := range output.Targets { @@ -268,8 +310,17 @@ func (r *scopeResource) Read(ctx context.Context, request resource.ReadRequest, data.Targets = targetsList } - // Set tags from API response - setTagsOut(ctx, output.Tags) + // Set tags - only set if there are actual tags, otherwise keep null + if len(output.Tags) > 0 { + tags := tftags.New(ctx, output.Tags) + data.Tags = tftags.FlattenStringValueMap(ctx, tags.Map()) + data.TagsAll = tftags.FlattenStringValueMap(ctx, tags.Map()) + } else { + // Keep tags null if no tags were originally set and none exist in AWS + // TagsAll should always reflect AWS state (empty map when no tags) + tags := tftags.New(ctx, output.Tags) + data.TagsAll = tftags.FlattenStringValueMap(ctx, tags.Map()) + } response.Diagnostics.Append(response.State.Set(ctx, &data)...) } @@ -287,6 +338,38 @@ func (r *scopeResource) Update(ctx context.Context, request resource.UpdateReque conn := r.Meta().NetworkFlowMonitorClient(ctx) + // Handle targets updates + if !new.Targets.Equal(old.Targets) { + // Calculate targets to add and remove + resourcesToAdd, resourcesToDelete, diags := r.calculateTargetChanges(ctx, old.Targets, new.Targets) + response.Diagnostics.Append(diags...) + if response.Diagnostics.HasError() { + return + } + + // Update scope targets if there are changes + if len(resourcesToAdd) > 0 || len(resourcesToDelete) > 0 { + input := &networkflowmonitor.UpdateScopeInput{ + ScopeId: aws.String(old.ScopeId.ValueString()), + ResourcesToAdd: resourcesToAdd, + ResourcesToDelete: resourcesToDelete, + } + + _, err := conn.UpdateScope(ctx, input) + if err != nil { + response.Diagnostics.AddError(fmt.Sprintf("updating Network Flow Monitor Scope (%s) targets", new.ID.ValueString()), err.Error()) + return + } + + // Wait for scope to be updated + _, err = waitScopeUpdated(ctx, conn, old.ScopeId.ValueString(), r.UpdateTimeout(ctx, new.Timeouts)) + if err != nil { + response.Diagnostics.AddError(fmt.Sprintf("waiting for Network Flow Monitor Scope (%s) update", new.ID.ValueString()), err.Error()) + return + } + } + } + // Handle tag updates if !new.Tags.Equal(old.Tags) { if err := updateTags(ctx, conn, new.ID.ValueString(), old.Tags, new.Tags); err != nil { @@ -295,9 +378,166 @@ func (r *scopeResource) Update(ctx context.Context, request resource.UpdateReque } } + // After updating, read the current state from AWS to get all computed values + output, err := findScopeByID(ctx, conn, old.ScopeId.ValueString()) + if err != nil { + response.Diagnostics.AddError(fmt.Sprintf("reading Network Flow Monitor Scope (%s) after update", new.ID.ValueString()), err.Error()) + return + } + + // Update the new model with current AWS state + new.ScopeId = types.StringValue(aws.ToString(output.ScopeId)) + new.Status = types.StringValue(string(output.Status)) + + // Map targets manually from AWS response + if len(output.Targets) > 0 { + targetModels := make([]targetResourceModel, len(output.Targets)) + for i, target := range output.Targets { + targetModels[i].Region = types.StringValue(aws.ToString(target.Region)) + + if target.TargetIdentifier != nil { + var targetIdValue string + if accountId, ok := target.TargetIdentifier.TargetId.(*awstypes.TargetIdMemberAccountId); ok { + targetIdValue = accountId.Value + } + + targetIdModel := targetIdentifierModel{ + TargetId: types.StringValue(targetIdValue), + TargetType: types.StringValue(string(target.TargetIdentifier.TargetType)), + } + + targetIdentifierList, diags := fwtypes.NewListNestedObjectValueOfValueSlice(ctx, []targetIdentifierModel{targetIdModel}) + response.Diagnostics.Append(diags...) + if response.Diagnostics.HasError() { + return + } + targetModels[i].TargetIdentifier = targetIdentifierList + } + } + + targetsList, diags := fwtypes.NewListNestedObjectValueOfValueSlice(ctx, targetModels) + response.Diagnostics.Append(diags...) + if response.Diagnostics.HasError() { + return + } + new.Targets = targetsList + } + + // Set tags based on the updated AWS state + if !new.Tags.IsNull() && len(output.Tags) > 0 { + tags := tftags.New(ctx, output.Tags) + new.Tags = tftags.FlattenStringValueMap(ctx, tags.Map()) + } + // TagsAll should always reflect AWS state + tags := tftags.New(ctx, output.Tags) + new.TagsAll = tftags.FlattenStringValueMap(ctx, tags.Map()) + response.Diagnostics.Append(response.State.Set(ctx, &new)...) } +func (r *scopeResource) calculateTargetChanges(ctx context.Context, oldTargets, newTargets fwtypes.ListNestedObjectValueOf[targetResourceModel]) ([]awstypes.TargetResource, []awstypes.TargetResource, diag.Diagnostics) { + var diags diag.Diagnostics + var resourcesToAdd, resourcesToDelete []awstypes.TargetResource + + // Convert old targets to map for easy lookup + oldTargetsMap := make(map[string]awstypes.TargetResource) + if !oldTargets.IsNull() && !oldTargets.IsUnknown() { + oldTargetsList, d := oldTargets.ToSlice(ctx) + diags.Append(d...) + if diags.HasError() { + return nil, nil, diags + } + + for _, target := range oldTargetsList { + awsTarget := awstypes.TargetResource{ + Region: aws.String(target.Region.ValueString()), + } + + // Handle union type for TargetIdentifier + if !target.TargetIdentifier.IsNull() && !target.TargetIdentifier.IsUnknown() { + identifiers, d := target.TargetIdentifier.ToSlice(ctx) + diags.Append(d...) + if diags.HasError() { + return nil, nil, diags + } + + if len(identifiers) > 0 { + identifier := identifiers[0] + awsTarget.TargetIdentifier = &awstypes.TargetIdentifier{ + TargetId: &awstypes.TargetIdMemberAccountId{ + Value: identifier.TargetId.ValueString(), + }, + TargetType: awstypes.TargetType(identifier.TargetType.ValueString()), + } + + // Create a key for the target (region + target_id + target_type) + key := fmt.Sprintf("%s:%s:%s", + target.Region.ValueString(), + identifier.TargetId.ValueString(), + identifier.TargetType.ValueString()) + oldTargetsMap[key] = awsTarget + } + } + } + } + + // Convert new targets to map and identify additions + newTargetsMap := make(map[string]awstypes.TargetResource) + if !newTargets.IsNull() && !newTargets.IsUnknown() { + newTargetsList, d := newTargets.ToSlice(ctx) + diags.Append(d...) + if diags.HasError() { + return nil, nil, diags + } + + for _, target := range newTargetsList { + awsTarget := awstypes.TargetResource{ + Region: aws.String(target.Region.ValueString()), + } + + // Handle union type for TargetIdentifier + if !target.TargetIdentifier.IsNull() && !target.TargetIdentifier.IsUnknown() { + identifiers, d := target.TargetIdentifier.ToSlice(ctx) + diags.Append(d...) + if diags.HasError() { + return nil, nil, diags + } + + if len(identifiers) > 0 { + identifier := identifiers[0] + awsTarget.TargetIdentifier = &awstypes.TargetIdentifier{ + TargetId: &awstypes.TargetIdMemberAccountId{ + Value: identifier.TargetId.ValueString(), + }, + TargetType: awstypes.TargetType(identifier.TargetType.ValueString()), + } + + // Create a key for the target + key := fmt.Sprintf("%s:%s:%s", + target.Region.ValueString(), + identifier.TargetId.ValueString(), + identifier.TargetType.ValueString()) + newTargetsMap[key] = awsTarget + + // If this target doesn't exist in old targets, it's an addition + if _, exists := oldTargetsMap[key]; !exists { + resourcesToAdd = append(resourcesToAdd, awsTarget) + } + } + } + } + } + + // Identify deletions + for key, target := range oldTargetsMap { + if _, exists := newTargetsMap[key]; !exists { + resourcesToDelete = append(resourcesToDelete, target) + } + } + + return resourcesToAdd, resourcesToDelete, diags +} + func (r *scopeResource) Delete(ctx context.Context, request resource.DeleteRequest, response *resource.DeleteResponse) { var data scopeResourceModel response.Diagnostics.Append(request.State.Get(ctx, &data)...) @@ -326,6 +566,30 @@ func (r *scopeResource) Delete(ctx context.Context, request resource.DeleteReque } } +func (r *scopeResource) ImportState(ctx context.Context, request resource.ImportStateRequest, response *resource.ImportStateResponse) { + // The import ID can be either an ARN or a scope ID + id := request.ID + + // If it's an ARN, extract the scope ID + if strings.HasPrefix(id, "arn:aws:networkflowmonitor:") { + // ARN format: arn:aws:networkflowmonitor:region:account:scope/scope-id + parts := strings.Split(id, "/") + if len(parts) != 2 { + response.Diagnostics.AddError("Invalid import ID", fmt.Sprintf("Expected ARN format 'arn:aws:networkflowmonitor:region:account:scope/scope-id', got: %s", id)) + return + } + scopeId := parts[1] + + // Set both ID (ARN) and scope_id + response.Diagnostics.Append(response.State.SetAttribute(ctx, path.Root("id"), id)...) + response.Diagnostics.Append(response.State.SetAttribute(ctx, path.Root("scope_id"), scopeId)...) + } else { + // Assume it's a scope ID, we'll need to construct the ARN during read + response.Diagnostics.Append(response.State.SetAttribute(ctx, path.Root("scope_id"), id)...) + // ID will be set during the subsequent Read operation + } +} + func findScopeByID(ctx context.Context, conn *networkflowmonitor.Client, id string) (*networkflowmonitor.GetScopeOutput, error) { input := &networkflowmonitor.GetScopeInput{ ScopeId: aws.String(id), @@ -384,6 +648,23 @@ func waitScopeCreated(ctx context.Context, conn *networkflowmonitor.Client, id s return nil, err } +func waitScopeUpdated(ctx context.Context, conn *networkflowmonitor.Client, id string, timeout time.Duration) (*networkflowmonitor.GetScopeOutput, error) { + stateConf := &retry.StateChangeConf{ + Pending: enum.Slice(awstypes.ScopeStatusInProgress), + Target: enum.Slice(awstypes.ScopeStatusSucceeded), + Refresh: statusScope(ctx, conn, id), + Timeout: timeout, + } + + outputRaw, err := stateConf.WaitForStateContext(ctx) + + if output, ok := outputRaw.(*networkflowmonitor.GetScopeOutput); ok { + return output, err + } + + return nil, err +} + func waitScopeDeleted(ctx context.Context, conn *networkflowmonitor.Client, id string, timeout time.Duration) (*networkflowmonitor.GetScopeOutput, error) { stateConf := &retry.StateChangeConf{ Pending: enum.Slice(awstypes.ScopeStatusDeactivating), diff --git a/internal/service/networkflowmonitor/scope_test.go b/internal/service/networkflowmonitor/scope_test.go index c4ff96d31f5c..a9f663cf12d9 100644 --- a/internal/service/networkflowmonitor/scope_test.go +++ b/internal/service/networkflowmonitor/scope_test.go @@ -19,12 +19,26 @@ import ( "github.com/hashicorp/terraform-provider-aws/names" ) -func TestAccNetworkFlowMonitorScope_basic(t *testing.T) { +func TestAccNetworkFlowMonitorScope_serial(t *testing.T) { + t.Parallel() + + testCases := map[string]map[string]func(t *testing.T){ + "Scope": { + acctest.CtBasic: testAccNetworkFlowMonitorScope_basic, + acctest.CtDisappears: testAccNetworkFlowMonitorScope_disappears, + "tags": testAccNetworkFlowMonitorScope_tags, + }, + } + + acctest.RunSerialTests2Levels(t, testCases, 0) +} + +func testAccNetworkFlowMonitorScope_basic(t *testing.T) { ctx := acctest.Context(t) var scope networkflowmonitor.GetScopeOutput resourceName := "aws_networkflowmonitor_scope.test" - resource.ParallelTest(t, resource.TestCase{ + resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) testAccPreCheck(ctx, t) @@ -51,12 +65,12 @@ func TestAccNetworkFlowMonitorScope_basic(t *testing.T) { }) } -func TestAccNetworkFlowMonitorScope_disappears(t *testing.T) { +func testAccNetworkFlowMonitorScope_disappears(t *testing.T) { ctx := acctest.Context(t) var scope networkflowmonitor.GetScopeOutput resourceName := "aws_networkflowmonitor_scope.test" - resource.ParallelTest(t, resource.TestCase{ + resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) testAccPreCheck(ctx, t) @@ -77,12 +91,12 @@ func TestAccNetworkFlowMonitorScope_disappears(t *testing.T) { }) } -func TestAccNetworkFlowMonitorScope_tags(t *testing.T) { +func testAccNetworkFlowMonitorScope_tags(t *testing.T) { ctx := acctest.Context(t) var scope networkflowmonitor.GetScopeOutput resourceName := "aws_networkflowmonitor_scope.test" - resource.ParallelTest(t, resource.TestCase{ + resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) testAccPreCheck(ctx, t) diff --git a/internal/service/networkflowmonitor/service_package_gen.go b/internal/service/networkflowmonitor/service_package_gen.go index c695ee9bf032..9bec180a0deb 100644 --- a/internal/service/networkflowmonitor/service_package_gen.go +++ b/internal/service/networkflowmonitor/service_package_gen.go @@ -4,6 +4,7 @@ package networkflowmonitor import ( "context" + "unique" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/networkflowmonitor" @@ -26,11 +27,17 @@ func (p *servicePackage) FrameworkResources(ctx context.Context) []*inttypes.Ser Factory: newMonitorResource, TypeName: "aws_networkflowmonitor_monitor", Name: "Monitor", + Tags: unique.Make(inttypes.ServicePackageResourceTags{ + IdentifierAttribute: names.AttrARN, + }), }, { Factory: newScopeResource, TypeName: "aws_networkflowmonitor_scope", Name: "Scope", + Tags: unique.Make(inttypes.ServicePackageResourceTags{ + IdentifierAttribute: names.AttrARN, + }), }, } } diff --git a/website/docs/r/networkflowmonitor_scope.html.markdown b/website/docs/r/networkflowmonitor_scope.html.markdown index 54d817162dad..b6b0b89cdb03 100644 --- a/website/docs/r/networkflowmonitor_scope.html.markdown +++ b/website/docs/r/networkflowmonitor_scope.html.markdown @@ -32,33 +32,6 @@ resource "aws_networkflowmonitor_scope" "example" { } ``` -### Multiple Targets - -```terraform -data "aws_caller_identity" "current" {} - -resource "aws_networkflowmonitor_scope" "example" { - targets { - region = "us-east-1" - target_identifier { - target_id = data.aws_caller_identity.current.account_id - target_type = "ACCOUNT" - } - } - - targets { - region = "us-west-2" - target_identifier { - target_id = data.aws_caller_identity.current.account_id - target_type = "ACCOUNT" - } - } - - tags = { - Name = "example" - } -} -``` ## Argument Reference From fe791421e33df35af807ec852227a83fe64b4357 Mon Sep 17 00:00:00 2001 From: Sasi Date: Thu, 23 Oct 2025 15:10:15 -0400 Subject: [PATCH 03/21] added changelog --- .changelog/44782.txt | 7 ++ .../networkflowmonitor/monitor_test.go | 101 +++++++++++++++--- 2 files changed, 95 insertions(+), 13 deletions(-) create mode 100644 .changelog/44782.txt diff --git a/.changelog/44782.txt b/.changelog/44782.txt new file mode 100644 index 000000000000..9095a9c704ff --- /dev/null +++ b/.changelog/44782.txt @@ -0,0 +1,7 @@ +```release-note:new-resource +aws_networkflowmonitor_monitor +``` + +```release-note:new-resource +aws_networkflowmonitor_scope +``` \ No newline at end of file diff --git a/internal/service/networkflowmonitor/monitor_test.go b/internal/service/networkflowmonitor/monitor_test.go index 2afd281b4f6c..a6bdd11043c2 100644 --- a/internal/service/networkflowmonitor/monitor_test.go +++ b/internal/service/networkflowmonitor/monitor_test.go @@ -20,13 +20,28 @@ import ( "github.com/hashicorp/terraform-provider-aws/names" ) -func TestAccNetworkFlowMonitorMonitor_basic(t *testing.T) { +func TestAccNetworkFlowMonitorMonitor_serial(t *testing.T) { + t.Parallel() + + testCases := map[string]map[string]func(t *testing.T){ + "Monitor": { + acctest.CtBasic: testAccNetworkFlowMonitorMonitor_basic, + acctest.CtDisappears: testAccNetworkFlowMonitorMonitor_disappears, + "tags": testAccNetworkFlowMonitorMonitor_tags, + "update": testAccNetworkFlowMonitorMonitor_update, + }, + } + + acctest.RunSerialTests2Levels(t, testCases, 0) +} + +func testAccNetworkFlowMonitorMonitor_basic(t *testing.T) { ctx := acctest.Context(t) var monitor networkflowmonitor.GetMonitorOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_networkflowmonitor_monitor.test" - resource.ParallelTest(t, resource.TestCase{ + resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) testAccPreCheck(ctx, t) @@ -54,13 +69,13 @@ func TestAccNetworkFlowMonitorMonitor_basic(t *testing.T) { }) } -func TestAccNetworkFlowMonitorMonitor_disappears(t *testing.T) { +func testAccNetworkFlowMonitorMonitor_disappears(t *testing.T) { ctx := acctest.Context(t) var monitor networkflowmonitor.GetMonitorOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_networkflowmonitor_monitor.test" - resource.ParallelTest(t, resource.TestCase{ + resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) testAccPreCheck(ctx, t) @@ -81,13 +96,13 @@ func TestAccNetworkFlowMonitorMonitor_disappears(t *testing.T) { }) } -func TestAccNetworkFlowMonitorMonitor_tags(t *testing.T) { +func testAccNetworkFlowMonitorMonitor_tags(t *testing.T) { ctx := acctest.Context(t) var monitor networkflowmonitor.GetMonitorOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_networkflowmonitor_monitor.test" - resource.ParallelTest(t, resource.TestCase{ + resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) testAccPreCheck(ctx, t) @@ -131,13 +146,13 @@ func TestAccNetworkFlowMonitorMonitor_tags(t *testing.T) { }) } -func TestAccNetworkFlowMonitorMonitor_update(t *testing.T) { +func testAccNetworkFlowMonitorMonitor_update(t *testing.T) { ctx := acctest.Context(t) var monitor networkflowmonitor.GetMonitorOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_networkflowmonitor_monitor.test" - resource.ParallelTest(t, resource.TestCase{ + resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) testAccPreCheck(ctx, t) @@ -249,6 +264,8 @@ func testAccCheckMonitorDestroy(ctx context.Context) resource.TestCheckFunc { func testAccMonitorConfig_basic(rName string) string { return fmt.Sprintf(` +data "aws_caller_identity" "current" {} + resource "aws_vpc" "test" { cidr_block = "10.0.0.0/16" @@ -257,9 +274,19 @@ resource "aws_vpc" "test" { } } +resource "aws_networkflowmonitor_scope" "test" { + targets { + region = "us-east-1" + target_identifier { + target_id = data.aws_caller_identity.current.account_id + target_type = "ACCOUNT" + } + } +} + resource "aws_networkflowmonitor_monitor" "test" { monitor_name = %[1]q - scope_arn = "arn:aws:networkflowmonitor:us-east-1:664418989480:scope/cd8df3fd-8ffa-4bfa-bdce-8bb1afaa0f83" + scope_arn = aws_networkflowmonitor_scope.test.arn local_resources { type = "AWS::EC2::VPC" @@ -276,6 +303,8 @@ resource "aws_networkflowmonitor_monitor" "test" { func testAccMonitorConfig_tags1(rName, tagKey1, tagValue1 string) string { return fmt.Sprintf(` +data "aws_caller_identity" "current" {} + resource "aws_vpc" "test" { cidr_block = "10.0.0.0/16" @@ -284,9 +313,19 @@ resource "aws_vpc" "test" { } } +resource "aws_networkflowmonitor_scope" "test" { + targets { + region = "us-east-1" + target_identifier { + target_id = data.aws_caller_identity.current.account_id + target_type = "ACCOUNT" + } + } +} + resource "aws_networkflowmonitor_monitor" "test" { monitor_name = %[1]q - scope_arn = "arn:aws:networkflowmonitor:us-east-1:664418989480:scope/cd8df3fd-8ffa-4bfa-bdce-8bb1afaa0f83" + scope_arn = aws_networkflowmonitor_scope.test.arn local_resources { type = "AWS::EC2::VPC" @@ -307,6 +346,8 @@ resource "aws_networkflowmonitor_monitor" "test" { func testAccMonitorConfig_tags2(rName, tagKey1, tagValue1, tagKey2, tagValue2 string) string { return fmt.Sprintf(` +data "aws_caller_identity" "current" {} + resource "aws_vpc" "test" { cidr_block = "10.0.0.0/16" @@ -315,9 +356,19 @@ resource "aws_vpc" "test" { } } +resource "aws_networkflowmonitor_scope" "test" { + targets { + region = "us-east-1" + target_identifier { + target_id = data.aws_caller_identity.current.account_id + target_type = "ACCOUNT" + } + } +} + resource "aws_networkflowmonitor_monitor" "test" { monitor_name = %[1]q - scope_arn = "arn:aws:networkflowmonitor:us-east-1:664418989480:scope/cd8df3fd-8ffa-4bfa-bdce-8bb1afaa0f83" + scope_arn = aws_networkflowmonitor_scope.test.arn local_resources { type = "AWS::EC2::VPC" @@ -339,6 +390,8 @@ resource "aws_networkflowmonitor_monitor" "test" { func testAccMonitorConfig_updated1(rName string) string { return fmt.Sprintf(` +data "aws_caller_identity" "current" {} + resource "aws_vpc" "test" { cidr_block = "10.0.0.0/16" @@ -356,9 +409,19 @@ resource "aws_subnet" "test" { } } +resource "aws_networkflowmonitor_scope" "test" { + targets { + region = "us-east-1" + target_identifier { + target_id = data.aws_caller_identity.current.account_id + target_type = "ACCOUNT" + } + } +} + resource "aws_networkflowmonitor_monitor" "test" { monitor_name = %[1]q - scope_arn = "arn:aws:networkflowmonitor:us-east-1:664418989480:scope/cd8df3fd-8ffa-4bfa-bdce-8bb1afaa0f83" + scope_arn = aws_networkflowmonitor_scope.test.arn local_resources { type = "AWS::EC2::VPC" @@ -380,6 +443,8 @@ resource "aws_networkflowmonitor_monitor" "test" { func testAccMonitorConfig_updated2(rName string) string { return fmt.Sprintf(` +data "aws_caller_identity" "current" {} + resource "aws_vpc" "test" { cidr_block = "10.0.0.0/16" @@ -397,9 +462,19 @@ resource "aws_subnet" "test" { } } +resource "aws_networkflowmonitor_scope" "test" { + targets { + region = "us-east-1" + target_identifier { + target_id = data.aws_caller_identity.current.account_id + target_type = "ACCOUNT" + } + } +} + resource "aws_networkflowmonitor_monitor" "test" { monitor_name = %[1]q - scope_arn = "arn:aws:networkflowmonitor:us-east-1:664418989480:scope/cd8df3fd-8ffa-4bfa-bdce-8bb1afaa0f83" + scope_arn = aws_networkflowmonitor_scope.test.arn local_resources { type = "AWS::EC2::VPC" From f07723c7ab8bd551d7a5cbfda6073a5bb6e7e97a Mon Sep 17 00:00:00 2001 From: Sasi Date: Wed, 5 Nov 2025 12:22:59 -0500 Subject: [PATCH 04/21] fixed linting and validation checks --- go.mod | 2 +- .../service/networkflowmonitor/monitor.go | 69 +++++++++++-------- .../networkflowmonitor/monitor_test.go | 41 ++++++----- internal/service/networkflowmonitor/scope.go | 57 ++++++++------- .../service/networkflowmonitor/scope_test.go | 31 +++++---- internal/service/networkflowmonitor/sweep.go | 17 ++--- .../networkflowmonitor_monitor.html.markdown | 4 +- .../r/networkflowmonitor_scope.html.markdown | 5 +- 8 files changed, 126 insertions(+), 100 deletions(-) diff --git a/go.mod b/go.mod index 30ad34869c9b..c1e4f5862dd0 100644 --- a/go.mod +++ b/go.mod @@ -280,6 +280,7 @@ require ( github.com/gertd/go-pluralize v0.2.1 github.com/goccy/go-yaml v1.18.0 github.com/google/go-cmp v0.7.0 + github.com/google/uuid v1.6.0 github.com/hashicorp/aws-cloudformation-resource-schema-sdk-go v0.23.0 github.com/hashicorp/aws-sdk-go-base/v2 v2.0.0-beta.67 github.com/hashicorp/awspolicyequivalence v1.7.0 @@ -345,7 +346,6 @@ require ( github.com/go-logr/logr v1.4.3 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/golang/protobuf v1.5.4 // indirect - github.com/google/uuid v1.6.0 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-checkpoint v0.5.0 // indirect github.com/hashicorp/go-plugin v1.7.0 // indirect diff --git a/internal/service/networkflowmonitor/monitor.go b/internal/service/networkflowmonitor/monitor.go index 0dfe1bfe586b..2d201bd870b0 100644 --- a/internal/service/networkflowmonitor/monitor.go +++ b/internal/service/networkflowmonitor/monitor.go @@ -10,6 +10,7 @@ import ( "time" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/networkflowmonitor" awstypes "github.com/aws/aws-sdk-go-v2/service/networkflowmonitor/types" "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" @@ -51,10 +52,6 @@ type monitorResource struct { framework.WithTimeouts } -func (r *monitorResource) Metadata(_ context.Context, request resource.MetadataRequest, response *resource.MetadataResponse) { - response.TypeName = request.ProviderTypeName + "_networkflowmonitor_monitor" -} - func (r *monitorResource) Schema(ctx context.Context, request resource.SchemaRequest, response *resource.SchemaResponse) { response.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ @@ -89,10 +86,10 @@ func (r *monitorResource) Schema(ctx context.Context, request resource.SchemaReq }, NestedObject: schema.NestedBlockObject{ Attributes: map[string]schema.Attribute{ - "type": schema.StringAttribute{ + names.AttrType: schema.StringAttribute{ Required: true, }, - "identifier": schema.StringAttribute{ + names.AttrIdentifier: schema.StringAttribute{ Required: true, }, }, @@ -102,10 +99,10 @@ func (r *monitorResource) Schema(ctx context.Context, request resource.SchemaReq CustomType: fwtypes.NewSetNestedObjectTypeOf[monitorResourceConfigModel](ctx), NestedObject: schema.NestedBlockObject{ Attributes: map[string]schema.Attribute{ - "type": schema.StringAttribute{ + names.AttrType: schema.StringAttribute{ Required: true, }, - "identifier": schema.StringAttribute{ + names.AttrIdentifier: schema.StringAttribute{ Required: true, }, }, @@ -147,8 +144,8 @@ func (r *monitorResource) Create(ctx context.Context, request resource.CreateReq conn := r.Meta().NetworkFlowMonitorClient(ctx) - input := &networkflowmonitor.CreateMonitorInput{} - response.Diagnostics.Append(fwflex.Expand(ctx, data, input)...) + input := networkflowmonitor.CreateMonitorInput{} + response.Diagnostics.Append(fwflex.Expand(ctx, data, &input)...) if response.Diagnostics.HasError() { return } @@ -156,7 +153,7 @@ func (r *monitorResource) Create(ctx context.Context, request resource.CreateReq // Set additional fields that need special handling input.Tags = getTagsIn(ctx) - output, err := conn.CreateMonitor(ctx, input) + output, err := conn.CreateMonitor(ctx, &input) if err != nil { response.Diagnostics.AddError("creating Network Flow Monitor Monitor", err.Error()) @@ -235,8 +232,8 @@ func (r *monitorResource) Update(ctx context.Context, request resource.UpdateReq // Check if local_resources or remote_resources have changed if !new.LocalResources.Equal(old.LocalResources) || !new.RemoteResources.Equal(old.RemoteResources) { - input := &networkflowmonitor.UpdateMonitorInput{ - MonitorName: aws.String(new.MonitorName.ValueString()), + input := networkflowmonitor.UpdateMonitorInput{ + MonitorName: new.MonitorName.ValueStringPointer(), } // Calculate local resources diff @@ -254,7 +251,7 @@ func (r *monitorResource) Update(ctx context.Context, request resource.UpdateReq key := resource.Type.ValueString() + "|" + resource.Identifier.ValueString() oldLocalResources[key] = awstypes.MonitorLocalResource{ Type: awstypes.MonitorLocalResourceType(resource.Type.ValueString()), - Identifier: aws.String(resource.Identifier.ValueString()), + Identifier: resource.Identifier.ValueStringPointer(), } } } @@ -270,7 +267,7 @@ func (r *monitorResource) Update(ctx context.Context, request resource.UpdateReq key := resource.Type.ValueString() + "|" + resource.Identifier.ValueString() newLocalResources[key] = awstypes.MonitorLocalResource{ Type: awstypes.MonitorLocalResourceType(resource.Type.ValueString()), - Identifier: aws.String(resource.Identifier.ValueString()), + Identifier: resource.Identifier.ValueStringPointer(), } } } @@ -306,7 +303,7 @@ func (r *monitorResource) Update(ctx context.Context, request resource.UpdateReq key := resource.Type.ValueString() + "|" + resource.Identifier.ValueString() oldRemoteResources[key] = awstypes.MonitorRemoteResource{ Type: awstypes.MonitorRemoteResourceType(resource.Type.ValueString()), - Identifier: aws.String(resource.Identifier.ValueString()), + Identifier: resource.Identifier.ValueStringPointer(), } } } @@ -322,7 +319,7 @@ func (r *monitorResource) Update(ctx context.Context, request resource.UpdateReq key := resource.Type.ValueString() + "|" + resource.Identifier.ValueString() newRemoteResources[key] = awstypes.MonitorRemoteResource{ Type: awstypes.MonitorRemoteResourceType(resource.Type.ValueString()), - Identifier: aws.String(resource.Identifier.ValueString()), + Identifier: resource.Identifier.ValueStringPointer(), } } } @@ -357,7 +354,7 @@ func (r *monitorResource) Update(ctx context.Context, request resource.UpdateReq input.RemoteResourcesToRemove = remoteResourcesToRemove } - _, err := conn.UpdateMonitor(ctx, input) + _, err := conn.UpdateMonitor(ctx, &input) if err != nil { response.Diagnostics.AddError(fmt.Sprintf("updating Network Flow Monitor Monitor (%s)", new.ID.ValueString()), err.Error()) return @@ -394,9 +391,10 @@ func (r *monitorResource) Delete(ctx context.Context, request resource.DeleteReq conn := r.Meta().NetworkFlowMonitorClient(ctx) - _, err := conn.DeleteMonitor(ctx, &networkflowmonitor.DeleteMonitorInput{ - MonitorName: aws.String(data.MonitorName.ValueString()), - }) + input := networkflowmonitor.DeleteMonitorInput{ + MonitorName: data.MonitorName.ValueStringPointer(), + } + _, err := conn.DeleteMonitor(ctx, &input) if errs.IsA[*awstypes.ResourceNotFoundException](err) { return @@ -418,17 +416,28 @@ func (r *monitorResource) ImportState(ctx context.Context, request resource.Impo id := request.ID // If it's an ARN, extract the monitor name - if strings.HasPrefix(id, "arn:aws:networkflowmonitor:") { - // ARN format: arn:aws:networkflowmonitor:region:account:monitor/monitor-name - parts := strings.Split(id, "/") - if len(parts) != 2 { - response.Diagnostics.AddError("Invalid import ID", fmt.Sprintf("Expected ARN format 'arn:aws:networkflowmonitor:region:account:monitor/monitor-name', got: %s", id)) + if arn.IsARN(id) { + parsedARN, err := arn.Parse(id) + if err != nil { + response.Diagnostics.AddError("Invalid ARN", fmt.Sprintf("Unable to parse ARN (%s): %s", id, err)) + return + } + + if parsedARN.Service != "networkflowmonitor" { + response.Diagnostics.AddError("Invalid ARN", fmt.Sprintf("Expected networkflowmonitor service ARN, got: %s", parsedARN.Service)) + return + } + + // ARN format: arn:partition:networkflowmonitor:region:account:monitor/monitor-name + parts := strings.Split(parsedARN.Resource, "/") + if len(parts) != 2 || parts[0] != "monitor" { + response.Diagnostics.AddError("Invalid import ID", fmt.Sprintf("Expected ARN format 'arn:partition:networkflowmonitor:region:account:monitor/monitor-name', got: %s", id)) return } monitorName := parts[1] // Set both ID (ARN) and monitor_name - response.Diagnostics.Append(response.State.SetAttribute(ctx, path.Root("id"), id)...) + response.Diagnostics.Append(response.State.SetAttribute(ctx, path.Root(names.AttrID), id)...) response.Diagnostics.Append(response.State.SetAttribute(ctx, path.Root("monitor_name"), monitorName)...) } else { // Assume it's a monitor name, we'll need to construct the ARN during read @@ -438,11 +447,11 @@ func (r *monitorResource) ImportState(ctx context.Context, request resource.Impo } func findMonitorByName(ctx context.Context, conn *networkflowmonitor.Client, name string) (*networkflowmonitor.GetMonitorOutput, error) { - input := &networkflowmonitor.GetMonitorInput{ + input := networkflowmonitor.GetMonitorInput{ MonitorName: aws.String(name), } - output, err := conn.GetMonitor(ctx, input) + output, err := conn.GetMonitor(ctx, &input) if errs.IsA[*awstypes.ResourceNotFoundException](err) { return nil, &retry.NotFoundError{ @@ -463,7 +472,7 @@ func findMonitorByName(ctx context.Context, conn *networkflowmonitor.Client, nam } func statusMonitor(ctx context.Context, conn *networkflowmonitor.Client, name string) retry.StateRefreshFunc { - return func() (interface{}, string, error) { + return func() (any, string, error) { output, err := findMonitorByName(ctx, conn, name) if tfresource.NotFound(err) { diff --git a/internal/service/networkflowmonitor/monitor_test.go b/internal/service/networkflowmonitor/monitor_test.go index a6bdd11043c2..1fb1d0188d7f 100644 --- a/internal/service/networkflowmonitor/monitor_test.go +++ b/internal/service/networkflowmonitor/monitor_test.go @@ -55,7 +55,7 @@ func testAccNetworkFlowMonitorMonitor_basic(t *testing.T) { Check: resource.ComposeAggregateTestCheckFunc( testAccCheckMonitorExists(ctx, resourceName, &monitor), resource.TestCheckResourceAttr(resourceName, "monitor_name", rName), - resource.TestCheckResourceAttrSet(resourceName, names.AttrARN), + acctest.CheckResourceAttrRegionalARN(ctx, resourceName, names.AttrARN, "networkflowmonitor", fmt.Sprintf("monitor/%s", rName)), resource.TestCheckResourceAttrSet(resourceName, "monitor_status"), ), }, @@ -112,11 +112,11 @@ func testAccNetworkFlowMonitorMonitor_tags(t *testing.T) { CheckDestroy: testAccCheckMonitorDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccMonitorConfig_tags1(rName, "key1", "value1"), + Config: testAccMonitorConfig_tags1(rName, acctest.CtKey1, acctest.CtValue1), Check: resource.ComposeTestCheckFunc( testAccCheckMonitorExists(ctx, resourceName, &monitor), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1"), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "1"), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey1, acctest.CtValue1), ), }, { @@ -126,20 +126,20 @@ func testAccNetworkFlowMonitorMonitor_tags(t *testing.T) { ImportStateVerifyIgnore: []string{"scope_arn"}, }, { - Config: testAccMonitorConfig_tags2(rName, "key1", "value1updated", "key2", "value2"), + Config: testAccMonitorConfig_tags2(rName, acctest.CtKey1, "value1updated", acctest.CtKey2, acctest.CtValue2), Check: resource.ComposeTestCheckFunc( testAccCheckMonitorExists(ctx, resourceName, &monitor), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1updated"), - resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "2"), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey1, "value1updated"), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey2, acctest.CtValue2), ), }, { - Config: testAccMonitorConfig_tags1(rName, "key2", "value2"), + Config: testAccMonitorConfig_tags1(rName, acctest.CtKey2, acctest.CtValue2), Check: resource.ComposeTestCheckFunc( testAccCheckMonitorExists(ctx, resourceName, &monitor), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "1"), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey2, acctest.CtValue2), ), }, }, @@ -265,6 +265,7 @@ func testAccCheckMonitorDestroy(ctx context.Context) resource.TestCheckFunc { func testAccMonitorConfig_basic(rName string) string { return fmt.Sprintf(` data "aws_caller_identity" "current" {} +data "aws_region" "current" {} resource "aws_vpc" "test" { cidr_block = "10.0.0.0/16" @@ -276,7 +277,7 @@ resource "aws_vpc" "test" { resource "aws_networkflowmonitor_scope" "test" { targets { - region = "us-east-1" + region = data.aws_region.current.name target_identifier { target_id = data.aws_caller_identity.current.account_id target_type = "ACCOUNT" @@ -304,6 +305,7 @@ resource "aws_networkflowmonitor_monitor" "test" { func testAccMonitorConfig_tags1(rName, tagKey1, tagValue1 string) string { return fmt.Sprintf(` data "aws_caller_identity" "current" {} +data "aws_region" "current" {} resource "aws_vpc" "test" { cidr_block = "10.0.0.0/16" @@ -315,7 +317,7 @@ resource "aws_vpc" "test" { resource "aws_networkflowmonitor_scope" "test" { targets { - region = "us-east-1" + region = data.aws_region.current.name target_identifier { target_id = data.aws_caller_identity.current.account_id target_type = "ACCOUNT" @@ -347,6 +349,7 @@ resource "aws_networkflowmonitor_monitor" "test" { func testAccMonitorConfig_tags2(rName, tagKey1, tagValue1, tagKey2, tagValue2 string) string { return fmt.Sprintf(` data "aws_caller_identity" "current" {} +data "aws_region" "current" {} resource "aws_vpc" "test" { cidr_block = "10.0.0.0/16" @@ -358,7 +361,7 @@ resource "aws_vpc" "test" { resource "aws_networkflowmonitor_scope" "test" { targets { - region = "us-east-1" + region = data.aws_region.current.name target_identifier { target_id = data.aws_caller_identity.current.account_id target_type = "ACCOUNT" @@ -391,6 +394,7 @@ resource "aws_networkflowmonitor_monitor" "test" { func testAccMonitorConfig_updated1(rName string) string { return fmt.Sprintf(` data "aws_caller_identity" "current" {} +data "aws_region" "current" {} resource "aws_vpc" "test" { cidr_block = "10.0.0.0/16" @@ -411,7 +415,7 @@ resource "aws_subnet" "test" { resource "aws_networkflowmonitor_scope" "test" { targets { - region = "us-east-1" + region = data.aws_region.current.name target_identifier { target_id = data.aws_caller_identity.current.account_id target_type = "ACCOUNT" @@ -444,6 +448,7 @@ resource "aws_networkflowmonitor_monitor" "test" { func testAccMonitorConfig_updated2(rName string) string { return fmt.Sprintf(` data "aws_caller_identity" "current" {} +data "aws_region" "current" {} resource "aws_vpc" "test" { cidr_block = "10.0.0.0/16" @@ -464,7 +469,7 @@ resource "aws_subnet" "test" { resource "aws_networkflowmonitor_scope" "test" { targets { - region = "us-east-1" + region = data.aws_region.current.name target_identifier { target_id = data.aws_caller_identity.current.account_id target_type = "ACCOUNT" @@ -502,9 +507,9 @@ resource "aws_networkflowmonitor_monitor" "test" { func testAccPreCheck(ctx context.Context, t *testing.T) { conn := acctest.Provider.Meta().(*conns.AWSClient).NetworkFlowMonitorClient(ctx) - input := &networkflowmonitor.ListMonitorsInput{} + input := networkflowmonitor.ListMonitorsInput{} - _, err := conn.ListMonitors(ctx, input) + _, err := conn.ListMonitors(ctx, &input) if acctest.PreCheckSkipError(err) { t.Skipf("skipping acceptance testing: %s", err) diff --git a/internal/service/networkflowmonitor/scope.go b/internal/service/networkflowmonitor/scope.go index 7f66323fd10e..9059c9d996dc 100644 --- a/internal/service/networkflowmonitor/scope.go +++ b/internal/service/networkflowmonitor/scope.go @@ -10,6 +10,7 @@ import ( "time" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/networkflowmonitor" awstypes "github.com/aws/aws-sdk-go-v2/service/networkflowmonitor/types" "github.com/google/uuid" @@ -50,10 +51,6 @@ type scopeResource struct { framework.WithTimeouts } -func (r *scopeResource) Metadata(_ context.Context, request resource.MetadataRequest, response *resource.MetadataResponse) { - response.TypeName = request.ProviderTypeName + "_networkflowmonitor_scope" -} - func (r *scopeResource) Schema(ctx context.Context, request resource.SchemaRequest, response *resource.SchemaResponse) { response.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ @@ -141,7 +138,7 @@ func (r *scopeResource) Create(ctx context.Context, request resource.CreateReque conn := r.Meta().NetworkFlowMonitorClient(ctx) // Manual parameter mapping (AutoFlex can't handle union types) - input := &networkflowmonitor.CreateScopeInput{} + input := networkflowmonitor.CreateScopeInput{} // Map targets manually since they contain union types if !data.Targets.IsNull() && !data.Targets.IsUnknown() { @@ -153,7 +150,7 @@ func (r *scopeResource) Create(ctx context.Context, request resource.CreateReque input.Targets = make([]awstypes.TargetResource, len(targets)) for i, target := range targets { - input.Targets[i].Region = aws.String(target.Region.ValueString()) + input.Targets[i].Region = target.Region.ValueStringPointer() if !target.TargetIdentifier.IsNull() && !target.TargetIdentifier.IsUnknown() { targetIds, diags := target.TargetIdentifier.ToSlice(ctx) @@ -179,7 +176,7 @@ func (r *scopeResource) Create(ctx context.Context, request resource.CreateReque input.ClientToken = aws.String(uuid.New().String()) input.Tags = getTagsIn(ctx) - output, err := conn.CreateScope(ctx, input) + output, err := conn.CreateScope(ctx, &input) if err != nil { response.Diagnostics.AddError("creating Network Flow Monitor Scope", err.Error()) return @@ -349,13 +346,13 @@ func (r *scopeResource) Update(ctx context.Context, request resource.UpdateReque // Update scope targets if there are changes if len(resourcesToAdd) > 0 || len(resourcesToDelete) > 0 { - input := &networkflowmonitor.UpdateScopeInput{ - ScopeId: aws.String(old.ScopeId.ValueString()), + input := networkflowmonitor.UpdateScopeInput{ + ScopeId: old.ScopeId.ValueStringPointer(), ResourcesToAdd: resourcesToAdd, ResourcesToDelete: resourcesToDelete, } - _, err := conn.UpdateScope(ctx, input) + _, err := conn.UpdateScope(ctx, &input) if err != nil { response.Diagnostics.AddError(fmt.Sprintf("updating Network Flow Monitor Scope (%s) targets", new.ID.ValueString()), err.Error()) return @@ -450,7 +447,7 @@ func (r *scopeResource) calculateTargetChanges(ctx context.Context, oldTargets, for _, target := range oldTargetsList { awsTarget := awstypes.TargetResource{ - Region: aws.String(target.Region.ValueString()), + Region: target.Region.ValueStringPointer(), } // Handle union type for TargetIdentifier @@ -492,7 +489,7 @@ func (r *scopeResource) calculateTargetChanges(ctx context.Context, oldTargets, for _, target := range newTargetsList { awsTarget := awstypes.TargetResource{ - Region: aws.String(target.Region.ValueString()), + Region: target.Region.ValueStringPointer(), } // Handle union type for TargetIdentifier @@ -547,9 +544,10 @@ func (r *scopeResource) Delete(ctx context.Context, request resource.DeleteReque conn := r.Meta().NetworkFlowMonitorClient(ctx) - _, err := conn.DeleteScope(ctx, &networkflowmonitor.DeleteScopeInput{ - ScopeId: aws.String(data.ScopeId.ValueString()), - }) + input := networkflowmonitor.DeleteScopeInput{ + ScopeId: data.ScopeId.ValueStringPointer(), + } + _, err := conn.DeleteScope(ctx, &input) if errs.IsA[*awstypes.ResourceNotFoundException](err) { return @@ -571,17 +569,28 @@ func (r *scopeResource) ImportState(ctx context.Context, request resource.Import id := request.ID // If it's an ARN, extract the scope ID - if strings.HasPrefix(id, "arn:aws:networkflowmonitor:") { - // ARN format: arn:aws:networkflowmonitor:region:account:scope/scope-id - parts := strings.Split(id, "/") - if len(parts) != 2 { - response.Diagnostics.AddError("Invalid import ID", fmt.Sprintf("Expected ARN format 'arn:aws:networkflowmonitor:region:account:scope/scope-id', got: %s", id)) + if arn.IsARN(id) { + parsedARN, err := arn.Parse(id) + if err != nil { + response.Diagnostics.AddError("Invalid ARN", fmt.Sprintf("Unable to parse ARN (%s): %s", id, err)) + return + } + + if parsedARN.Service != "networkflowmonitor" { + response.Diagnostics.AddError("Invalid ARN", fmt.Sprintf("Expected networkflowmonitor service ARN, got: %s", parsedARN.Service)) + return + } + + // ARN format: arn:partition:networkflowmonitor:region:account:scope/scope-id + parts := strings.Split(parsedARN.Resource, "/") + if len(parts) != 2 || parts[0] != "scope" { + response.Diagnostics.AddError("Invalid import ID", fmt.Sprintf("Expected ARN format 'arn:partition:networkflowmonitor:region:account:scope/scope-id', got: %s", id)) return } scopeId := parts[1] // Set both ID (ARN) and scope_id - response.Diagnostics.Append(response.State.SetAttribute(ctx, path.Root("id"), id)...) + response.Diagnostics.Append(response.State.SetAttribute(ctx, path.Root(names.AttrID), id)...) response.Diagnostics.Append(response.State.SetAttribute(ctx, path.Root("scope_id"), scopeId)...) } else { // Assume it's a scope ID, we'll need to construct the ARN during read @@ -591,11 +600,11 @@ func (r *scopeResource) ImportState(ctx context.Context, request resource.Import } func findScopeByID(ctx context.Context, conn *networkflowmonitor.Client, id string) (*networkflowmonitor.GetScopeOutput, error) { - input := &networkflowmonitor.GetScopeInput{ + input := networkflowmonitor.GetScopeInput{ ScopeId: aws.String(id), } - output, err := conn.GetScope(ctx, input) + output, err := conn.GetScope(ctx, &input) if errs.IsA[*awstypes.ResourceNotFoundException](err) { return nil, &retry.NotFoundError{ @@ -616,7 +625,7 @@ func findScopeByID(ctx context.Context, conn *networkflowmonitor.Client, id stri } func statusScope(ctx context.Context, conn *networkflowmonitor.Client, id string) retry.StateRefreshFunc { - return func() (interface{}, string, error) { + return func() (any, string, error) { output, err := findScopeByID(ctx, conn, id) if tfresource.NotFound(err) { diff --git a/internal/service/networkflowmonitor/scope_test.go b/internal/service/networkflowmonitor/scope_test.go index a9f663cf12d9..118da017504e 100644 --- a/internal/service/networkflowmonitor/scope_test.go +++ b/internal/service/networkflowmonitor/scope_test.go @@ -51,7 +51,7 @@ func testAccNetworkFlowMonitorScope_basic(t *testing.T) { Config: testAccScopeConfig_basic(), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckScopeExists(ctx, resourceName, &scope), - resource.TestCheckResourceAttrSet(resourceName, names.AttrARN), + acctest.CheckResourceAttrRegionalARN(ctx, resourceName, names.AttrARN, "networkflowmonitor", "scope/*"), resource.TestCheckResourceAttrSet(resourceName, "scope_id"), resource.TestCheckResourceAttrSet(resourceName, names.AttrStatus), ), @@ -106,11 +106,11 @@ func testAccNetworkFlowMonitorScope_tags(t *testing.T) { CheckDestroy: testAccCheckScopeDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccScopeConfig_tags1("key1", "value1"), + Config: testAccScopeConfig_tags1(acctest.CtKey1, acctest.CtValue1), Check: resource.ComposeTestCheckFunc( testAccCheckScopeExists(ctx, resourceName, &scope), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1"), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "1"), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey1, acctest.CtValue1), ), }, { @@ -119,20 +119,20 @@ func testAccNetworkFlowMonitorScope_tags(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccScopeConfig_tags2("key1", "value1updated", "key2", "value2"), + Config: testAccScopeConfig_tags2(acctest.CtKey1, "value1updated", acctest.CtKey2, acctest.CtValue2), Check: resource.ComposeTestCheckFunc( testAccCheckScopeExists(ctx, resourceName, &scope), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1updated"), - resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "2"), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey1, "value1updated"), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey2, acctest.CtValue2), ), }, { - Config: testAccScopeConfig_tags1("key2", "value2"), + Config: testAccScopeConfig_tags1(acctest.CtKey2, acctest.CtValue2), Check: resource.ComposeTestCheckFunc( testAccCheckScopeExists(ctx, resourceName, &scope), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "1"), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey2, acctest.CtValue2), ), }, }, @@ -189,10 +189,11 @@ func testAccCheckScopeDestroy(ctx context.Context) resource.TestCheckFunc { func testAccScopeConfig_basic() string { return ` data "aws_caller_identity" "current" {} +data "aws_region" "current" {} resource "aws_networkflowmonitor_scope" "test" { targets { - region = "us-east-1" + region = data.aws_region.current.name target_identifier { target_id = data.aws_caller_identity.current.account_id target_type = "ACCOUNT" @@ -205,10 +206,11 @@ resource "aws_networkflowmonitor_scope" "test" { func testAccScopeConfig_tags1(tagKey1, tagValue1 string) string { return fmt.Sprintf(` data "aws_caller_identity" "current" {} +data "aws_region" "current" {} resource "aws_networkflowmonitor_scope" "test" { targets { - region = "us-east-1" + region = data.aws_region.current.name target_identifier { target_id = data.aws_caller_identity.current.account_id target_type = "ACCOUNT" @@ -225,10 +227,11 @@ resource "aws_networkflowmonitor_scope" "test" { func testAccScopeConfig_tags2(tagKey1, tagValue1, tagKey2, tagValue2 string) string { return fmt.Sprintf(` data "aws_caller_identity" "current" {} +data "aws_region" "current" {} resource "aws_networkflowmonitor_scope" "test" { targets { - region = "us-east-1" + region = data.aws_region.current.name target_identifier { target_id = data.aws_caller_identity.current.account_id target_type = "ACCOUNT" diff --git a/internal/service/networkflowmonitor/sweep.go b/internal/service/networkflowmonitor/sweep.go index f6c9377c328b..9ec84c749821 100644 --- a/internal/service/networkflowmonitor/sweep.go +++ b/internal/service/networkflowmonitor/sweep.go @@ -13,6 +13,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/sweep" "github.com/hashicorp/terraform-provider-aws/internal/sweep/awsv2" "github.com/hashicorp/terraform-provider-aws/internal/sweep/framework" + "github.com/hashicorp/terraform-provider-aws/names" ) func RegisterSweepers() { @@ -31,13 +32,13 @@ func sweepMonitors(region string) error { ctx := sweep.Context(region) client, err := sweep.SharedRegionalSweepClient(ctx, region) if err != nil { - return fmt.Errorf("error getting client: %s", err) + return fmt.Errorf("error getting client: %w", err) } conn := client.NetworkFlowMonitorClient(ctx) - input := &networkflowmonitor.ListMonitorsInput{} + input := networkflowmonitor.ListMonitorsInput{} sweepResources := make([]sweep.Sweepable, 0) - pages := networkflowmonitor.NewListMonitorsPaginator(conn, input) + pages := networkflowmonitor.NewListMonitorsPaginator(conn, &input) for pages.HasMorePages() { page, err := pages.NextPage(ctx) @@ -55,7 +56,7 @@ func sweepMonitors(region string) error { name := aws.ToString(v.MonitorName) sweepResources = append(sweepResources, framework.NewSweepResource(newMonitorResource, client, - framework.NewAttribute("id", arn), + framework.NewAttribute(names.AttrID, arn), framework.NewAttribute("monitor_name", name), )) } @@ -73,13 +74,13 @@ func sweepScopes(region string) error { ctx := sweep.Context(region) client, err := sweep.SharedRegionalSweepClient(ctx, region) if err != nil { - return fmt.Errorf("error getting client: %s", err) + return fmt.Errorf("error getting client: %w", err) } conn := client.NetworkFlowMonitorClient(ctx) - input := &networkflowmonitor.ListScopesInput{} + input := networkflowmonitor.ListScopesInput{} sweepResources := make([]sweep.Sweepable, 0) - pages := networkflowmonitor.NewListScopesPaginator(conn, input) + pages := networkflowmonitor.NewListScopesPaginator(conn, &input) for pages.HasMorePages() { page, err := pages.NextPage(ctx) @@ -97,7 +98,7 @@ func sweepScopes(region string) error { scopeArn := aws.ToString(v.ScopeArn) sweepResources = append(sweepResources, framework.NewSweepResource(newScopeResource, client, - framework.NewAttribute("id", scopeArn), + framework.NewAttribute(names.AttrID, scopeArn), framework.NewAttribute("scope_id", scopeId), )) } diff --git a/website/docs/r/networkflowmonitor_monitor.html.markdown b/website/docs/r/networkflowmonitor_monitor.html.markdown index 4f601a5aadc9..a87becf2d5d1 100644 --- a/website/docs/r/networkflowmonitor_monitor.html.markdown +++ b/website/docs/r/networkflowmonitor_monitor.html.markdown @@ -1,5 +1,5 @@ --- -subcategory: "Network Flow Monitor" +subcategory: "CloudWatch NetworkFlow Monitor" layout: "aws" page_title: "AWS: aws_networkflowmonitor_monitor" description: |- @@ -92,4 +92,4 @@ Using `terraform import`, import Network Flow Monitor Monitor using the monitor ```console % terraform import aws_networkflowmonitor_monitor.example arn:aws:networkflowmonitor:us-west-2:123456789012:monitor/example-monitor -``` \ No newline at end of file +``` diff --git a/website/docs/r/networkflowmonitor_scope.html.markdown b/website/docs/r/networkflowmonitor_scope.html.markdown index b6b0b89cdb03..ab007e1ac94e 100644 --- a/website/docs/r/networkflowmonitor_scope.html.markdown +++ b/website/docs/r/networkflowmonitor_scope.html.markdown @@ -1,5 +1,5 @@ --- -subcategory: "Network Flow Monitor" +subcategory: "CloudWatch NetworkFlow Monitor" layout: "aws" page_title: "AWS: aws_networkflowmonitor_scope" description: |- @@ -32,7 +32,6 @@ resource "aws_networkflowmonitor_scope" "example" { } ``` - ## Argument Reference This resource supports the following arguments: @@ -87,4 +86,4 @@ Using `terraform import`, import Network Flow Monitor Scope using the scope ARN. ```console % terraform import aws_networkflowmonitor_scope.example arn:aws:networkflowmonitor:us-east-1:123456789012:scope/example-scope-id -``` \ No newline at end of file +``` From ac8f19060ab7135bf66d9e3bed49a45d1150fd58 Mon Sep 17 00:00:00 2001 From: Sasi Date: Wed, 5 Nov 2025 19:19:21 -0500 Subject: [PATCH 05/21] fixed linting and make gen error --- .../monitor_tags_gen_test.go | 2257 +++++++++++++++++ .../networkflowmonitor/monitor_test.go | 40 +- internal/service/networkflowmonitor/scope.go | 2 +- .../networkflowmonitor/scope_tags_gen_test.go | 2257 +++++++++++++++++ .../service/networkflowmonitor/scope_test.go | 30 +- .../networkflowmonitor/service_package_gen.go | 2 + .../networkflowmonitor/tags_gen_test.go | 16 + .../testdata/Monitor/tags/main_gen.tf | 52 + .../Monitor/tagsComputed1/main_gen.tf | 56 + .../Monitor/tagsComputed2/main_gen.tf | 67 + .../Monitor/tags_defaults/main_gen.tf | 63 + .../testdata/Monitor/tags_ignore/main_gen.tf | 72 + .../testdata/Scope/tags/main_gen.tf | 29 + .../testdata/Scope/tagsComputed1/main_gen.tf | 33 + .../testdata/Scope/tagsComputed2/main_gen.tf | 44 + .../testdata/Scope/tags_defaults/main_gen.tf | 40 + .../testdata/Scope/tags_ignore/main_gen.tf | 49 + .../testdata/tmpl/monitor_tags.gtpl | 36 + .../testdata/tmpl/scope_tags.gtpl | 13 + .../networkflowmonitor_monitor.html.markdown | 6 +- .../r/networkflowmonitor_scope.html.markdown | 5 +- 21 files changed, 5121 insertions(+), 48 deletions(-) create mode 100644 internal/service/networkflowmonitor/monitor_tags_gen_test.go create mode 100644 internal/service/networkflowmonitor/scope_tags_gen_test.go create mode 100644 internal/service/networkflowmonitor/tags_gen_test.go create mode 100644 internal/service/networkflowmonitor/testdata/Monitor/tags/main_gen.tf create mode 100644 internal/service/networkflowmonitor/testdata/Monitor/tagsComputed1/main_gen.tf create mode 100644 internal/service/networkflowmonitor/testdata/Monitor/tagsComputed2/main_gen.tf create mode 100644 internal/service/networkflowmonitor/testdata/Monitor/tags_defaults/main_gen.tf create mode 100644 internal/service/networkflowmonitor/testdata/Monitor/tags_ignore/main_gen.tf create mode 100644 internal/service/networkflowmonitor/testdata/Scope/tags/main_gen.tf create mode 100644 internal/service/networkflowmonitor/testdata/Scope/tagsComputed1/main_gen.tf create mode 100644 internal/service/networkflowmonitor/testdata/Scope/tagsComputed2/main_gen.tf create mode 100644 internal/service/networkflowmonitor/testdata/Scope/tags_defaults/main_gen.tf create mode 100644 internal/service/networkflowmonitor/testdata/Scope/tags_ignore/main_gen.tf create mode 100644 internal/service/networkflowmonitor/testdata/tmpl/monitor_tags.gtpl create mode 100644 internal/service/networkflowmonitor/testdata/tmpl/scope_tags.gtpl diff --git a/internal/service/networkflowmonitor/monitor_tags_gen_test.go b/internal/service/networkflowmonitor/monitor_tags_gen_test.go new file mode 100644 index 000000000000..3f77387ccfba --- /dev/null +++ b/internal/service/networkflowmonitor/monitor_tags_gen_test.go @@ -0,0 +1,2257 @@ +// Code generated by internal/generate/tagstests/main.go; DO NOT EDIT. + +package networkflowmonitor_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/config" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/knownvalue" + "github.com/hashicorp/terraform-plugin-testing/plancheck" + "github.com/hashicorp/terraform-plugin-testing/statecheck" + "github.com/hashicorp/terraform-plugin-testing/tfjsonpath" + "github.com/hashicorp/terraform-provider-aws/internal/acctest" + "github.com/hashicorp/terraform-provider-aws/names" +) + +func TestAccNetworkFlowMonitorMonitor_tags(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_monitor.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckMonitorDestroy(ctx), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1Updated), + acctest.CtKey2: config.StringVariable(acctest.CtValue2), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1Updated), + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1Updated), + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1Updated), + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1Updated), + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1Updated), + acctest.CtKey2: config.StringVariable(acctest.CtValue2), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey2: config.StringVariable(acctest.CtValue2), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey2: config.StringVariable(acctest.CtValue2), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: nil, + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: nil, + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorMonitor_tags_null(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_monitor.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckMonitorDestroy(ctx), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: nil, + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.Null(), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.Null(), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: nil, + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + acctest.CtTagsKey1, // The canonical value returned by the AWS API is "" + }, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorMonitor_tags_EmptyMap(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_monitor.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckMonitorDestroy(ctx), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{}), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{})), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{})), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{}), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + acctest.CtTagsKey1, // The canonical value returned by the AWS API is "" + }, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorMonitor_tags_AddOnUpdate(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_monitor.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckMonitorDestroy(ctx), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: nil, + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorMonitor_tags_EmptyTag_OnCreate(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_monitor.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckMonitorDestroy(ctx), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(""), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(""), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: nil, + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: nil, + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorMonitor_tags_EmptyTag_OnUpdate_Add(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_monitor.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckMonitorDestroy(ctx), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + acctest.CtKey2: config.StringVariable(""), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + acctest.CtKey2: knownvalue.StringExact(""), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + acctest.CtKey2: knownvalue.StringExact(""), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + acctest.CtKey2: knownvalue.StringExact(""), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + acctest.CtKey2: knownvalue.StringExact(""), + })), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + acctest.CtKey2: config.StringVariable(""), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorMonitor_tags_EmptyTag_OnUpdate_Replace(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_monitor.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckMonitorDestroy(ctx), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(""), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(""), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorMonitor_tags_DefaultTags_providerOnly(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_monitor.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckMonitorDestroy(ctx), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + acctest.CtResourceTags: nil, + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + acctest.CtResourceTags: nil, + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1Updated), + acctest.CtKey2: config.StringVariable(acctest.CtValue2), + }), + acctest.CtResourceTags: nil, + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1Updated), + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1Updated), + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1Updated), + acctest.CtKey2: config.StringVariable(acctest.CtValue2), + }), + acctest.CtResourceTags: nil, + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey2: config.StringVariable(acctest.CtValue2), + }), + acctest.CtResourceTags: nil, + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey2: config.StringVariable(acctest.CtValue2), + }), + acctest.CtResourceTags: nil, + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: nil, + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: nil, + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorMonitor_tags_DefaultTags_nonOverlapping(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_monitor.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckMonitorDestroy(ctx), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1), + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1), + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1Updated), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1Updated), + acctest.CtResourceKey2: config.StringVariable(acctest.CtResourceValue2), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1Updated), + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1Updated), + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1Updated), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1Updated), + acctest.CtResourceKey2: config.StringVariable(acctest.CtResourceValue2), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: nil, + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: nil, + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorMonitor_tags_DefaultTags_overlapping(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_monitor.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckMonitorDestroy(ctx), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtOverlapKey1: config.StringVariable(acctest.CtProviderValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtOverlapKey1: config.StringVariable(acctest.CtResourceValue1), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtOverlapKey1: config.StringVariable(acctest.CtProviderValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtOverlapKey1: config.StringVariable(acctest.CtResourceValue1), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtOverlapKey1: config.StringVariable(acctest.CtProviderValue1), + acctest.CtOverlapKey2: config.StringVariable("providervalue2"), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtOverlapKey1: config.StringVariable(acctest.CtResourceValue1), + acctest.CtOverlapKey2: config.StringVariable(acctest.CtResourceValue2), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), + acctest.CtOverlapKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), + acctest.CtOverlapKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), + acctest.CtOverlapKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), + acctest.CtOverlapKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtOverlapKey1: config.StringVariable(acctest.CtProviderValue1), + acctest.CtOverlapKey2: config.StringVariable("providervalue2"), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtOverlapKey1: config.StringVariable(acctest.CtResourceValue1), + acctest.CtOverlapKey2: config.StringVariable(acctest.CtResourceValue2), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtOverlapKey1: config.StringVariable(acctest.CtProviderValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtOverlapKey1: config.StringVariable(acctest.CtResourceValue2), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue2), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue2), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue2), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue2), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtOverlapKey1: config.StringVariable(acctest.CtProviderValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtOverlapKey1: config.StringVariable(acctest.CtResourceValue2), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorMonitor_tags_DefaultTags_updateToProviderOnly(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_monitor.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckMonitorDestroy(ctx), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + acctest.CtResourceTags: nil, + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + acctest.CtResourceTags: nil, + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorMonitor_tags_DefaultTags_updateToResourceOnly(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_monitor.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckMonitorDestroy(ctx), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + acctest.CtResourceTags: nil, + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorMonitor_tags_DefaultTags_emptyResourceTag(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_monitor.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckMonitorDestroy(ctx), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(""), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(""), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorMonitor_tags_DefaultTags_emptyProviderOnlyTag(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_monitor.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckMonitorDestroy(ctx), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(""), + }), + acctest.CtResourceTags: nil, + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(""), + }), + acctest.CtResourceTags: nil, + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorMonitor_tags_DefaultTags_nullOverlappingResourceTag(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_monitor.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckMonitorDestroy(ctx), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtProviderValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: nil, + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.Null(), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.Null(), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtProviderValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: nil, + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + acctest.CtTagsKey1, // The canonical value returned by the AWS API is "" + }, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorMonitor_tags_DefaultTags_nullNonOverlappingResourceTag(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_monitor.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckMonitorDestroy(ctx), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: nil, + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.Null(), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(""), + acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.Null(), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(""), + acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: nil, + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "tags.resourcekey1", // The canonical value returned by the AWS API is "" + }, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorMonitor_tags_ComputedTag_OnCreate(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_monitor.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckMonitorDestroy(ctx), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tagsComputed1/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + "unknownTagKey": config.StringVariable("computedkey1"), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + resource.TestCheckResourceAttrPair(resourceName, "tags.computedkey1", "null_resource.test", names.AttrID), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapSizeExact(1)), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapSizeExact(1)), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectUnknownValue(resourceName, tfjsonpath.New(names.AttrTags).AtMapKey("computedkey1")), + plancheck.ExpectUnknownValue(resourceName, tfjsonpath.New(names.AttrTagsAll)), + }, + PostApplyPreRefresh: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), + }, + PostApplyPostRefresh: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tagsComputed1/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + "unknownTagKey": config.StringVariable("computedkey1"), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorMonitor_tags_ComputedTag_OnUpdate_Add(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_monitor.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckMonitorDestroy(ctx), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tagsComputed2/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + "unknownTagKey": config.StringVariable("computedkey1"), + "knownTagKey": config.StringVariable(acctest.CtKey1), + "knownTagValue": config.StringVariable(acctest.CtValue1), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + resource.TestCheckResourceAttrPair(resourceName, "tags.computedkey1", "null_resource.test", names.AttrID), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapSizeExact(2)), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapPartial(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapSizeExact(2)), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapPartial(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectUnknownValue(resourceName, tfjsonpath.New(names.AttrTags).AtMapKey("computedkey1")), + plancheck.ExpectUnknownValue(resourceName, tfjsonpath.New(names.AttrTagsAll)), + }, + PostApplyPreRefresh: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), + }, + PostApplyPostRefresh: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tagsComputed2/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + "unknownTagKey": config.StringVariable("computedkey1"), + "knownTagKey": config.StringVariable(acctest.CtKey1), + "knownTagValue": config.StringVariable(acctest.CtValue1), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorMonitor_tags_ComputedTag_OnUpdate_Replace(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_monitor.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckMonitorDestroy(ctx), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tagsComputed1/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + "unknownTagKey": config.StringVariable(acctest.CtKey1), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + resource.TestCheckResourceAttrPair(resourceName, acctest.CtTagsKey1, "null_resource.test", names.AttrID), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapSizeExact(1)), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapSizeExact(1)), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectUnknownValue(resourceName, tfjsonpath.New(names.AttrTags).AtMapKey(acctest.CtKey1)), + plancheck.ExpectUnknownValue(resourceName, tfjsonpath.New(names.AttrTagsAll)), + }, + PostApplyPreRefresh: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), + }, + PostApplyPostRefresh: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tagsComputed1/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + "unknownTagKey": config.StringVariable(acctest.CtKey1), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorMonitor_tags_IgnoreTags_Overlap_DefaultTag(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_monitor.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckMonitorDestroy(ctx), + Steps: []resource.TestStep{ + // 1: Create + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_ignore/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1), + }), + "ignore_tag_keys": config.SetVariable( + config.StringVariable(acctest.CtProviderKey1), + ), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + expectFullResourceTags(ctx, resourceName, knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1), // TODO: Should not be set + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + }, + PostApplyPreRefresh: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + }, + PostApplyPostRefresh: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + }, + }, + }, + // 2: Update ignored tag only + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_ignore/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1Updated), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1), + }), + "ignore_tag_keys": config.SetVariable( + config.StringVariable(acctest.CtProviderKey1), + ), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + expectFullResourceTags(ctx, resourceName, knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1), // TODO: Should not be set + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + }, + PostApplyPreRefresh: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + }, + PostApplyPostRefresh: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + }, + }, + }, + // 3: Update both tags + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_ignore/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1Again), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1Updated), + }), + "ignore_tag_keys": config.SetVariable( + config.StringVariable(acctest.CtProviderKey1), + ), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), + })), + expectFullResourceTags(ctx, resourceName, knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1), // TODO: Should not be set + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), + })), + }, + PostApplyPreRefresh: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + }, + PostApplyPostRefresh: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + }, + }, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorMonitor_tags_IgnoreTags_Overlap_ResourceTag(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_monitor.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckMonitorDestroy(ctx), + Steps: []resource.TestStep{ + // 1: Create + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_ignore/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1), + acctest.CtResourceKey2: config.StringVariable(acctest.CtResourceValue2), + }), + "ignore_tag_keys": config.SetVariable( + config.StringVariable(acctest.CtResourceKey1), + ), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + expectFullResourceTags(ctx, resourceName, knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), // TODO: Should not be set + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + }, + PostApplyPreRefresh: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + }, + PostApplyPostRefresh: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), // TODO: Should be NoOp + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + }, + }, + ExpectNonEmptyPlan: true, + }, + // 2: Update ignored tag + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_ignore/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1Updated), + acctest.CtResourceKey2: config.StringVariable(acctest.CtResourceValue2), + }), + "ignore_tag_keys": config.SetVariable( + config.StringVariable(acctest.CtResourceKey1), + ), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + expectFullResourceTags(ctx, resourceName, knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), // TODO: Should not be set + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + }, + PostApplyPreRefresh: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + }, + PostApplyPostRefresh: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), // TODO: Should be NoOp + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + }, + }, + ExpectNonEmptyPlan: true, + }, + // 3: Update both tags + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_ignore/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1Again), + acctest.CtResourceKey2: config.StringVariable(acctest.CtResourceValue2Updated), + }), + "ignore_tag_keys": config.SetVariable( + config.StringVariable(acctest.CtResourceKey1), + ), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMonitorExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Again), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2Updated), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2Updated), + })), + expectFullResourceTags(ctx, resourceName, knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), // TODO: Should not be set + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2Updated), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Again), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2Updated), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2Updated), + })), + }, + PostApplyPreRefresh: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + }, + PostApplyPostRefresh: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), // TODO: Should be NoOp + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Again), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2Updated), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2Updated), + })), + }, + }, + ExpectNonEmptyPlan: true, + }, + }, + }) +} diff --git a/internal/service/networkflowmonitor/monitor_test.go b/internal/service/networkflowmonitor/monitor_test.go index 1fb1d0188d7f..7db8be912850 100644 --- a/internal/service/networkflowmonitor/monitor_test.go +++ b/internal/service/networkflowmonitor/monitor_test.go @@ -37,7 +37,6 @@ func TestAccNetworkFlowMonitorMonitor_serial(t *testing.T) { func testAccNetworkFlowMonitorMonitor_basic(t *testing.T) { ctx := acctest.Context(t) - var monitor networkflowmonitor.GetMonitorOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_networkflowmonitor_monitor.test" @@ -53,7 +52,7 @@ func testAccNetworkFlowMonitorMonitor_basic(t *testing.T) { { Config: testAccMonitorConfig_basic(rName), Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName, &monitor), + testAccCheckMonitorExists(ctx, resourceName), resource.TestCheckResourceAttr(resourceName, "monitor_name", rName), acctest.CheckResourceAttrRegionalARN(ctx, resourceName, names.AttrARN, "networkflowmonitor", fmt.Sprintf("monitor/%s", rName)), resource.TestCheckResourceAttrSet(resourceName, "monitor_status"), @@ -71,7 +70,6 @@ func testAccNetworkFlowMonitorMonitor_basic(t *testing.T) { func testAccNetworkFlowMonitorMonitor_disappears(t *testing.T) { ctx := acctest.Context(t) - var monitor networkflowmonitor.GetMonitorOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_networkflowmonitor_monitor.test" @@ -87,7 +85,7 @@ func testAccNetworkFlowMonitorMonitor_disappears(t *testing.T) { { Config: testAccMonitorConfig_basic(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName, &monitor), + testAccCheckMonitorExists(ctx, resourceName), acctest.CheckFrameworkResourceDisappears(ctx, acctest.Provider, tfnetworkflowmonitor.ResourceMonitor, resourceName), ), ExpectNonEmptyPlan: true, @@ -98,7 +96,6 @@ func testAccNetworkFlowMonitorMonitor_disappears(t *testing.T) { func testAccNetworkFlowMonitorMonitor_tags(t *testing.T) { ctx := acctest.Context(t) - var monitor networkflowmonitor.GetMonitorOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_networkflowmonitor_monitor.test" @@ -114,7 +111,7 @@ func testAccNetworkFlowMonitorMonitor_tags(t *testing.T) { { Config: testAccMonitorConfig_tags1(rName, acctest.CtKey1, acctest.CtValue1), Check: resource.ComposeTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName, &monitor), + testAccCheckMonitorExists(ctx, resourceName), resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "1"), resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey1, acctest.CtValue1), ), @@ -126,18 +123,18 @@ func testAccNetworkFlowMonitorMonitor_tags(t *testing.T) { ImportStateVerifyIgnore: []string{"scope_arn"}, }, { - Config: testAccMonitorConfig_tags2(rName, acctest.CtKey1, "value1updated", acctest.CtKey2, acctest.CtValue2), + Config: testAccMonitorConfig_tags2(rName, acctest.CtKey1, acctest.CtValue1Updated, acctest.CtKey2, acctest.CtValue2), Check: resource.ComposeTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName, &monitor), + testAccCheckMonitorExists(ctx, resourceName), resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "2"), - resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey1, "value1updated"), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey1, acctest.CtValue1Updated), resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey2, acctest.CtValue2), ), }, { Config: testAccMonitorConfig_tags1(rName, acctest.CtKey2, acctest.CtValue2), Check: resource.ComposeTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName, &monitor), + testAccCheckMonitorExists(ctx, resourceName), resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "1"), resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey2, acctest.CtValue2), ), @@ -148,7 +145,6 @@ func testAccNetworkFlowMonitorMonitor_tags(t *testing.T) { func testAccNetworkFlowMonitorMonitor_update(t *testing.T) { ctx := acctest.Context(t) - var monitor networkflowmonitor.GetMonitorOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_networkflowmonitor_monitor.test" @@ -164,7 +160,7 @@ func testAccNetworkFlowMonitorMonitor_update(t *testing.T) { { Config: testAccMonitorConfig_basic(rName), Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName, &monitor), + testAccCheckMonitorExists(ctx, resourceName), resource.TestCheckResourceAttr(resourceName, "monitor_name", rName), resource.TestCheckResourceAttr(resourceName, "local_resources.0.type", "AWS::EC2::VPC"), ), @@ -173,7 +169,7 @@ func testAccNetworkFlowMonitorMonitor_update(t *testing.T) { { Config: testAccMonitorConfig_updated1(rName), Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName, &monitor), + testAccCheckMonitorExists(ctx, resourceName), resource.TestCheckResourceAttr(resourceName, "monitor_name", rName), resource.TestCheckResourceAttr(resourceName, "local_resources.#", "2"), resource.TestCheckResourceAttr(resourceName, "remote_resources.#", "1"), @@ -183,7 +179,7 @@ func testAccNetworkFlowMonitorMonitor_update(t *testing.T) { { Config: testAccMonitorConfig_basic(rName), Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName, &monitor), + testAccCheckMonitorExists(ctx, resourceName), resource.TestCheckResourceAttr(resourceName, "monitor_name", rName), resource.TestCheckResourceAttr(resourceName, "local_resources.#", "1"), resource.TestCheckResourceAttr(resourceName, "remote_resources.#", "1"), @@ -194,7 +190,7 @@ func testAccNetworkFlowMonitorMonitor_update(t *testing.T) { { Config: testAccMonitorConfig_updated2(rName), Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName, &monitor), + testAccCheckMonitorExists(ctx, resourceName), resource.TestCheckResourceAttr(resourceName, "monitor_name", rName), resource.TestCheckResourceAttr(resourceName, "local_resources.#", "2"), resource.TestCheckResourceAttr(resourceName, "remote_resources.#", "2"), @@ -204,7 +200,7 @@ func testAccNetworkFlowMonitorMonitor_update(t *testing.T) { { Config: testAccMonitorConfig_basic(rName), Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName, &monitor), + testAccCheckMonitorExists(ctx, resourceName), resource.TestCheckResourceAttr(resourceName, "monitor_name", rName), resource.TestCheckResourceAttr(resourceName, "local_resources.#", "1"), resource.TestCheckResourceAttr(resourceName, "remote_resources.#", "1"), @@ -215,7 +211,7 @@ func testAccNetworkFlowMonitorMonitor_update(t *testing.T) { }) } -func testAccCheckMonitorExists(ctx context.Context, n string, v *networkflowmonitor.GetMonitorOutput) resource.TestCheckFunc { +func testAccCheckMonitorExists(ctx context.Context, n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -224,15 +220,9 @@ func testAccCheckMonitorExists(ctx context.Context, n string, v *networkflowmoni conn := acctest.Provider.Meta().(*conns.AWSClient).NetworkFlowMonitorClient(ctx) - output, err := tfnetworkflowmonitor.FindMonitorByName(ctx, conn, rs.Primary.Attributes["monitor_name"]) + _, err := tfnetworkflowmonitor.FindMonitorByName(ctx, conn, rs.Primary.Attributes["monitor_name"]) - if err != nil { - return err - } - - *v = *output - - return nil + return err } } diff --git a/internal/service/networkflowmonitor/scope.go b/internal/service/networkflowmonitor/scope.go index 9059c9d996dc..b5d7a5ae0204 100644 --- a/internal/service/networkflowmonitor/scope.go +++ b/internal/service/networkflowmonitor/scope.go @@ -583,7 +583,7 @@ func (r *scopeResource) ImportState(ctx context.Context, request resource.Import // ARN format: arn:partition:networkflowmonitor:region:account:scope/scope-id parts := strings.Split(parsedARN.Resource, "/") - if len(parts) != 2 || parts[0] != "scope" { + if len(parts) != 2 || parts[0] != names.AttrScope { response.Diagnostics.AddError("Invalid import ID", fmt.Sprintf("Expected ARN format 'arn:partition:networkflowmonitor:region:account:scope/scope-id', got: %s", id)) return } diff --git a/internal/service/networkflowmonitor/scope_tags_gen_test.go b/internal/service/networkflowmonitor/scope_tags_gen_test.go new file mode 100644 index 000000000000..428c03b887b9 --- /dev/null +++ b/internal/service/networkflowmonitor/scope_tags_gen_test.go @@ -0,0 +1,2257 @@ +// Code generated by internal/generate/tagstests/main.go; DO NOT EDIT. + +package networkflowmonitor_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/config" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/knownvalue" + "github.com/hashicorp/terraform-plugin-testing/plancheck" + "github.com/hashicorp/terraform-plugin-testing/statecheck" + "github.com/hashicorp/terraform-plugin-testing/tfjsonpath" + "github.com/hashicorp/terraform-provider-aws/internal/acctest" + "github.com/hashicorp/terraform-provider-aws/names" +) + +func TestAccNetworkFlowMonitorScope_tags(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_scope.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckScopeDestroy(ctx), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1Updated), + acctest.CtKey2: config.StringVariable(acctest.CtValue2), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1Updated), + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1Updated), + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1Updated), + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1Updated), + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1Updated), + acctest.CtKey2: config.StringVariable(acctest.CtValue2), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey2: config.StringVariable(acctest.CtValue2), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey2: config.StringVariable(acctest.CtValue2), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: nil, + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: nil, + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorScope_tags_null(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_scope.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckScopeDestroy(ctx), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: nil, + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.Null(), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.Null(), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: nil, + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + acctest.CtTagsKey1, // The canonical value returned by the AWS API is "" + }, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorScope_tags_EmptyMap(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_scope.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckScopeDestroy(ctx), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{}), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{})), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{})), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{}), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + acctest.CtTagsKey1, // The canonical value returned by the AWS API is "" + }, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorScope_tags_AddOnUpdate(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_scope.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckScopeDestroy(ctx), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: nil, + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorScope_tags_EmptyTag_OnCreate(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_scope.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckScopeDestroy(ctx), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(""), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(""), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: nil, + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: nil, + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorScope_tags_EmptyTag_OnUpdate_Add(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_scope.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckScopeDestroy(ctx), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + acctest.CtKey2: config.StringVariable(""), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + acctest.CtKey2: knownvalue.StringExact(""), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + acctest.CtKey2: knownvalue.StringExact(""), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + acctest.CtKey2: knownvalue.StringExact(""), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + acctest.CtKey2: knownvalue.StringExact(""), + })), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + acctest.CtKey2: config.StringVariable(""), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorScope_tags_EmptyTag_OnUpdate_Replace(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_scope.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckScopeDestroy(ctx), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(""), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + }, + }, + }, + { + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(""), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorScope_tags_DefaultTags_providerOnly(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_scope.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckScopeDestroy(ctx), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + acctest.CtResourceTags: nil, + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + acctest.CtResourceTags: nil, + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1Updated), + acctest.CtKey2: config.StringVariable(acctest.CtValue2), + }), + acctest.CtResourceTags: nil, + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1Updated), + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1Updated), + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1Updated), + acctest.CtKey2: config.StringVariable(acctest.CtValue2), + }), + acctest.CtResourceTags: nil, + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey2: config.StringVariable(acctest.CtValue2), + }), + acctest.CtResourceTags: nil, + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey2: config.StringVariable(acctest.CtValue2), + }), + acctest.CtResourceTags: nil, + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: nil, + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: nil, + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorScope_tags_DefaultTags_nonOverlapping(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_scope.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckScopeDestroy(ctx), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1), + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1), + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1Updated), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1Updated), + acctest.CtResourceKey2: config.StringVariable(acctest.CtResourceValue2), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1Updated), + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1Updated), + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1Updated), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1Updated), + acctest.CtResourceKey2: config.StringVariable(acctest.CtResourceValue2), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: nil, + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: nil, + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorScope_tags_DefaultTags_overlapping(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_scope.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckScopeDestroy(ctx), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtOverlapKey1: config.StringVariable(acctest.CtProviderValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtOverlapKey1: config.StringVariable(acctest.CtResourceValue1), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtOverlapKey1: config.StringVariable(acctest.CtProviderValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtOverlapKey1: config.StringVariable(acctest.CtResourceValue1), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtOverlapKey1: config.StringVariable(acctest.CtProviderValue1), + acctest.CtOverlapKey2: config.StringVariable("providervalue2"), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtOverlapKey1: config.StringVariable(acctest.CtResourceValue1), + acctest.CtOverlapKey2: config.StringVariable(acctest.CtResourceValue2), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), + acctest.CtOverlapKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), + acctest.CtOverlapKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), + acctest.CtOverlapKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), + acctest.CtOverlapKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtOverlapKey1: config.StringVariable(acctest.CtProviderValue1), + acctest.CtOverlapKey2: config.StringVariable("providervalue2"), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtOverlapKey1: config.StringVariable(acctest.CtResourceValue1), + acctest.CtOverlapKey2: config.StringVariable(acctest.CtResourceValue2), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtOverlapKey1: config.StringVariable(acctest.CtProviderValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtOverlapKey1: config.StringVariable(acctest.CtResourceValue2), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue2), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue2), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue2), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue2), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtOverlapKey1: config.StringVariable(acctest.CtProviderValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtOverlapKey1: config.StringVariable(acctest.CtResourceValue2), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorScope_tags_DefaultTags_updateToProviderOnly(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_scope.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckScopeDestroy(ctx), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + acctest.CtResourceTags: nil, + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + acctest.CtResourceTags: nil, + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorScope_tags_DefaultTags_updateToResourceOnly(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_scope.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckScopeDestroy(ctx), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + acctest.CtResourceTags: nil, + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorScope_tags_DefaultTags_emptyResourceTag(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_scope.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckScopeDestroy(ctx), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(""), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(""), + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorScope_tags_DefaultTags_emptyProviderOnlyTag(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_scope.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckScopeDestroy(ctx), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(""), + }), + acctest.CtResourceTags: nil, + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(""), + }), + acctest.CtResourceTags: nil, + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorScope_tags_DefaultTags_nullOverlappingResourceTag(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_scope.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckScopeDestroy(ctx), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtProviderValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: nil, + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.Null(), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.Null(), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(""), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtProviderValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: nil, + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + acctest.CtTagsKey1, // The canonical value returned by the AWS API is "" + }, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorScope_tags_DefaultTags_nullNonOverlappingResourceTag(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_scope.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckScopeDestroy(ctx), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: nil, + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.Null(), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(""), + acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.Null(), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(""), + acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: nil, + }), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "tags.resourcekey1", // The canonical value returned by the AWS API is "" + }, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorScope_tags_ComputedTag_OnCreate(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_scope.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckScopeDestroy(ctx), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tagsComputed1/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + "unknownTagKey": config.StringVariable("computedkey1"), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + resource.TestCheckResourceAttrPair(resourceName, "tags.computedkey1", "null_resource.test", names.AttrID), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapSizeExact(1)), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapSizeExact(1)), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectUnknownValue(resourceName, tfjsonpath.New(names.AttrTags).AtMapKey("computedkey1")), + plancheck.ExpectUnknownValue(resourceName, tfjsonpath.New(names.AttrTagsAll)), + }, + PostApplyPreRefresh: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), + }, + PostApplyPostRefresh: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tagsComputed1/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + "unknownTagKey": config.StringVariable("computedkey1"), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorScope_tags_ComputedTag_OnUpdate_Add(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_scope.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckScopeDestroy(ctx), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tagsComputed2/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + "unknownTagKey": config.StringVariable("computedkey1"), + "knownTagKey": config.StringVariable(acctest.CtKey1), + "knownTagValue": config.StringVariable(acctest.CtValue1), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + resource.TestCheckResourceAttrPair(resourceName, "tags.computedkey1", "null_resource.test", names.AttrID), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapSizeExact(2)), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapPartial(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapSizeExact(2)), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapPartial(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectUnknownValue(resourceName, tfjsonpath.New(names.AttrTags).AtMapKey("computedkey1")), + plancheck.ExpectUnknownValue(resourceName, tfjsonpath.New(names.AttrTagsAll)), + }, + PostApplyPreRefresh: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), + }, + PostApplyPostRefresh: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tagsComputed2/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + "unknownTagKey": config.StringVariable("computedkey1"), + "knownTagKey": config.StringVariable(acctest.CtKey1), + "knownTagValue": config.StringVariable(acctest.CtValue1), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorScope_tags_ComputedTag_OnUpdate_Replace(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_scope.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckScopeDestroy(ctx), + Steps: []resource.TestStep{ + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtKey1: config.StringVariable(acctest.CtValue1), + }), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tagsComputed1/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + "unknownTagKey": config.StringVariable(acctest.CtKey1), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + resource.TestCheckResourceAttrPair(resourceName, acctest.CtTagsKey1, "null_resource.test", names.AttrID), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapSizeExact(1)), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapSizeExact(1)), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectUnknownValue(resourceName, tfjsonpath.New(names.AttrTags).AtMapKey(acctest.CtKey1)), + plancheck.ExpectUnknownValue(resourceName, tfjsonpath.New(names.AttrTagsAll)), + }, + PostApplyPreRefresh: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), + }, + PostApplyPostRefresh: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), + }, + }, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tagsComputed1/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + "unknownTagKey": config.StringVariable(acctest.CtKey1), + }, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorScope_tags_IgnoreTags_Overlap_DefaultTag(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_scope.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckScopeDestroy(ctx), + Steps: []resource.TestStep{ + // 1: Create + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_ignore/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1), + }), + "ignore_tag_keys": config.SetVariable( + config.StringVariable(acctest.CtProviderKey1), + ), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + expectFullResourceTags(ctx, resourceName, knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1), // TODO: Should not be set + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + }, + PostApplyPreRefresh: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + }, + PostApplyPostRefresh: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + }, + }, + }, + // 2: Update ignored tag only + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_ignore/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1Updated), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1), + }), + "ignore_tag_keys": config.SetVariable( + config.StringVariable(acctest.CtProviderKey1), + ), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + expectFullResourceTags(ctx, resourceName, knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1), // TODO: Should not be set + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + })), + }, + PostApplyPreRefresh: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + }, + PostApplyPostRefresh: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + }, + }, + }, + // 3: Update both tags + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_ignore/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ + acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1Again), + }), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1Updated), + }), + "ignore_tag_keys": config.SetVariable( + config.StringVariable(acctest.CtProviderKey1), + ), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), + })), + expectFullResourceTags(ctx, resourceName, knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1), // TODO: Should not be set + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), + })), + }, + PostApplyPreRefresh: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + }, + PostApplyPostRefresh: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + }, + }, + }, + }, + }) +} + +func TestAccNetworkFlowMonitorScope_tags_IgnoreTags_Overlap_ResourceTag(t *testing.T) { + ctx := acctest.Context(t) + + resourceName := "aws_networkflowmonitor_scope.test" + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) + + acctest.ParallelTest(ctx, t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), + CheckDestroy: testAccCheckScopeDestroy(ctx), + Steps: []resource.TestStep{ + // 1: Create + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_ignore/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1), + acctest.CtResourceKey2: config.StringVariable(acctest.CtResourceValue2), + }), + "ignore_tag_keys": config.SetVariable( + config.StringVariable(acctest.CtResourceKey1), + ), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + expectFullResourceTags(ctx, resourceName, knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), // TODO: Should not be set + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + }, + PostApplyPreRefresh: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + }, + PostApplyPostRefresh: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), // TODO: Should be NoOp + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + }, + }, + ExpectNonEmptyPlan: true, + }, + // 2: Update ignored tag + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_ignore/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1Updated), + acctest.CtResourceKey2: config.StringVariable(acctest.CtResourceValue2), + }), + "ignore_tag_keys": config.SetVariable( + config.StringVariable(acctest.CtResourceKey1), + ), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + expectFullResourceTags(ctx, resourceName, knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), // TODO: Should not be set + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + }, + PostApplyPreRefresh: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + }, + PostApplyPostRefresh: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), // TODO: Should be NoOp + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), + })), + }, + }, + ExpectNonEmptyPlan: true, + }, + // 3: Update both tags + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_ignore/"), + ConfigVariables: config.Variables{ + acctest.CtRName: config.StringVariable(rName), + acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ + acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1Again), + acctest.CtResourceKey2: config.StringVariable(acctest.CtResourceValue2Updated), + }), + "ignore_tag_keys": config.SetVariable( + config.StringVariable(acctest.CtResourceKey1), + ), + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckScopeExists(ctx, resourceName), + ), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Again), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2Updated), + })), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2Updated), + })), + expectFullResourceTags(ctx, resourceName, knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), // TODO: Should not be set + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2Updated), + })), + }, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Again), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2Updated), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2Updated), + })), + }, + PostApplyPreRefresh: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + }, + PostApplyPostRefresh: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), // TODO: Should be NoOp + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Again), + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2Updated), + })), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2Updated), + })), + }, + }, + ExpectNonEmptyPlan: true, + }, + }, + }) +} diff --git a/internal/service/networkflowmonitor/scope_test.go b/internal/service/networkflowmonitor/scope_test.go index 118da017504e..8a5449b0c36c 100644 --- a/internal/service/networkflowmonitor/scope_test.go +++ b/internal/service/networkflowmonitor/scope_test.go @@ -8,7 +8,6 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go-v2/service/networkflowmonitor" awstypes "github.com/aws/aws-sdk-go-v2/service/networkflowmonitor/types" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -35,7 +34,6 @@ func TestAccNetworkFlowMonitorScope_serial(t *testing.T) { func testAccNetworkFlowMonitorScope_basic(t *testing.T) { ctx := acctest.Context(t) - var scope networkflowmonitor.GetScopeOutput resourceName := "aws_networkflowmonitor_scope.test" resource.Test(t, resource.TestCase{ @@ -50,7 +48,7 @@ func testAccNetworkFlowMonitorScope_basic(t *testing.T) { { Config: testAccScopeConfig_basic(), Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName, &scope), + testAccCheckScopeExists(ctx, resourceName), acctest.CheckResourceAttrRegionalARN(ctx, resourceName, names.AttrARN, "networkflowmonitor", "scope/*"), resource.TestCheckResourceAttrSet(resourceName, "scope_id"), resource.TestCheckResourceAttrSet(resourceName, names.AttrStatus), @@ -67,7 +65,6 @@ func testAccNetworkFlowMonitorScope_basic(t *testing.T) { func testAccNetworkFlowMonitorScope_disappears(t *testing.T) { ctx := acctest.Context(t) - var scope networkflowmonitor.GetScopeOutput resourceName := "aws_networkflowmonitor_scope.test" resource.Test(t, resource.TestCase{ @@ -82,7 +79,7 @@ func testAccNetworkFlowMonitorScope_disappears(t *testing.T) { { Config: testAccScopeConfig_basic(), Check: resource.ComposeTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName, &scope), + testAccCheckScopeExists(ctx, resourceName), acctest.CheckFrameworkResourceDisappears(ctx, acctest.Provider, tfnetworkflowmonitor.ResourceScope, resourceName), ), ExpectNonEmptyPlan: true, @@ -93,7 +90,6 @@ func testAccNetworkFlowMonitorScope_disappears(t *testing.T) { func testAccNetworkFlowMonitorScope_tags(t *testing.T) { ctx := acctest.Context(t) - var scope networkflowmonitor.GetScopeOutput resourceName := "aws_networkflowmonitor_scope.test" resource.Test(t, resource.TestCase{ @@ -108,7 +104,7 @@ func testAccNetworkFlowMonitorScope_tags(t *testing.T) { { Config: testAccScopeConfig_tags1(acctest.CtKey1, acctest.CtValue1), Check: resource.ComposeTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName, &scope), + testAccCheckScopeExists(ctx, resourceName), resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "1"), resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey1, acctest.CtValue1), ), @@ -119,18 +115,18 @@ func testAccNetworkFlowMonitorScope_tags(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccScopeConfig_tags2(acctest.CtKey1, "value1updated", acctest.CtKey2, acctest.CtValue2), + Config: testAccScopeConfig_tags2(acctest.CtKey1, acctest.CtValue1Updated, acctest.CtKey2, acctest.CtValue2), Check: resource.ComposeTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName, &scope), + testAccCheckScopeExists(ctx, resourceName), resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "2"), - resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey1, "value1updated"), + resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey1, acctest.CtValue1Updated), resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey2, acctest.CtValue2), ), }, { Config: testAccScopeConfig_tags1(acctest.CtKey2, acctest.CtValue2), Check: resource.ComposeTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName, &scope), + testAccCheckScopeExists(ctx, resourceName), resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "1"), resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey2, acctest.CtValue2), ), @@ -139,7 +135,7 @@ func testAccNetworkFlowMonitorScope_tags(t *testing.T) { }) } -func testAccCheckScopeExists(ctx context.Context, n string, v *networkflowmonitor.GetScopeOutput) resource.TestCheckFunc { +func testAccCheckScopeExists(ctx context.Context, n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -148,15 +144,9 @@ func testAccCheckScopeExists(ctx context.Context, n string, v *networkflowmonito conn := acctest.Provider.Meta().(*conns.AWSClient).NetworkFlowMonitorClient(ctx) - output, err := tfnetworkflowmonitor.FindScopeByID(ctx, conn, rs.Primary.Attributes["scope_id"]) + _, err := tfnetworkflowmonitor.FindScopeByID(ctx, conn, rs.Primary.Attributes["scope_id"]) - if err != nil { - return err - } - - *v = *output - - return nil + return err } } diff --git a/internal/service/networkflowmonitor/service_package_gen.go b/internal/service/networkflowmonitor/service_package_gen.go index 9bec180a0deb..86709e6d5c1e 100644 --- a/internal/service/networkflowmonitor/service_package_gen.go +++ b/internal/service/networkflowmonitor/service_package_gen.go @@ -30,6 +30,7 @@ func (p *servicePackage) FrameworkResources(ctx context.Context) []*inttypes.Ser Tags: unique.Make(inttypes.ServicePackageResourceTags{ IdentifierAttribute: names.AttrARN, }), + Region: unique.Make(inttypes.ResourceRegionDefault()), }, { Factory: newScopeResource, @@ -38,6 +39,7 @@ func (p *servicePackage) FrameworkResources(ctx context.Context) []*inttypes.Ser Tags: unique.Make(inttypes.ServicePackageResourceTags{ IdentifierAttribute: names.AttrARN, }), + Region: unique.Make(inttypes.ResourceRegionDefault()), }, } } diff --git a/internal/service/networkflowmonitor/tags_gen_test.go b/internal/service/networkflowmonitor/tags_gen_test.go new file mode 100644 index 000000000000..88465be11f11 --- /dev/null +++ b/internal/service/networkflowmonitor/tags_gen_test.go @@ -0,0 +1,16 @@ +// Code generated by internal/generate/tagstests/main.go; DO NOT EDIT. + +package networkflowmonitor_test + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-testing/knownvalue" + "github.com/hashicorp/terraform-plugin-testing/statecheck" + tfstatecheck "github.com/hashicorp/terraform-provider-aws/internal/acctest/statecheck" + tfnetworkflowmonitor "github.com/hashicorp/terraform-provider-aws/internal/service/networkflowmonitor" +) + +func expectFullResourceTags(ctx context.Context, resourceAddress string, knownValue knownvalue.Check) statecheck.StateCheck { + return tfstatecheck.ExpectFullResourceTags(tfnetworkflowmonitor.ServicePackage(ctx), resourceAddress, knownValue) +} diff --git a/internal/service/networkflowmonitor/testdata/Monitor/tags/main_gen.tf b/internal/service/networkflowmonitor/testdata/Monitor/tags/main_gen.tf new file mode 100644 index 000000000000..19d756c0992c --- /dev/null +++ b/internal/service/networkflowmonitor/testdata/Monitor/tags/main_gen.tf @@ -0,0 +1,52 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + +data "aws_caller_identity" "current" {} +data "aws_region" "current" {} + +resource "aws_vpc" "test" { + cidr_block = "10.0.0.0/16" + + tags = { + Name = var.rName + } +} + +resource "aws_networkflowmonitor_scope" "test" { + targets { + region = data.aws_region.current.name + target_identifier { + target_id = data.aws_caller_identity.current.account_id + target_type = "ACCOUNT" + } + } +} + +resource "aws_networkflowmonitor_monitor" "test" { + monitor_name = var.rName + scope_arn = aws_networkflowmonitor_scope.test.arn + + local_resources { + type = "AWS::EC2::VPC" + identifier = aws_vpc.test.arn + } + + remote_resources { + type = "AWS::EC2::VPC" + identifier = aws_vpc.test.arn + } + + tags = var.resource_tags +} +variable "rName" { + description = "Name for resource" + type = string + nullable = false +} + +variable "resource_tags" { + description = "Tags to set on resource. To specify no tags, set to `null`" + # Not setting a default, so that this must explicitly be set to `null` to specify no tags + type = map(string) + nullable = true +} diff --git a/internal/service/networkflowmonitor/testdata/Monitor/tagsComputed1/main_gen.tf b/internal/service/networkflowmonitor/testdata/Monitor/tagsComputed1/main_gen.tf new file mode 100644 index 000000000000..79c50bcf2090 --- /dev/null +++ b/internal/service/networkflowmonitor/testdata/Monitor/tagsComputed1/main_gen.tf @@ -0,0 +1,56 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + +provider "null" {} + +data "aws_caller_identity" "current" {} +data "aws_region" "current" {} + +resource "aws_vpc" "test" { + cidr_block = "10.0.0.0/16" + + tags = { + Name = var.rName + } +} + +resource "aws_networkflowmonitor_scope" "test" { + targets { + region = data.aws_region.current.name + target_identifier { + target_id = data.aws_caller_identity.current.account_id + target_type = "ACCOUNT" + } + } +} + +resource "aws_networkflowmonitor_monitor" "test" { + monitor_name = var.rName + scope_arn = aws_networkflowmonitor_scope.test.arn + + local_resources { + type = "AWS::EC2::VPC" + identifier = aws_vpc.test.arn + } + + remote_resources { + type = "AWS::EC2::VPC" + identifier = aws_vpc.test.arn + } + + tags = { + (var.unknownTagKey) = null_resource.test.id + } +} +resource "null_resource" "test" {} + +variable "rName" { + description = "Name for resource" + type = string + nullable = false +} + +variable "unknownTagKey" { + type = string + nullable = false +} diff --git a/internal/service/networkflowmonitor/testdata/Monitor/tagsComputed2/main_gen.tf b/internal/service/networkflowmonitor/testdata/Monitor/tagsComputed2/main_gen.tf new file mode 100644 index 000000000000..0a5c21a20fd6 --- /dev/null +++ b/internal/service/networkflowmonitor/testdata/Monitor/tagsComputed2/main_gen.tf @@ -0,0 +1,67 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + +provider "null" {} + +data "aws_caller_identity" "current" {} +data "aws_region" "current" {} + +resource "aws_vpc" "test" { + cidr_block = "10.0.0.0/16" + + tags = { + Name = var.rName + } +} + +resource "aws_networkflowmonitor_scope" "test" { + targets { + region = data.aws_region.current.name + target_identifier { + target_id = data.aws_caller_identity.current.account_id + target_type = "ACCOUNT" + } + } +} + +resource "aws_networkflowmonitor_monitor" "test" { + monitor_name = var.rName + scope_arn = aws_networkflowmonitor_scope.test.arn + + local_resources { + type = "AWS::EC2::VPC" + identifier = aws_vpc.test.arn + } + + remote_resources { + type = "AWS::EC2::VPC" + identifier = aws_vpc.test.arn + } + + tags = { + (var.unknownTagKey) = null_resource.test.id + (var.knownTagKey) = var.knownTagValue + } +} +resource "null_resource" "test" {} + +variable "rName" { + description = "Name for resource" + type = string + nullable = false +} + +variable "unknownTagKey" { + type = string + nullable = false +} + +variable "knownTagKey" { + type = string + nullable = false +} + +variable "knownTagValue" { + type = string + nullable = false +} diff --git a/internal/service/networkflowmonitor/testdata/Monitor/tags_defaults/main_gen.tf b/internal/service/networkflowmonitor/testdata/Monitor/tags_defaults/main_gen.tf new file mode 100644 index 000000000000..c9d7a76daac5 --- /dev/null +++ b/internal/service/networkflowmonitor/testdata/Monitor/tags_defaults/main_gen.tf @@ -0,0 +1,63 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + +provider "aws" { + default_tags { + tags = var.provider_tags + } +} + +data "aws_caller_identity" "current" {} +data "aws_region" "current" {} + +resource "aws_vpc" "test" { + cidr_block = "10.0.0.0/16" + + tags = { + Name = var.rName + } +} + +resource "aws_networkflowmonitor_scope" "test" { + targets { + region = data.aws_region.current.name + target_identifier { + target_id = data.aws_caller_identity.current.account_id + target_type = "ACCOUNT" + } + } +} + +resource "aws_networkflowmonitor_monitor" "test" { + monitor_name = var.rName + scope_arn = aws_networkflowmonitor_scope.test.arn + + local_resources { + type = "AWS::EC2::VPC" + identifier = aws_vpc.test.arn + } + + remote_resources { + type = "AWS::EC2::VPC" + identifier = aws_vpc.test.arn + } + + tags = var.resource_tags +} +variable "rName" { + description = "Name for resource" + type = string + nullable = false +} + +variable "resource_tags" { + description = "Tags to set on resource. To specify no tags, set to `null`" + # Not setting a default, so that this must explicitly be set to `null` to specify no tags + type = map(string) + nullable = true +} + +variable "provider_tags" { + type = map(string) + nullable = false +} diff --git a/internal/service/networkflowmonitor/testdata/Monitor/tags_ignore/main_gen.tf b/internal/service/networkflowmonitor/testdata/Monitor/tags_ignore/main_gen.tf new file mode 100644 index 000000000000..12129342a6f6 --- /dev/null +++ b/internal/service/networkflowmonitor/testdata/Monitor/tags_ignore/main_gen.tf @@ -0,0 +1,72 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + +provider "aws" { + default_tags { + tags = var.provider_tags + } + ignore_tags { + keys = var.ignore_tag_keys + } +} + +data "aws_caller_identity" "current" {} +data "aws_region" "current" {} + +resource "aws_vpc" "test" { + cidr_block = "10.0.0.0/16" + + tags = { + Name = var.rName + } +} + +resource "aws_networkflowmonitor_scope" "test" { + targets { + region = data.aws_region.current.name + target_identifier { + target_id = data.aws_caller_identity.current.account_id + target_type = "ACCOUNT" + } + } +} + +resource "aws_networkflowmonitor_monitor" "test" { + monitor_name = var.rName + scope_arn = aws_networkflowmonitor_scope.test.arn + + local_resources { + type = "AWS::EC2::VPC" + identifier = aws_vpc.test.arn + } + + remote_resources { + type = "AWS::EC2::VPC" + identifier = aws_vpc.test.arn + } + + tags = var.resource_tags +} +variable "rName" { + description = "Name for resource" + type = string + nullable = false +} + +variable "resource_tags" { + description = "Tags to set on resource. To specify no tags, set to `null`" + # Not setting a default, so that this must explicitly be set to `null` to specify no tags + type = map(string) + nullable = true +} + +variable "provider_tags" { + type = map(string) + nullable = true + default = null +} + +variable "ignore_tag_keys" { + type = set(string) + nullable = false +} diff --git a/internal/service/networkflowmonitor/testdata/Scope/tags/main_gen.tf b/internal/service/networkflowmonitor/testdata/Scope/tags/main_gen.tf new file mode 100644 index 000000000000..019cc9d5f57e --- /dev/null +++ b/internal/service/networkflowmonitor/testdata/Scope/tags/main_gen.tf @@ -0,0 +1,29 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + +data "aws_caller_identity" "current" {} +data "aws_region" "current" {} + +resource "aws_networkflowmonitor_scope" "test" { + targets { + region = data.aws_region.current.name + target_identifier { + target_id = data.aws_caller_identity.current.account_id + target_type = "ACCOUNT" + } + } + + tags = var.resource_tags +} +variable "rName" { + description = "Name for resource" + type = string + nullable = false +} + +variable "resource_tags" { + description = "Tags to set on resource. To specify no tags, set to `null`" + # Not setting a default, so that this must explicitly be set to `null` to specify no tags + type = map(string) + nullable = true +} diff --git a/internal/service/networkflowmonitor/testdata/Scope/tagsComputed1/main_gen.tf b/internal/service/networkflowmonitor/testdata/Scope/tagsComputed1/main_gen.tf new file mode 100644 index 000000000000..b146a4627813 --- /dev/null +++ b/internal/service/networkflowmonitor/testdata/Scope/tagsComputed1/main_gen.tf @@ -0,0 +1,33 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + +provider "null" {} + +data "aws_caller_identity" "current" {} +data "aws_region" "current" {} + +resource "aws_networkflowmonitor_scope" "test" { + targets { + region = data.aws_region.current.name + target_identifier { + target_id = data.aws_caller_identity.current.account_id + target_type = "ACCOUNT" + } + } + + tags = { + (var.unknownTagKey) = null_resource.test.id + } +} +resource "null_resource" "test" {} + +variable "rName" { + description = "Name for resource" + type = string + nullable = false +} + +variable "unknownTagKey" { + type = string + nullable = false +} diff --git a/internal/service/networkflowmonitor/testdata/Scope/tagsComputed2/main_gen.tf b/internal/service/networkflowmonitor/testdata/Scope/tagsComputed2/main_gen.tf new file mode 100644 index 000000000000..29e2b0f9d293 --- /dev/null +++ b/internal/service/networkflowmonitor/testdata/Scope/tagsComputed2/main_gen.tf @@ -0,0 +1,44 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + +provider "null" {} + +data "aws_caller_identity" "current" {} +data "aws_region" "current" {} + +resource "aws_networkflowmonitor_scope" "test" { + targets { + region = data.aws_region.current.name + target_identifier { + target_id = data.aws_caller_identity.current.account_id + target_type = "ACCOUNT" + } + } + + tags = { + (var.unknownTagKey) = null_resource.test.id + (var.knownTagKey) = var.knownTagValue + } +} +resource "null_resource" "test" {} + +variable "rName" { + description = "Name for resource" + type = string + nullable = false +} + +variable "unknownTagKey" { + type = string + nullable = false +} + +variable "knownTagKey" { + type = string + nullable = false +} + +variable "knownTagValue" { + type = string + nullable = false +} diff --git a/internal/service/networkflowmonitor/testdata/Scope/tags_defaults/main_gen.tf b/internal/service/networkflowmonitor/testdata/Scope/tags_defaults/main_gen.tf new file mode 100644 index 000000000000..0bd9d41e2abd --- /dev/null +++ b/internal/service/networkflowmonitor/testdata/Scope/tags_defaults/main_gen.tf @@ -0,0 +1,40 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + +provider "aws" { + default_tags { + tags = var.provider_tags + } +} + +data "aws_caller_identity" "current" {} +data "aws_region" "current" {} + +resource "aws_networkflowmonitor_scope" "test" { + targets { + region = data.aws_region.current.name + target_identifier { + target_id = data.aws_caller_identity.current.account_id + target_type = "ACCOUNT" + } + } + + tags = var.resource_tags +} +variable "rName" { + description = "Name for resource" + type = string + nullable = false +} + +variable "resource_tags" { + description = "Tags to set on resource. To specify no tags, set to `null`" + # Not setting a default, so that this must explicitly be set to `null` to specify no tags + type = map(string) + nullable = true +} + +variable "provider_tags" { + type = map(string) + nullable = false +} diff --git a/internal/service/networkflowmonitor/testdata/Scope/tags_ignore/main_gen.tf b/internal/service/networkflowmonitor/testdata/Scope/tags_ignore/main_gen.tf new file mode 100644 index 000000000000..524bd938a82e --- /dev/null +++ b/internal/service/networkflowmonitor/testdata/Scope/tags_ignore/main_gen.tf @@ -0,0 +1,49 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + +provider "aws" { + default_tags { + tags = var.provider_tags + } + ignore_tags { + keys = var.ignore_tag_keys + } +} + +data "aws_caller_identity" "current" {} +data "aws_region" "current" {} + +resource "aws_networkflowmonitor_scope" "test" { + targets { + region = data.aws_region.current.name + target_identifier { + target_id = data.aws_caller_identity.current.account_id + target_type = "ACCOUNT" + } + } + + tags = var.resource_tags +} +variable "rName" { + description = "Name for resource" + type = string + nullable = false +} + +variable "resource_tags" { + description = "Tags to set on resource. To specify no tags, set to `null`" + # Not setting a default, so that this must explicitly be set to `null` to specify no tags + type = map(string) + nullable = true +} + +variable "provider_tags" { + type = map(string) + nullable = true + default = null +} + +variable "ignore_tag_keys" { + type = set(string) + nullable = false +} diff --git a/internal/service/networkflowmonitor/testdata/tmpl/monitor_tags.gtpl b/internal/service/networkflowmonitor/testdata/tmpl/monitor_tags.gtpl new file mode 100644 index 000000000000..2826c1295e42 --- /dev/null +++ b/internal/service/networkflowmonitor/testdata/tmpl/monitor_tags.gtpl @@ -0,0 +1,36 @@ +data "aws_caller_identity" "current" {} +data "aws_region" "current" {} + +resource "aws_vpc" "test" { + cidr_block = "10.0.0.0/16" + + tags = { + Name = var.rName + } +} + +resource "aws_networkflowmonitor_scope" "test" { + targets { + region = data.aws_region.current.name + target_identifier { + target_id = data.aws_caller_identity.current.account_id + target_type = "ACCOUNT" + } + } +} + +resource "aws_networkflowmonitor_monitor" "test" { + monitor_name = var.rName + scope_arn = aws_networkflowmonitor_scope.test.arn + + local_resources { + type = "AWS::EC2::VPC" + identifier = aws_vpc.test.arn + } + + remote_resources { + type = "AWS::EC2::VPC" + identifier = aws_vpc.test.arn + } +{{- template "tags" . }} +} \ No newline at end of file diff --git a/internal/service/networkflowmonitor/testdata/tmpl/scope_tags.gtpl b/internal/service/networkflowmonitor/testdata/tmpl/scope_tags.gtpl new file mode 100644 index 000000000000..b75524325a70 --- /dev/null +++ b/internal/service/networkflowmonitor/testdata/tmpl/scope_tags.gtpl @@ -0,0 +1,13 @@ +data "aws_caller_identity" "current" {} +data "aws_region" "current" {} + +resource "aws_networkflowmonitor_scope" "test" { + targets { + region = data.aws_region.current.name + target_identifier { + target_id = data.aws_caller_identity.current.account_id + target_type = "ACCOUNT" + } + } +{{- template "tags" . }} +} \ No newline at end of file diff --git a/website/docs/r/networkflowmonitor_monitor.html.markdown b/website/docs/r/networkflowmonitor_monitor.html.markdown index a87becf2d5d1..5bafe30ae8c3 100644 --- a/website/docs/r/networkflowmonitor_monitor.html.markdown +++ b/website/docs/r/networkflowmonitor_monitor.html.markdown @@ -45,11 +45,15 @@ resource "aws_networkflowmonitor_monitor" "example" { ## Argument Reference -This resource supports the following arguments: +The following arguments are required: * `monitor_name` - (Required) The name of the monitor. Cannot be changed after creation. * `scope_arn` - (Required) The Amazon Resource Name (ARN) of the scope for the monitor. Cannot be changed after creation. + +The following arguments are optional: + * `local_resources` - (Optional) The local resources to monitor. A local resource in a workload is the location of the hosts where the Network Flow Monitor agent is installed. +* `region` - (Optional) Region where this resource will be [managed](https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints). Defaults to the Region set in the [provider configuration](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#aws-configuration-reference). * `remote_resources` - (Optional) The remote resources to monitor. A remote resource is the other endpoint specified for the network flow of a workload, with a local resource. * `tags` - (Optional) A 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. diff --git a/website/docs/r/networkflowmonitor_scope.html.markdown b/website/docs/r/networkflowmonitor_scope.html.markdown index ab007e1ac94e..47977a2391d1 100644 --- a/website/docs/r/networkflowmonitor_scope.html.markdown +++ b/website/docs/r/networkflowmonitor_scope.html.markdown @@ -34,9 +34,12 @@ resource "aws_networkflowmonitor_scope" "example" { ## Argument Reference -This resource supports the following arguments: +The following arguments are required: * `targets` - (Required) The targets to define the scope to be monitored. A target is an array of target resources, which are currently Region-account pairs. + +The following arguments are optional: +* `region` - (Optional) Region where this resource will be [managed](https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints). Defaults to the Region set in the [provider configuration](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#aws-configuration-reference). * `tags` - (Optional) A 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. ### targets From 8516df58f14c661798c82f37c193e7b69305cc9d Mon Sep 17 00:00:00 2001 From: Sasi Date: Wed, 5 Nov 2025 22:50:05 -0500 Subject: [PATCH 06/21] region parameter issue fixed --- internal/service/networkflowmonitor/monitor.go | 1 + internal/service/networkflowmonitor/scope.go | 1 + internal/service/networkflowmonitor/scope_test.go | 3 ++- website/docs/r/networkflowmonitor_scope.html.markdown | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/service/networkflowmonitor/monitor.go b/internal/service/networkflowmonitor/monitor.go index 2d201bd870b0..a23849bba5b2 100644 --- a/internal/service/networkflowmonitor/monitor.go +++ b/internal/service/networkflowmonitor/monitor.go @@ -118,6 +118,7 @@ func (r *monitorResource) Schema(ctx context.Context, request resource.SchemaReq } type monitorResourceModel struct { + framework.WithRegionModel ARN types.String `tfsdk:"arn"` ID types.String `tfsdk:"id"` MonitorName types.String `tfsdk:"monitor_name"` diff --git a/internal/service/networkflowmonitor/scope.go b/internal/service/networkflowmonitor/scope.go index b5d7a5ae0204..8693d3e37190 100644 --- a/internal/service/networkflowmonitor/scope.go +++ b/internal/service/networkflowmonitor/scope.go @@ -108,6 +108,7 @@ func (r *scopeResource) Schema(ctx context.Context, request resource.SchemaReque } type scopeResourceModel struct { + framework.WithRegionModel ARN types.String `tfsdk:"arn"` ID types.String `tfsdk:"id"` ScopeId types.String `tfsdk:"scope_id"` diff --git a/internal/service/networkflowmonitor/scope_test.go b/internal/service/networkflowmonitor/scope_test.go index 8a5449b0c36c..fb8de3e45878 100644 --- a/internal/service/networkflowmonitor/scope_test.go +++ b/internal/service/networkflowmonitor/scope_test.go @@ -8,6 +8,7 @@ import ( "fmt" "testing" + "github.com/YakDriver/regexache" awstypes "github.com/aws/aws-sdk-go-v2/service/networkflowmonitor/types" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -49,7 +50,7 @@ func testAccNetworkFlowMonitorScope_basic(t *testing.T) { Config: testAccScopeConfig_basic(), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckScopeExists(ctx, resourceName), - acctest.CheckResourceAttrRegionalARN(ctx, resourceName, names.AttrARN, "networkflowmonitor", "scope/*"), + resource.TestMatchResourceAttr(resourceName, names.AttrARN, regexache.MustCompile(`^arn:[^:]+:networkflowmonitor:[^:]+:[^:]+:scope/.+$`)), resource.TestCheckResourceAttrSet(resourceName, "scope_id"), resource.TestCheckResourceAttrSet(resourceName, names.AttrStatus), ), diff --git a/website/docs/r/networkflowmonitor_scope.html.markdown b/website/docs/r/networkflowmonitor_scope.html.markdown index 47977a2391d1..89ff253cf286 100644 --- a/website/docs/r/networkflowmonitor_scope.html.markdown +++ b/website/docs/r/networkflowmonitor_scope.html.markdown @@ -39,6 +39,7 @@ The following arguments are required: * `targets` - (Required) The targets to define the scope to be monitored. A target is an array of target resources, which are currently Region-account pairs. The following arguments are optional: + * `region` - (Optional) Region where this resource will be [managed](https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints). Defaults to the Region set in the [provider configuration](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#aws-configuration-reference). * `tags` - (Optional) A 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. From 5296685f0f969a6a8a6fdac0b0e79e4a4756b6a8 Mon Sep 17 00:00:00 2001 From: Sasi Date: Wed, 5 Nov 2025 23:05:04 -0500 Subject: [PATCH 07/21] removed unused variable definition --- .../networkflowmonitor/testdata/Scope/tags/main_gen.tf | 6 +----- .../testdata/Scope/tagsComputed1/main_gen.tf | 5 ----- .../testdata/Scope/tagsComputed2/main_gen.tf | 5 ----- .../testdata/Scope/tags_defaults/main_gen.tf | 6 +----- .../testdata/Scope/tags_ignore/main_gen.tf | 6 +----- 5 files changed, 3 insertions(+), 25 deletions(-) diff --git a/internal/service/networkflowmonitor/testdata/Scope/tags/main_gen.tf b/internal/service/networkflowmonitor/testdata/Scope/tags/main_gen.tf index 019cc9d5f57e..2098ddbf0bde 100644 --- a/internal/service/networkflowmonitor/testdata/Scope/tags/main_gen.tf +++ b/internal/service/networkflowmonitor/testdata/Scope/tags/main_gen.tf @@ -15,11 +15,7 @@ resource "aws_networkflowmonitor_scope" "test" { tags = var.resource_tags } -variable "rName" { - description = "Name for resource" - type = string - nullable = false -} + variable "resource_tags" { description = "Tags to set on resource. To specify no tags, set to `null`" diff --git a/internal/service/networkflowmonitor/testdata/Scope/tagsComputed1/main_gen.tf b/internal/service/networkflowmonitor/testdata/Scope/tagsComputed1/main_gen.tf index b146a4627813..53f959159fee 100644 --- a/internal/service/networkflowmonitor/testdata/Scope/tagsComputed1/main_gen.tf +++ b/internal/service/networkflowmonitor/testdata/Scope/tagsComputed1/main_gen.tf @@ -21,11 +21,6 @@ resource "aws_networkflowmonitor_scope" "test" { } resource "null_resource" "test" {} -variable "rName" { - description = "Name for resource" - type = string - nullable = false -} variable "unknownTagKey" { type = string diff --git a/internal/service/networkflowmonitor/testdata/Scope/tagsComputed2/main_gen.tf b/internal/service/networkflowmonitor/testdata/Scope/tagsComputed2/main_gen.tf index 29e2b0f9d293..34d06396836c 100644 --- a/internal/service/networkflowmonitor/testdata/Scope/tagsComputed2/main_gen.tf +++ b/internal/service/networkflowmonitor/testdata/Scope/tagsComputed2/main_gen.tf @@ -22,11 +22,6 @@ resource "aws_networkflowmonitor_scope" "test" { } resource "null_resource" "test" {} -variable "rName" { - description = "Name for resource" - type = string - nullable = false -} variable "unknownTagKey" { type = string diff --git a/internal/service/networkflowmonitor/testdata/Scope/tags_defaults/main_gen.tf b/internal/service/networkflowmonitor/testdata/Scope/tags_defaults/main_gen.tf index 0bd9d41e2abd..d83962d345f6 100644 --- a/internal/service/networkflowmonitor/testdata/Scope/tags_defaults/main_gen.tf +++ b/internal/service/networkflowmonitor/testdata/Scope/tags_defaults/main_gen.tf @@ -21,11 +21,7 @@ resource "aws_networkflowmonitor_scope" "test" { tags = var.resource_tags } -variable "rName" { - description = "Name for resource" - type = string - nullable = false -} + variable "resource_tags" { description = "Tags to set on resource. To specify no tags, set to `null`" diff --git a/internal/service/networkflowmonitor/testdata/Scope/tags_ignore/main_gen.tf b/internal/service/networkflowmonitor/testdata/Scope/tags_ignore/main_gen.tf index 524bd938a82e..5ae317016b7c 100644 --- a/internal/service/networkflowmonitor/testdata/Scope/tags_ignore/main_gen.tf +++ b/internal/service/networkflowmonitor/testdata/Scope/tags_ignore/main_gen.tf @@ -24,11 +24,7 @@ resource "aws_networkflowmonitor_scope" "test" { tags = var.resource_tags } -variable "rName" { - description = "Name for resource" - type = string - nullable = false -} + variable "resource_tags" { description = "Tags to set on resource. To specify no tags, set to `null`" From b05480fd80e527168a50ddc70163c136e3f525da Mon Sep 17 00:00:00 2001 From: Sasi Date: Wed, 5 Nov 2025 23:38:50 -0500 Subject: [PATCH 08/21] added variable definition, which is needed --- .../networkflowmonitor/testdata/Scope/tags/main_gen.tf | 7 ++++++- .../testdata/Scope/tagsComputed1/main_gen.tf | 6 ++++++ .../testdata/Scope/tagsComputed2/main_gen.tf | 6 ++++++ .../testdata/Scope/tags_defaults/main_gen.tf | 7 ++++++- .../testdata/Scope/tags_ignore/main_gen.tf | 7 ++++++- .../networkflowmonitor/testdata/tmpl/scope_tags.gtpl | 1 + 6 files changed, 31 insertions(+), 3 deletions(-) diff --git a/internal/service/networkflowmonitor/testdata/Scope/tags/main_gen.tf b/internal/service/networkflowmonitor/testdata/Scope/tags/main_gen.tf index 2098ddbf0bde..5e82d15050e5 100644 --- a/internal/service/networkflowmonitor/testdata/Scope/tags/main_gen.tf +++ b/internal/service/networkflowmonitor/testdata/Scope/tags/main_gen.tf @@ -4,6 +4,7 @@ data "aws_caller_identity" "current" {} data "aws_region" "current" {} +# Test scope for ${var.rName} resource "aws_networkflowmonitor_scope" "test" { targets { region = data.aws_region.current.name @@ -15,7 +16,11 @@ resource "aws_networkflowmonitor_scope" "test" { tags = var.resource_tags } - +variable "rName" { + description = "Name for resource" + type = string + nullable = false +} variable "resource_tags" { description = "Tags to set on resource. To specify no tags, set to `null`" diff --git a/internal/service/networkflowmonitor/testdata/Scope/tagsComputed1/main_gen.tf b/internal/service/networkflowmonitor/testdata/Scope/tagsComputed1/main_gen.tf index 53f959159fee..4ccd4147a360 100644 --- a/internal/service/networkflowmonitor/testdata/Scope/tagsComputed1/main_gen.tf +++ b/internal/service/networkflowmonitor/testdata/Scope/tagsComputed1/main_gen.tf @@ -6,6 +6,7 @@ provider "null" {} data "aws_caller_identity" "current" {} data "aws_region" "current" {} +# Test scope for ${var.rName} resource "aws_networkflowmonitor_scope" "test" { targets { region = data.aws_region.current.name @@ -21,6 +22,11 @@ resource "aws_networkflowmonitor_scope" "test" { } resource "null_resource" "test" {} +variable "rName" { + description = "Name for resource" + type = string + nullable = false +} variable "unknownTagKey" { type = string diff --git a/internal/service/networkflowmonitor/testdata/Scope/tagsComputed2/main_gen.tf b/internal/service/networkflowmonitor/testdata/Scope/tagsComputed2/main_gen.tf index 34d06396836c..9d91d8b50898 100644 --- a/internal/service/networkflowmonitor/testdata/Scope/tagsComputed2/main_gen.tf +++ b/internal/service/networkflowmonitor/testdata/Scope/tagsComputed2/main_gen.tf @@ -6,6 +6,7 @@ provider "null" {} data "aws_caller_identity" "current" {} data "aws_region" "current" {} +# Test scope for ${var.rName} resource "aws_networkflowmonitor_scope" "test" { targets { region = data.aws_region.current.name @@ -22,6 +23,11 @@ resource "aws_networkflowmonitor_scope" "test" { } resource "null_resource" "test" {} +variable "rName" { + description = "Name for resource" + type = string + nullable = false +} variable "unknownTagKey" { type = string diff --git a/internal/service/networkflowmonitor/testdata/Scope/tags_defaults/main_gen.tf b/internal/service/networkflowmonitor/testdata/Scope/tags_defaults/main_gen.tf index d83962d345f6..fedbe5a7305a 100644 --- a/internal/service/networkflowmonitor/testdata/Scope/tags_defaults/main_gen.tf +++ b/internal/service/networkflowmonitor/testdata/Scope/tags_defaults/main_gen.tf @@ -10,6 +10,7 @@ provider "aws" { data "aws_caller_identity" "current" {} data "aws_region" "current" {} +# Test scope for ${var.rName} resource "aws_networkflowmonitor_scope" "test" { targets { region = data.aws_region.current.name @@ -21,7 +22,11 @@ resource "aws_networkflowmonitor_scope" "test" { tags = var.resource_tags } - +variable "rName" { + description = "Name for resource" + type = string + nullable = false +} variable "resource_tags" { description = "Tags to set on resource. To specify no tags, set to `null`" diff --git a/internal/service/networkflowmonitor/testdata/Scope/tags_ignore/main_gen.tf b/internal/service/networkflowmonitor/testdata/Scope/tags_ignore/main_gen.tf index 5ae317016b7c..810efd5f5cfe 100644 --- a/internal/service/networkflowmonitor/testdata/Scope/tags_ignore/main_gen.tf +++ b/internal/service/networkflowmonitor/testdata/Scope/tags_ignore/main_gen.tf @@ -13,6 +13,7 @@ provider "aws" { data "aws_caller_identity" "current" {} data "aws_region" "current" {} +# Test scope for ${var.rName} resource "aws_networkflowmonitor_scope" "test" { targets { region = data.aws_region.current.name @@ -24,7 +25,11 @@ resource "aws_networkflowmonitor_scope" "test" { tags = var.resource_tags } - +variable "rName" { + description = "Name for resource" + type = string + nullable = false +} variable "resource_tags" { description = "Tags to set on resource. To specify no tags, set to `null`" diff --git a/internal/service/networkflowmonitor/testdata/tmpl/scope_tags.gtpl b/internal/service/networkflowmonitor/testdata/tmpl/scope_tags.gtpl index b75524325a70..028909ea5ddf 100644 --- a/internal/service/networkflowmonitor/testdata/tmpl/scope_tags.gtpl +++ b/internal/service/networkflowmonitor/testdata/tmpl/scope_tags.gtpl @@ -1,6 +1,7 @@ data "aws_caller_identity" "current" {} data "aws_region" "current" {} +# Test scope for ${var.rName} resource "aws_networkflowmonitor_scope" "test" { targets { region = data.aws_region.current.name From 65d7bcf7914afa7cf3531823574a7642d46885d4 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 11 Nov 2025 13:15:24 -0500 Subject: [PATCH 09/21] r/aws_networkflowmonitor_scope: 'targets' -> 'target'. --- internal/service/networkflowmonitor/scope.go | 465 ++++++------------ .../service/networkflowmonitor/scope_test.go | 18 +- .../networkflowmonitor/service_package_gen.go | 2 +- .../r/networkflowmonitor_scope.html.markdown | 26 +- 4 files changed, 180 insertions(+), 331 deletions(-) diff --git a/internal/service/networkflowmonitor/scope.go b/internal/service/networkflowmonitor/scope.go index 8693d3e37190..9ee58bf4b442 100644 --- a/internal/service/networkflowmonitor/scope.go +++ b/internal/service/networkflowmonitor/scope.go @@ -6,14 +6,11 @@ package networkflowmonitor import ( "context" "fmt" - "strings" "time" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/networkflowmonitor" awstypes "github.com/aws/aws-sdk-go-v2/service/networkflowmonitor/types" - "github.com/google/uuid" "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "github.com/hashicorp/terraform-plugin-framework/diag" @@ -22,19 +19,22 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/schema/validator" "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/enum" "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" + fwvalidators "github.com/hashicorp/terraform-provider-aws/internal/framework/validators" 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_networkflowmonitor_scope", name="Scope") -// @Tags(identifierAttribute="arn") +// @Tags(identifierAttribute="scope_arn") func newScopeResource(_ context.Context) (resource.ResourceWithConfigure, error) { r := &scopeResource{} @@ -46,7 +46,6 @@ func newScopeResource(_ context.Context) (resource.ResourceWithConfigure, error) } type scopeResource struct { - framework.ResourceWithConfigure framework.ResourceWithModel[scopeResourceModel] framework.WithTimeouts } @@ -54,43 +53,60 @@ type scopeResource struct { func (r *scopeResource) Schema(ctx context.Context, request resource.SchemaRequest, response *resource.SchemaResponse) { response.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ - names.AttrARN: framework.ARNAttributeComputedOnly(), - names.AttrID: framework.IDAttribute(), - "scope_id": schema.StringAttribute{ - Computed: true, - }, - names.AttrStatus: schema.StringAttribute{ - Computed: true, - }, + "scope_arn": framework.ARNAttributeComputedOnly(), + "scope_id": framework.IDAttribute(), names.AttrTags: tftags.TagsAttribute(), names.AttrTagsAll: tftags.TagsAttributeComputedOnly(), }, Blocks: map[string]schema.Block{ - "targets": schema.ListNestedBlock{ + "target": schema.ListNestedBlock{ CustomType: fwtypes.NewListNestedObjectTypeOf[targetResourceModel](ctx), Validators: []validator.List{ listvalidator.SizeAtLeast(1), + listvalidator.IsRequired(), }, NestedObject: schema.NestedBlockObject{ Attributes: map[string]schema.Attribute{ names.AttrRegion: schema.StringAttribute{ Required: true, + Validators: []validator.String{ + fwvalidators.AWSRegion(), + }, }, }, Blocks: map[string]schema.Block{ "target_identifier": schema.ListNestedBlock{ CustomType: fwtypes.NewListNestedObjectTypeOf[targetIdentifierModel](ctx), Validators: []validator.List{ + listvalidator.SizeAtLeast(1), listvalidator.SizeAtMost(1), listvalidator.IsRequired(), }, NestedObject: schema.NestedBlockObject{ Attributes: map[string]schema.Attribute{ - "target_id": schema.StringAttribute{ - Required: true, - }, "target_type": schema.StringAttribute{ - Required: true, + CustomType: fwtypes.StringEnumType[awstypes.TargetType](), + Required: true, + }, + }, + Blocks: map[string]schema.Block{ + "target_id": schema.ListNestedBlock{ + CustomType: fwtypes.NewListNestedObjectTypeOf[targetIdModel](ctx), + Validators: []validator.List{ + listvalidator.SizeAtLeast(1), + listvalidator.SizeAtMost(1), + listvalidator.IsRequired(), + }, + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "account_id": schema.StringAttribute{ + Required: true, + Validators: []validator.String{ + fwvalidators.AWSAccountID(), + }, + }, + }, + }, }, }, }, @@ -107,28 +123,6 @@ func (r *scopeResource) Schema(ctx context.Context, request resource.SchemaReque } } -type scopeResourceModel struct { - framework.WithRegionModel - ARN types.String `tfsdk:"arn"` - ID types.String `tfsdk:"id"` - ScopeId types.String `tfsdk:"scope_id"` - Status types.String `tfsdk:"status"` - Targets fwtypes.ListNestedObjectValueOf[targetResourceModel] `tfsdk:"targets"` - Tags tftags.Map `tfsdk:"tags"` - TagsAll tftags.Map `tfsdk:"tags_all"` - Timeouts timeouts.Value `tfsdk:"timeouts"` -} - -type targetResourceModel struct { - Region types.String `tfsdk:"region"` - TargetIdentifier fwtypes.ListNestedObjectValueOf[targetIdentifierModel] `tfsdk:"target_identifier"` -} - -type targetIdentifierModel struct { - TargetId types.String `tfsdk:"target_id"` - TargetType types.String `tfsdk:"target_type"` -} - func (r *scopeResource) Create(ctx context.Context, request resource.CreateRequest, response *resource.CreateResponse) { var data scopeResourceModel response.Diagnostics.Append(request.Plan.Get(ctx, &data)...) @@ -138,110 +132,33 @@ func (r *scopeResource) Create(ctx context.Context, request resource.CreateReque conn := r.Meta().NetworkFlowMonitorClient(ctx) - // Manual parameter mapping (AutoFlex can't handle union types) - input := networkflowmonitor.CreateScopeInput{} - - // Map targets manually since they contain union types - if !data.Targets.IsNull() && !data.Targets.IsUnknown() { - targets, diags := data.Targets.ToSlice(ctx) - response.Diagnostics.Append(diags...) - if response.Diagnostics.HasError() { - return - } - - input.Targets = make([]awstypes.TargetResource, len(targets)) - for i, target := range targets { - input.Targets[i].Region = target.Region.ValueStringPointer() - - if !target.TargetIdentifier.IsNull() && !target.TargetIdentifier.IsUnknown() { - targetIds, diags := target.TargetIdentifier.ToSlice(ctx) - response.Diagnostics.Append(diags...) - if response.Diagnostics.HasError() { - return - } - - if len(targetIds) > 0 { - targetId := targetIds[0] - input.Targets[i].TargetIdentifier = &awstypes.TargetIdentifier{ - TargetId: &awstypes.TargetIdMemberAccountId{ - Value: targetId.TargetId.ValueString(), - }, - TargetType: awstypes.TargetType(targetId.TargetType.ValueString()), - } - } - } - } + var input networkflowmonitor.CreateScopeInput + response.Diagnostics.Append(fwflex.Expand(ctx, data, &input)...) + if response.Diagnostics.HasError() { + return } - // Set additional fields that need special handling - input.ClientToken = aws.String(uuid.New().String()) + // Additional fields. + input.ClientToken = aws.String(sdkid.UniqueId()) input.Tags = getTagsIn(ctx) output, err := conn.CreateScope(ctx, &input) + if err != nil { response.Diagnostics.AddError("creating Network Flow Monitor Scope", err.Error()) return } - // Set ID and computed attributes from create output - data.ID = types.StringValue(aws.ToString(output.ScopeArn)) - data.ARN = types.StringValue(aws.ToString(output.ScopeArn)) + // Set values for unknowns. + data.ScopeARN = fwflex.StringToFramework(ctx, output.ScopeArn) + data.ScopeID = fwflex.StringToFramework(ctx, output.ScopeId) - // Wait for scope to be ready - scope, err := waitScopeCreated(ctx, conn, aws.ToString(output.ScopeId), r.CreateTimeout(ctx, data.Timeouts)) - if err != nil { - response.Diagnostics.AddError(fmt.Sprintf("waiting for Network Flow Monitor Scope (%s) create", data.ID.ValueString()), err.Error()) + scopeID := fwflex.StringValueFromFramework(ctx, data.ScopeID) + if _, err := waitScopeCreated(ctx, conn, scopeID, r.CreateTimeout(ctx, data.Timeouts)); err != nil { + response.Diagnostics.AddError(fmt.Sprintf("waiting for Network Flow Monitor Scope (%s) create", scopeID), err.Error()) return } - // Set all attributes from final scope state manually - data.ScopeId = types.StringValue(aws.ToString(scope.ScopeId)) - data.Status = types.StringValue(string(scope.Status)) - - // Handle targets with union types manually - if len(scope.Targets) > 0 { - targetModels := make([]targetResourceModel, len(scope.Targets)) - for i, target := range scope.Targets { - targetModels[i].Region = types.StringValue(aws.ToString(target.Region)) - - if target.TargetIdentifier != nil { - var targetIdValue string - if accountId, ok := target.TargetIdentifier.TargetId.(*awstypes.TargetIdMemberAccountId); ok { - targetIdValue = accountId.Value - } - - targetIdModel := targetIdentifierModel{ - TargetId: types.StringValue(targetIdValue), - TargetType: types.StringValue(string(target.TargetIdentifier.TargetType)), - } - - targetIdentifierList, diags := fwtypes.NewListNestedObjectValueOfValueSlice(ctx, []targetIdentifierModel{targetIdModel}) - response.Diagnostics.Append(diags...) - if response.Diagnostics.HasError() { - return - } - targetModels[i].TargetIdentifier = targetIdentifierList - } - } - - targetsList, diags := fwtypes.NewListNestedObjectValueOfValueSlice(ctx, targetModels) - response.Diagnostics.Append(diags...) - if response.Diagnostics.HasError() { - return - } - data.Targets = targetsList - } - - // Set tags - preserve the original plan's tags state - // If tags were null in the plan, keep them null in the state - if !data.Tags.IsNull() { - tags := tftags.New(ctx, scope.Tags) - data.Tags = tftags.FlattenStringValueMap(ctx, tags.Map()) - } - // TagsAll should always reflect the actual AWS state - tags := tftags.New(ctx, scope.Tags) - data.TagsAll = tftags.FlattenStringValueMap(ctx, tags.Map()) - response.Diagnostics.Append(response.State.Set(ctx, data)...) } @@ -254,7 +171,8 @@ func (r *scopeResource) Read(ctx context.Context, request resource.ReadRequest, conn := r.Meta().NetworkFlowMonitorClient(ctx) - output, err := findScopeByID(ctx, conn, data.ScopeId.ValueString()) + scopeID := fwflex.StringValueFromFramework(ctx, data.ScopeID) + output, err := findScopeByID(ctx, conn, scopeID) if tfresource.NotFound(err) { response.Diagnostics.Append(fwdiag.NewResourceNotFoundWarningDiagnostic(err)) @@ -263,61 +181,13 @@ func (r *scopeResource) Read(ctx context.Context, request resource.ReadRequest, } if err != nil { - response.Diagnostics.AddError(fmt.Sprintf("reading Network Flow Monitor Scope (%s)", data.ID.ValueString()), err.Error()) + response.Diagnostics.AddError(fmt.Sprintf("reading Network Flow Monitor Scope (%s)", scopeID), err.Error()) return } - // Manual parameter mapping (AutoFlex can't handle union types) - // Set basic attributes - data.ID = types.StringValue(aws.ToString(output.ScopeArn)) - data.ARN = types.StringValue(aws.ToString(output.ScopeArn)) - data.ScopeId = types.StringValue(aws.ToString(output.ScopeId)) - data.Status = types.StringValue(string(output.Status)) - - // Handle targets with union types manually - if len(output.Targets) > 0 { - targetModels := make([]targetResourceModel, len(output.Targets)) - for i, target := range output.Targets { - targetModels[i].Region = types.StringValue(aws.ToString(target.Region)) - - if target.TargetIdentifier != nil { - var targetIdValue string - if accountId, ok := target.TargetIdentifier.TargetId.(*awstypes.TargetIdMemberAccountId); ok { - targetIdValue = accountId.Value - } - - targetIdModel := targetIdentifierModel{ - TargetId: types.StringValue(targetIdValue), - TargetType: types.StringValue(string(target.TargetIdentifier.TargetType)), - } - - targetIdentifierList, diags := fwtypes.NewListNestedObjectValueOfValueSlice(ctx, []targetIdentifierModel{targetIdModel}) - response.Diagnostics.Append(diags...) - if response.Diagnostics.HasError() { - return - } - targetModels[i].TargetIdentifier = targetIdentifierList - } - } - - targetsList, diags := fwtypes.NewListNestedObjectValueOfValueSlice(ctx, targetModels) - response.Diagnostics.Append(diags...) - if response.Diagnostics.HasError() { - return - } - data.Targets = targetsList - } - - // Set tags - only set if there are actual tags, otherwise keep null - if len(output.Tags) > 0 { - tags := tftags.New(ctx, output.Tags) - data.Tags = tftags.FlattenStringValueMap(ctx, tags.Map()) - data.TagsAll = tftags.FlattenStringValueMap(ctx, tags.Map()) - } else { - // Keep tags null if no tags were originally set and none exist in AWS - // TagsAll should always reflect AWS state (empty map when no tags) - tags := tftags.New(ctx, output.Tags) - data.TagsAll = tftags.FlattenStringValueMap(ctx, tags.Map()) + response.Diagnostics.Append(fwflex.Flatten(ctx, output, &data)...) + if response.Diagnostics.HasError() { + return } response.Diagnostics.Append(response.State.Set(ctx, &data)...) @@ -334,105 +204,44 @@ func (r *scopeResource) Update(ctx context.Context, request resource.UpdateReque return } - conn := r.Meta().NetworkFlowMonitorClient(ctx) + //conn := r.Meta().NetworkFlowMonitorClient(ctx) // Handle targets updates - if !new.Targets.Equal(old.Targets) { - // Calculate targets to add and remove - resourcesToAdd, resourcesToDelete, diags := r.calculateTargetChanges(ctx, old.Targets, new.Targets) - response.Diagnostics.Append(diags...) - if response.Diagnostics.HasError() { - return - } - - // Update scope targets if there are changes - if len(resourcesToAdd) > 0 || len(resourcesToDelete) > 0 { - input := networkflowmonitor.UpdateScopeInput{ - ScopeId: old.ScopeId.ValueStringPointer(), - ResourcesToAdd: resourcesToAdd, - ResourcesToDelete: resourcesToDelete, - } - - _, err := conn.UpdateScope(ctx, &input) - if err != nil { - response.Diagnostics.AddError(fmt.Sprintf("updating Network Flow Monitor Scope (%s) targets", new.ID.ValueString()), err.Error()) - return - } - - // Wait for scope to be updated - _, err = waitScopeUpdated(ctx, conn, old.ScopeId.ValueString(), r.UpdateTimeout(ctx, new.Timeouts)) - if err != nil { - response.Diagnostics.AddError(fmt.Sprintf("waiting for Network Flow Monitor Scope (%s) update", new.ID.ValueString()), err.Error()) - return - } - } - } - - // Handle tag updates - if !new.Tags.Equal(old.Tags) { - if err := updateTags(ctx, conn, new.ID.ValueString(), old.Tags, new.Tags); err != nil { - response.Diagnostics.AddError(fmt.Sprintf("updating Network Flow Monitor Scope (%s) tags", new.ID.ValueString()), err.Error()) - return - } - } - - // After updating, read the current state from AWS to get all computed values - output, err := findScopeByID(ctx, conn, old.ScopeId.ValueString()) - if err != nil { - response.Diagnostics.AddError(fmt.Sprintf("reading Network Flow Monitor Scope (%s) after update", new.ID.ValueString()), err.Error()) - return - } - - // Update the new model with current AWS state - new.ScopeId = types.StringValue(aws.ToString(output.ScopeId)) - new.Status = types.StringValue(string(output.Status)) - - // Map targets manually from AWS response - if len(output.Targets) > 0 { - targetModels := make([]targetResourceModel, len(output.Targets)) - for i, target := range output.Targets { - targetModels[i].Region = types.StringValue(aws.ToString(target.Region)) - - if target.TargetIdentifier != nil { - var targetIdValue string - if accountId, ok := target.TargetIdentifier.TargetId.(*awstypes.TargetIdMemberAccountId); ok { - targetIdValue = accountId.Value - } - - targetIdModel := targetIdentifierModel{ - TargetId: types.StringValue(targetIdValue), - TargetType: types.StringValue(string(target.TargetIdentifier.TargetType)), - } - - targetIdentifierList, diags := fwtypes.NewListNestedObjectValueOfValueSlice(ctx, []targetIdentifierModel{targetIdModel}) - response.Diagnostics.Append(diags...) - if response.Diagnostics.HasError() { - return - } - targetModels[i].TargetIdentifier = targetIdentifierList - } - } - - targetsList, diags := fwtypes.NewListNestedObjectValueOfValueSlice(ctx, targetModels) - response.Diagnostics.Append(diags...) - if response.Diagnostics.HasError() { - return - } - new.Targets = targetsList - } - - // Set tags based on the updated AWS state - if !new.Tags.IsNull() && len(output.Tags) > 0 { - tags := tftags.New(ctx, output.Tags) - new.Tags = tftags.FlattenStringValueMap(ctx, tags.Map()) - } - // TagsAll should always reflect AWS state - tags := tftags.New(ctx, output.Tags) - new.TagsAll = tftags.FlattenStringValueMap(ctx, tags.Map()) + // if !new.Targets.Equal(old.Targets) { + // // Calculate targets to add and remove + // resourcesToAdd, resourcesToDelete, diags := r.calculateTargetChanges(ctx, old.Targets, new.Targets) + // response.Diagnostics.Append(diags...) + // if response.Diagnostics.HasError() { + // return + // } + + // // Update scope targets if there are changes + // if len(resourcesToAdd) > 0 || len(resourcesToDelete) > 0 { + // input := networkflowmonitor.UpdateScopeInput{ + // ScopeId: old.ScopeID.ValueStringPointer(), + // ResourcesToAdd: resourcesToAdd, + // ResourcesToDelete: resourcesToDelete, + // } + + // _, err := conn.UpdateScope(ctx, &input) + // if err != nil { + // response.Diagnostics.AddError(fmt.Sprintf("updating Network Flow Monitor Scope (%s) targets", new.ID.ValueString()), err.Error()) + // return + // } + + // // Wait for scope to be updated + // _, err = waitScopeUpdated(ctx, conn, old.ScopeID.ValueString(), r.UpdateTimeout(ctx, new.Timeouts)) + // if err != nil { + // response.Diagnostics.AddError(fmt.Sprintf("waiting for Network Flow Monitor Scope (%s) update", new.ID.ValueString()), err.Error()) + // return + // } + // } + // } response.Diagnostics.Append(response.State.Set(ctx, &new)...) } +/* func (r *scopeResource) calculateTargetChanges(ctx context.Context, oldTargets, newTargets fwtypes.ListNestedObjectValueOf[targetResourceModel]) ([]awstypes.TargetResource, []awstypes.TargetResource, diag.Diagnostics) { var diags diag.Diagnostics var resourcesToAdd, resourcesToDelete []awstypes.TargetResource @@ -535,6 +344,7 @@ func (r *scopeResource) calculateTargetChanges(ctx context.Context, oldTargets, return resourcesToAdd, resourcesToDelete, diags } +*/ func (r *scopeResource) Delete(ctx context.Context, request resource.DeleteRequest, response *resource.DeleteResponse) { var data scopeResourceModel @@ -545,8 +355,9 @@ func (r *scopeResource) Delete(ctx context.Context, request resource.DeleteReque conn := r.Meta().NetworkFlowMonitorClient(ctx) + scopeID := fwflex.StringValueFromFramework(ctx, data.ScopeID) input := networkflowmonitor.DeleteScopeInput{ - ScopeId: data.ScopeId.ValueStringPointer(), + ScopeId: aws.String(scopeID), } _, err := conn.DeleteScope(ctx, &input) @@ -555,49 +366,18 @@ func (r *scopeResource) Delete(ctx context.Context, request resource.DeleteReque } if err != nil { - response.Diagnostics.AddError(fmt.Sprintf("deleting Network Flow Monitor Scope (%s)", data.ID.ValueString()), err.Error()) + response.Diagnostics.AddError(fmt.Sprintf("deleting Network Flow Monitor Scope (%s)", scopeID), err.Error()) return } - if _, err := waitScopeDeleted(ctx, conn, data.ScopeId.ValueString(), r.DeleteTimeout(ctx, data.Timeouts)); err != nil { - response.Diagnostics.AddError(fmt.Sprintf("waiting for Network Flow Monitor Scope (%s) delete", data.ID.ValueString()), err.Error()) + if _, err := waitScopeDeleted(ctx, conn, scopeID, r.DeleteTimeout(ctx, data.Timeouts)); err != nil { + response.Diagnostics.AddError(fmt.Sprintf("waiting for Network Flow Monitor Scope (%s) delete", scopeID), err.Error()) return } } func (r *scopeResource) ImportState(ctx context.Context, request resource.ImportStateRequest, response *resource.ImportStateResponse) { - // The import ID can be either an ARN or a scope ID - id := request.ID - - // If it's an ARN, extract the scope ID - if arn.IsARN(id) { - parsedARN, err := arn.Parse(id) - if err != nil { - response.Diagnostics.AddError("Invalid ARN", fmt.Sprintf("Unable to parse ARN (%s): %s", id, err)) - return - } - - if parsedARN.Service != "networkflowmonitor" { - response.Diagnostics.AddError("Invalid ARN", fmt.Sprintf("Expected networkflowmonitor service ARN, got: %s", parsedARN.Service)) - return - } - - // ARN format: arn:partition:networkflowmonitor:region:account:scope/scope-id - parts := strings.Split(parsedARN.Resource, "/") - if len(parts) != 2 || parts[0] != names.AttrScope { - response.Diagnostics.AddError("Invalid import ID", fmt.Sprintf("Expected ARN format 'arn:partition:networkflowmonitor:region:account:scope/scope-id', got: %s", id)) - return - } - scopeId := parts[1] - - // Set both ID (ARN) and scope_id - response.Diagnostics.Append(response.State.SetAttribute(ctx, path.Root(names.AttrID), id)...) - response.Diagnostics.Append(response.State.SetAttribute(ctx, path.Root("scope_id"), scopeId)...) - } else { - // Assume it's a scope ID, we'll need to construct the ARN during read - response.Diagnostics.Append(response.State.SetAttribute(ctx, path.Root("scope_id"), id)...) - // ID will be set during the subsequent Read operation - } + response.Diagnostics.Append(response.State.SetAttribute(ctx, path.Root("scope_id"), request.ID)...) } func findScopeByID(ctx context.Context, conn *networkflowmonitor.Client, id string) (*networkflowmonitor.GetScopeOutput, error) { @@ -605,11 +385,14 @@ func findScopeByID(ctx context.Context, conn *networkflowmonitor.Client, id stri ScopeId: aws.String(id), } - output, err := conn.GetScope(ctx, &input) + return findScope(ctx, conn, &input) +} + +func findScope(ctx context.Context, conn *networkflowmonitor.Client, input *networkflowmonitor.GetScopeInput) (*networkflowmonitor.GetScopeOutput, error) { + output, err := conn.GetScope(ctx, input) if errs.IsA[*awstypes.ResourceNotFoundException](err) { return nil, &retry.NotFoundError{ - LastError: err, LastRequest: input, } } @@ -691,3 +474,57 @@ func waitScopeDeleted(ctx context.Context, conn *networkflowmonitor.Client, id s return nil, err } + +type scopeResourceModel struct { + framework.WithRegionModel + ScopeARN types.String `tfsdk:"scope_arn"` + ScopeID types.String `tfsdk:"scope_id"` + Tags tftags.Map `tfsdk:"tags"` + TagsAll tftags.Map `tfsdk:"tags_all"` + Targets fwtypes.ListNestedObjectValueOf[targetResourceModel] `tfsdk:"target"` + Timeouts timeouts.Value `tfsdk:"timeouts"` +} + +type targetResourceModel struct { + Region types.String `tfsdk:"region"` + TargetIdentifier fwtypes.ListNestedObjectValueOf[targetIdentifierModel] `tfsdk:"target_identifier"` +} + +type targetIdentifierModel struct { + TargetID fwtypes.ListNestedObjectValueOf[targetIdModel] `tfsdk:"target_id"` + TargetType fwtypes.StringEnum[awstypes.TargetType] `tfsdk:"target_type"` +} + +type targetIdModel struct { + AccountID types.String `tfsdk:"account_id"` +} + +var ( + _ fwflex.Expander = targetIdModel{} + _ fwflex.Flattener = &targetIdModel{} +) + +func (m targetIdModel) Expand(ctx context.Context) (any, diag.Diagnostics) { + var diags diag.Diagnostics + switch { + case !m.AccountID.IsNull(): + var r awstypes.TargetIdMemberAccountId + r.Value = fwflex.StringValueFromFramework(ctx, m.AccountID) + return &r, diags + } + return nil, diags +} + +func (m *targetIdModel) Flatten(ctx context.Context, v any) diag.Diagnostics { + var diags diag.Diagnostics + switch t := v.(type) { + case awstypes.TargetIdMemberAccountId: + m.AccountID = fwflex.StringValueToFramework(ctx, t.Value) + default: + diags.AddError( + "Unsupported Type", + fmt.Sprintf("target ID flatten: %T", v), + ) + } + return diags +} diff --git a/internal/service/networkflowmonitor/scope_test.go b/internal/service/networkflowmonitor/scope_test.go index fb8de3e45878..6d7e7257231e 100644 --- a/internal/service/networkflowmonitor/scope_test.go +++ b/internal/service/networkflowmonitor/scope_test.go @@ -183,11 +183,13 @@ data "aws_caller_identity" "current" {} data "aws_region" "current" {} resource "aws_networkflowmonitor_scope" "test" { - targets { + target { region = data.aws_region.current.name target_identifier { - target_id = data.aws_caller_identity.current.account_id target_type = "ACCOUNT" + target_id { + account_id = data.aws_caller_identity.current.account_id + } } } } @@ -200,11 +202,13 @@ data "aws_caller_identity" "current" {} data "aws_region" "current" {} resource "aws_networkflowmonitor_scope" "test" { - targets { + target { region = data.aws_region.current.name target_identifier { - target_id = data.aws_caller_identity.current.account_id target_type = "ACCOUNT" + target_id { + account_id = data.aws_caller_identity.current.account_id + } } } @@ -221,11 +225,13 @@ data "aws_caller_identity" "current" {} data "aws_region" "current" {} resource "aws_networkflowmonitor_scope" "test" { - targets { + target { region = data.aws_region.current.name target_identifier { - target_id = data.aws_caller_identity.current.account_id target_type = "ACCOUNT" + target_id { + account_id = data.aws_caller_identity.current.account_id + } } } diff --git a/internal/service/networkflowmonitor/service_package_gen.go b/internal/service/networkflowmonitor/service_package_gen.go index 86709e6d5c1e..26d25c6646fd 100644 --- a/internal/service/networkflowmonitor/service_package_gen.go +++ b/internal/service/networkflowmonitor/service_package_gen.go @@ -37,7 +37,7 @@ func (p *servicePackage) FrameworkResources(ctx context.Context) []*inttypes.Ser TypeName: "aws_networkflowmonitor_scope", Name: "Scope", Tags: unique.Make(inttypes.ServicePackageResourceTags{ - IdentifierAttribute: names.AttrARN, + IdentifierAttribute: "scope_arn", }), Region: unique.Make(inttypes.ResourceRegionDefault()), }, diff --git a/website/docs/r/networkflowmonitor_scope.html.markdown b/website/docs/r/networkflowmonitor_scope.html.markdown index 89ff253cf286..42ee8453edba 100644 --- a/website/docs/r/networkflowmonitor_scope.html.markdown +++ b/website/docs/r/networkflowmonitor_scope.html.markdown @@ -18,11 +18,13 @@ Manages a Network Flow Monitor Scope. data "aws_caller_identity" "current" {} resource "aws_networkflowmonitor_scope" "example" { - targets { + target { region = "us-east-1" target_identifier { - target_id = data.aws_caller_identity.current.account_id target_type = "ACCOUNT" + target_id { + account_id = data.aws_caller_identity.current.account_id + } } } @@ -36,7 +38,7 @@ resource "aws_networkflowmonitor_scope" "example" { The following arguments are required: -* `targets` - (Required) The targets to define the scope to be monitored. A target is an array of target resources, which are currently Region-account pairs. +* `target` - (Required) The targets to define the scope to be monitored. A target is an array of target resources, which are currently Region-account pairs. The following arguments are optional: @@ -57,14 +59,18 @@ The `target_identifier` block supports the following: * `target_id` - (Required) The identifier for a target, which is currently always an account ID. * `target_type` - (Required) The type of a target. A target type is currently always `ACCOUNT`. +### target_id + +The `target_id` block supports the following: + +* `account_id` - (Required) AWS account ID. + ## Attribute Reference This resource exports the following attributes in addition to the arguments above: -* `arn` - The Amazon Resource Name (ARN) of the scope. -* `id` - The Amazon Resource Name (ARN) of the scope. +* `scope_arn` - The Amazon Resource Name (ARN) of the scope. * `scope_id` - The identifier for the scope that includes the resources you want to get data results for. -* `status` - The status for a scope. The status can be one of the following: `SUCCEEDED`, `IN_PROGRESS`, `FAILED`, `DEACTIVATING`, or `DEACTIVATED`. * `tags_all` - A 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 @@ -77,17 +83,17 @@ This resource exports the following attributes in addition to the arguments abov ## Import -In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import Network Flow Monitor Scope using the scope ARN. For example: +In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import Network Flow Monitor Scope using the scope ID. For example: ```terraform import { to = aws_networkflowmonitor_scope.example - id = "arn:aws:networkflowmonitor:us-east-1:123456789012:scope/example-scope-id" + id = "example-scope-id" } ``` -Using `terraform import`, import Network Flow Monitor Scope using the scope ARN. For example: +Using `terraform import`, import Network Flow Monitor Scope using the scope ID. For example: ```console -% terraform import aws_networkflowmonitor_scope.example arn:aws:networkflowmonitor:us-east-1:123456789012:scope/example-scope-id +% terraform import aws_networkflowmonitor_scope.example example-scope-id ``` From b5bf374d74bc2a224bd6901ce8636c37dc50df03 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 11 Nov 2025 13:17:49 -0500 Subject: [PATCH 10/21] networkflowmonitor: Don't generate tagging tests. --- .../service/networkflowmonitor/generate.go | 1 - .../monitor_tags_gen_test.go | 2257 ----------------- .../networkflowmonitor/scope_tags_gen_test.go | 2257 ----------------- 3 files changed, 4515 deletions(-) delete mode 100644 internal/service/networkflowmonitor/monitor_tags_gen_test.go delete mode 100644 internal/service/networkflowmonitor/scope_tags_gen_test.go diff --git a/internal/service/networkflowmonitor/generate.go b/internal/service/networkflowmonitor/generate.go index ef406938b6b1..4bf50c2009ed 100644 --- a/internal/service/networkflowmonitor/generate.go +++ b/internal/service/networkflowmonitor/generate.go @@ -3,7 +3,6 @@ //go:generate go run ../../generate/servicepackage/main.go //go:generate go run ../../generate/tags/main.go -KVTValues -ServiceTagsMap -ListTags -UpdateTags -//go:generate go run ../../generate/tagstests/main.go // ONLY generate directives and package declaration! Do not add anything else to this file. package networkflowmonitor diff --git a/internal/service/networkflowmonitor/monitor_tags_gen_test.go b/internal/service/networkflowmonitor/monitor_tags_gen_test.go deleted file mode 100644 index 3f77387ccfba..000000000000 --- a/internal/service/networkflowmonitor/monitor_tags_gen_test.go +++ /dev/null @@ -1,2257 +0,0 @@ -// Code generated by internal/generate/tagstests/main.go; DO NOT EDIT. - -package networkflowmonitor_test - -import ( - "testing" - - "github.com/hashicorp/terraform-plugin-testing/config" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" - "github.com/hashicorp/terraform-plugin-testing/knownvalue" - "github.com/hashicorp/terraform-plugin-testing/plancheck" - "github.com/hashicorp/terraform-plugin-testing/statecheck" - "github.com/hashicorp/terraform-plugin-testing/tfjsonpath" - "github.com/hashicorp/terraform-provider-aws/internal/acctest" - "github.com/hashicorp/terraform-provider-aws/names" -) - -func TestAccNetworkFlowMonitorMonitor_tags(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_monitor.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckMonitorDestroy(ctx), - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - Steps: []resource.TestStep{ - { - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - }, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1Updated), - acctest.CtKey2: config.StringVariable(acctest.CtValue2), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1Updated), - acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1Updated), - acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1Updated), - acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1Updated), - acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), - })), - }, - }, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1Updated), - acctest.CtKey2: config.StringVariable(acctest.CtValue2), - }), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey2: config.StringVariable(acctest.CtValue2), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), - })), - }, - }, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey2: config.StringVariable(acctest.CtValue2), - }), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: nil, - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), - }, - }, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: nil, - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorMonitor_tags_null(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_monitor.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckMonitorDestroy(ctx), - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - Steps: []resource.TestStep{ - { - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: nil, - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.Null(), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(""), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.Null(), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(""), - })), - }, - }, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: nil, - }), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - acctest.CtTagsKey1, // The canonical value returned by the AWS API is "" - }, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorMonitor_tags_EmptyMap(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_monitor.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckMonitorDestroy(ctx), - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - Steps: []resource.TestStep{ - { - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{}), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{})), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{})), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), - }, - }, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{}), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - acctest.CtTagsKey1, // The canonical value returned by the AWS API is "" - }, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorMonitor_tags_AddOnUpdate(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_monitor.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckMonitorDestroy(ctx), - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - Steps: []resource.TestStep{ - { - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: nil, - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), - }, - }, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - }, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorMonitor_tags_EmptyTag_OnCreate(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_monitor.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckMonitorDestroy(ctx), - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - Steps: []resource.TestStep{ - { - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(""), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(""), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(""), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(""), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(""), - })), - }, - }, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(""), - }), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: nil, - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), - }, - }, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: nil, - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorMonitor_tags_EmptyTag_OnUpdate_Add(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_monitor.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckMonitorDestroy(ctx), - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - Steps: []resource.TestStep{ - { - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - }, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - acctest.CtKey2: config.StringVariable(""), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - acctest.CtKey2: knownvalue.StringExact(""), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - acctest.CtKey2: knownvalue.StringExact(""), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - acctest.CtKey2: knownvalue.StringExact(""), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - acctest.CtKey2: knownvalue.StringExact(""), - })), - }, - }, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - acctest.CtKey2: config.StringVariable(""), - }), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - }, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorMonitor_tags_EmptyTag_OnUpdate_Replace(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_monitor.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckMonitorDestroy(ctx), - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - Steps: []resource.TestStep{ - { - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - }, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(""), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(""), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(""), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(""), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(""), - })), - }, - }, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(""), - }), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorMonitor_tags_DefaultTags_providerOnly(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_monitor.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckMonitorDestroy(ctx), - Steps: []resource.TestStep{ - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - acctest.CtResourceTags: nil, - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - acctest.CtResourceTags: nil, - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1Updated), - acctest.CtKey2: config.StringVariable(acctest.CtValue2), - }), - acctest.CtResourceTags: nil, - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1Updated), - acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1Updated), - acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), - })), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1Updated), - acctest.CtKey2: config.StringVariable(acctest.CtValue2), - }), - acctest.CtResourceTags: nil, - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey2: config.StringVariable(acctest.CtValue2), - }), - acctest.CtResourceTags: nil, - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), - })), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey2: config.StringVariable(acctest.CtValue2), - }), - acctest.CtResourceTags: nil, - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: nil, - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: nil, - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorMonitor_tags_DefaultTags_nonOverlapping(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_monitor.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckMonitorDestroy(ctx), - Steps: []resource.TestStep{ - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1), - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1), - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), - })), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1), - }), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1Updated), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1Updated), - acctest.CtResourceKey2: config.StringVariable(acctest.CtResourceValue2), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1Updated), - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1Updated), - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1Updated), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1Updated), - acctest.CtResourceKey2: config.StringVariable(acctest.CtResourceValue2), - }), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: nil, - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: nil, - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorMonitor_tags_DefaultTags_overlapping(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_monitor.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckMonitorDestroy(ctx), - Steps: []resource.TestStep{ - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtOverlapKey1: config.StringVariable(acctest.CtProviderValue1), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtOverlapKey1: config.StringVariable(acctest.CtResourceValue1), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), - })), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtOverlapKey1: config.StringVariable(acctest.CtProviderValue1), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtOverlapKey1: config.StringVariable(acctest.CtResourceValue1), - }), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtOverlapKey1: config.StringVariable(acctest.CtProviderValue1), - acctest.CtOverlapKey2: config.StringVariable("providervalue2"), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtOverlapKey1: config.StringVariable(acctest.CtResourceValue1), - acctest.CtOverlapKey2: config.StringVariable(acctest.CtResourceValue2), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), - acctest.CtOverlapKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), - acctest.CtOverlapKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), - acctest.CtOverlapKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), - acctest.CtOverlapKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtOverlapKey1: config.StringVariable(acctest.CtProviderValue1), - acctest.CtOverlapKey2: config.StringVariable("providervalue2"), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtOverlapKey1: config.StringVariable(acctest.CtResourceValue1), - acctest.CtOverlapKey2: config.StringVariable(acctest.CtResourceValue2), - }), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtOverlapKey1: config.StringVariable(acctest.CtProviderValue1), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtOverlapKey1: config.StringVariable(acctest.CtResourceValue2), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue2), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue2), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue2), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue2), - })), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtOverlapKey1: config.StringVariable(acctest.CtProviderValue1), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtOverlapKey1: config.StringVariable(acctest.CtResourceValue2), - }), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorMonitor_tags_DefaultTags_updateToProviderOnly(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_monitor.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckMonitorDestroy(ctx), - Steps: []resource.TestStep{ - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - acctest.CtResourceTags: nil, - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - acctest.CtResourceTags: nil, - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorMonitor_tags_DefaultTags_updateToResourceOnly(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_monitor.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckMonitorDestroy(ctx), - Steps: []resource.TestStep{ - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - acctest.CtResourceTags: nil, - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorMonitor_tags_DefaultTags_emptyResourceTag(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_monitor.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckMonitorDestroy(ctx), - Steps: []resource.TestStep{ - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(""), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(""), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(""), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(""), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(""), - })), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(""), - }), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorMonitor_tags_DefaultTags_emptyProviderOnlyTag(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_monitor.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckMonitorDestroy(ctx), - Steps: []resource.TestStep{ - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(""), - }), - acctest.CtResourceTags: nil, - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(""), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(""), - })), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(""), - }), - acctest.CtResourceTags: nil, - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorMonitor_tags_DefaultTags_nullOverlappingResourceTag(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_monitor.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckMonitorDestroy(ctx), - Steps: []resource.TestStep{ - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtProviderValue1), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: nil, - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.Null(), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(""), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.Null(), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(""), - })), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtProviderValue1), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: nil, - }), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - acctest.CtTagsKey1, // The canonical value returned by the AWS API is "" - }, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorMonitor_tags_DefaultTags_nullNonOverlappingResourceTag(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_monitor.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckMonitorDestroy(ctx), - Steps: []resource.TestStep{ - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtResourceKey1: nil, - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.Null(), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(""), - acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.Null(), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(""), - acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1), - })), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtResourceKey1: nil, - }), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "tags.resourcekey1", // The canonical value returned by the AWS API is "" - }, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorMonitor_tags_ComputedTag_OnCreate(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_monitor.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckMonitorDestroy(ctx), - Steps: []resource.TestStep{ - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tagsComputed1/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - "unknownTagKey": config.StringVariable("computedkey1"), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - resource.TestCheckResourceAttrPair(resourceName, "tags.computedkey1", "null_resource.test", names.AttrID), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapSizeExact(1)), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapSizeExact(1)), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectUnknownValue(resourceName, tfjsonpath.New(names.AttrTags).AtMapKey("computedkey1")), - plancheck.ExpectUnknownValue(resourceName, tfjsonpath.New(names.AttrTagsAll)), - }, - PostApplyPreRefresh: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), - }, - PostApplyPostRefresh: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tagsComputed1/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - "unknownTagKey": config.StringVariable("computedkey1"), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorMonitor_tags_ComputedTag_OnUpdate_Add(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_monitor.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckMonitorDestroy(ctx), - Steps: []resource.TestStep{ - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tagsComputed2/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - "unknownTagKey": config.StringVariable("computedkey1"), - "knownTagKey": config.StringVariable(acctest.CtKey1), - "knownTagValue": config.StringVariable(acctest.CtValue1), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - resource.TestCheckResourceAttrPair(resourceName, "tags.computedkey1", "null_resource.test", names.AttrID), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapSizeExact(2)), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapPartial(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapSizeExact(2)), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapPartial(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectUnknownValue(resourceName, tfjsonpath.New(names.AttrTags).AtMapKey("computedkey1")), - plancheck.ExpectUnknownValue(resourceName, tfjsonpath.New(names.AttrTagsAll)), - }, - PostApplyPreRefresh: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), - }, - PostApplyPostRefresh: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tagsComputed2/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - "unknownTagKey": config.StringVariable("computedkey1"), - "knownTagKey": config.StringVariable(acctest.CtKey1), - "knownTagValue": config.StringVariable(acctest.CtValue1), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorMonitor_tags_ComputedTag_OnUpdate_Replace(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_monitor.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckMonitorDestroy(ctx), - Steps: []resource.TestStep{ - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tagsComputed1/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - "unknownTagKey": config.StringVariable(acctest.CtKey1), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - resource.TestCheckResourceAttrPair(resourceName, acctest.CtTagsKey1, "null_resource.test", names.AttrID), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapSizeExact(1)), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapSizeExact(1)), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectUnknownValue(resourceName, tfjsonpath.New(names.AttrTags).AtMapKey(acctest.CtKey1)), - plancheck.ExpectUnknownValue(resourceName, tfjsonpath.New(names.AttrTagsAll)), - }, - PostApplyPreRefresh: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), - }, - PostApplyPostRefresh: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tagsComputed1/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - "unknownTagKey": config.StringVariable(acctest.CtKey1), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorMonitor_tags_IgnoreTags_Overlap_DefaultTag(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_monitor.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckMonitorDestroy(ctx), - Steps: []resource.TestStep{ - // 1: Create - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_ignore/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1), - }), - "ignore_tag_keys": config.SetVariable( - config.StringVariable(acctest.CtProviderKey1), - ), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), - })), - expectFullResourceTags(ctx, resourceName, knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1), // TODO: Should not be set - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), - })), - }, - PostApplyPreRefresh: []plancheck.PlanCheck{ - plancheck.ExpectEmptyPlan(), - }, - PostApplyPostRefresh: []plancheck.PlanCheck{ - plancheck.ExpectEmptyPlan(), - }, - }, - }, - // 2: Update ignored tag only - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_ignore/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1Updated), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1), - }), - "ignore_tag_keys": config.SetVariable( - config.StringVariable(acctest.CtProviderKey1), - ), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), - })), - expectFullResourceTags(ctx, resourceName, knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1), // TODO: Should not be set - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), - })), - }, - PostApplyPreRefresh: []plancheck.PlanCheck{ - plancheck.ExpectEmptyPlan(), - }, - PostApplyPostRefresh: []plancheck.PlanCheck{ - plancheck.ExpectEmptyPlan(), - }, - }, - }, - // 3: Update both tags - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_ignore/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1Again), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1Updated), - }), - "ignore_tag_keys": config.SetVariable( - config.StringVariable(acctest.CtProviderKey1), - ), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), - })), - expectFullResourceTags(ctx, resourceName, knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1), // TODO: Should not be set - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), - })), - }, - PostApplyPreRefresh: []plancheck.PlanCheck{ - plancheck.ExpectEmptyPlan(), - }, - PostApplyPostRefresh: []plancheck.PlanCheck{ - plancheck.ExpectEmptyPlan(), - }, - }, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorMonitor_tags_IgnoreTags_Overlap_ResourceTag(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_monitor.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckMonitorDestroy(ctx), - Steps: []resource.TestStep{ - // 1: Create - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_ignore/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1), - acctest.CtResourceKey2: config.StringVariable(acctest.CtResourceValue2), - }), - "ignore_tag_keys": config.SetVariable( - config.StringVariable(acctest.CtResourceKey1), - ), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - expectFullResourceTags(ctx, resourceName, knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), // TODO: Should not be set - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - }, - PostApplyPreRefresh: []plancheck.PlanCheck{ - plancheck.ExpectEmptyPlan(), - }, - PostApplyPostRefresh: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), // TODO: Should be NoOp - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - }, - }, - ExpectNonEmptyPlan: true, - }, - // 2: Update ignored tag - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_ignore/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1Updated), - acctest.CtResourceKey2: config.StringVariable(acctest.CtResourceValue2), - }), - "ignore_tag_keys": config.SetVariable( - config.StringVariable(acctest.CtResourceKey1), - ), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - expectFullResourceTags(ctx, resourceName, knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), // TODO: Should not be set - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - }, - PostApplyPreRefresh: []plancheck.PlanCheck{ - plancheck.ExpectEmptyPlan(), - }, - PostApplyPostRefresh: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), // TODO: Should be NoOp - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - }, - }, - ExpectNonEmptyPlan: true, - }, - // 3: Update both tags - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Monitor/tags_ignore/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1Again), - acctest.CtResourceKey2: config.StringVariable(acctest.CtResourceValue2Updated), - }), - "ignore_tag_keys": config.SetVariable( - config.StringVariable(acctest.CtResourceKey1), - ), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Again), - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2Updated), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2Updated), - })), - expectFullResourceTags(ctx, resourceName, knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), // TODO: Should not be set - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2Updated), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Again), - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2Updated), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2Updated), - })), - }, - PostApplyPreRefresh: []plancheck.PlanCheck{ - plancheck.ExpectEmptyPlan(), - }, - PostApplyPostRefresh: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), // TODO: Should be NoOp - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Again), - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2Updated), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2Updated), - })), - }, - }, - ExpectNonEmptyPlan: true, - }, - }, - }) -} diff --git a/internal/service/networkflowmonitor/scope_tags_gen_test.go b/internal/service/networkflowmonitor/scope_tags_gen_test.go deleted file mode 100644 index 428c03b887b9..000000000000 --- a/internal/service/networkflowmonitor/scope_tags_gen_test.go +++ /dev/null @@ -1,2257 +0,0 @@ -// Code generated by internal/generate/tagstests/main.go; DO NOT EDIT. - -package networkflowmonitor_test - -import ( - "testing" - - "github.com/hashicorp/terraform-plugin-testing/config" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" - "github.com/hashicorp/terraform-plugin-testing/knownvalue" - "github.com/hashicorp/terraform-plugin-testing/plancheck" - "github.com/hashicorp/terraform-plugin-testing/statecheck" - "github.com/hashicorp/terraform-plugin-testing/tfjsonpath" - "github.com/hashicorp/terraform-provider-aws/internal/acctest" - "github.com/hashicorp/terraform-provider-aws/names" -) - -func TestAccNetworkFlowMonitorScope_tags(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_scope.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckScopeDestroy(ctx), - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - Steps: []resource.TestStep{ - { - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - }, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1Updated), - acctest.CtKey2: config.StringVariable(acctest.CtValue2), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1Updated), - acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1Updated), - acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1Updated), - acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1Updated), - acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), - })), - }, - }, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1Updated), - acctest.CtKey2: config.StringVariable(acctest.CtValue2), - }), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey2: config.StringVariable(acctest.CtValue2), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), - })), - }, - }, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey2: config.StringVariable(acctest.CtValue2), - }), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: nil, - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), - }, - }, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: nil, - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorScope_tags_null(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_scope.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckScopeDestroy(ctx), - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - Steps: []resource.TestStep{ - { - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: nil, - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.Null(), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(""), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.Null(), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(""), - })), - }, - }, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: nil, - }), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - acctest.CtTagsKey1, // The canonical value returned by the AWS API is "" - }, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorScope_tags_EmptyMap(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_scope.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckScopeDestroy(ctx), - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - Steps: []resource.TestStep{ - { - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{}), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{})), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{})), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), - }, - }, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{}), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - acctest.CtTagsKey1, // The canonical value returned by the AWS API is "" - }, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorScope_tags_AddOnUpdate(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_scope.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckScopeDestroy(ctx), - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - Steps: []resource.TestStep{ - { - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: nil, - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), - }, - }, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - }, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorScope_tags_EmptyTag_OnCreate(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_scope.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckScopeDestroy(ctx), - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - Steps: []resource.TestStep{ - { - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(""), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(""), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(""), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(""), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(""), - })), - }, - }, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(""), - }), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: nil, - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), - }, - }, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: nil, - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorScope_tags_EmptyTag_OnUpdate_Add(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_scope.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckScopeDestroy(ctx), - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - Steps: []resource.TestStep{ - { - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - }, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - acctest.CtKey2: config.StringVariable(""), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - acctest.CtKey2: knownvalue.StringExact(""), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - acctest.CtKey2: knownvalue.StringExact(""), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - acctest.CtKey2: knownvalue.StringExact(""), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - acctest.CtKey2: knownvalue.StringExact(""), - })), - }, - }, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - acctest.CtKey2: config.StringVariable(""), - }), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - }, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorScope_tags_EmptyTag_OnUpdate_Replace(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_scope.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckScopeDestroy(ctx), - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - Steps: []resource.TestStep{ - { - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - }, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(""), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(""), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(""), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(""), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(""), - })), - }, - }, - }, - { - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(""), - }), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorScope_tags_DefaultTags_providerOnly(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_scope.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckScopeDestroy(ctx), - Steps: []resource.TestStep{ - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - acctest.CtResourceTags: nil, - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - acctest.CtResourceTags: nil, - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1Updated), - acctest.CtKey2: config.StringVariable(acctest.CtValue2), - }), - acctest.CtResourceTags: nil, - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1Updated), - acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1Updated), - acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), - })), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1Updated), - acctest.CtKey2: config.StringVariable(acctest.CtValue2), - }), - acctest.CtResourceTags: nil, - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey2: config.StringVariable(acctest.CtValue2), - }), - acctest.CtResourceTags: nil, - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), - })), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey2: config.StringVariable(acctest.CtValue2), - }), - acctest.CtResourceTags: nil, - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: nil, - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: nil, - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorScope_tags_DefaultTags_nonOverlapping(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_scope.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckScopeDestroy(ctx), - Steps: []resource.TestStep{ - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1), - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1), - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), - })), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1), - }), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1Updated), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1Updated), - acctest.CtResourceKey2: config.StringVariable(acctest.CtResourceValue2), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1Updated), - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1Updated), - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1Updated), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1Updated), - acctest.CtResourceKey2: config.StringVariable(acctest.CtResourceValue2), - }), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: nil, - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{})), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: nil, - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorScope_tags_DefaultTags_overlapping(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_scope.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckScopeDestroy(ctx), - Steps: []resource.TestStep{ - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtOverlapKey1: config.StringVariable(acctest.CtProviderValue1), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtOverlapKey1: config.StringVariable(acctest.CtResourceValue1), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), - })), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtOverlapKey1: config.StringVariable(acctest.CtProviderValue1), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtOverlapKey1: config.StringVariable(acctest.CtResourceValue1), - }), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtOverlapKey1: config.StringVariable(acctest.CtProviderValue1), - acctest.CtOverlapKey2: config.StringVariable("providervalue2"), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtOverlapKey1: config.StringVariable(acctest.CtResourceValue1), - acctest.CtOverlapKey2: config.StringVariable(acctest.CtResourceValue2), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), - acctest.CtOverlapKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), - acctest.CtOverlapKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), - acctest.CtOverlapKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue1), - acctest.CtOverlapKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtOverlapKey1: config.StringVariable(acctest.CtProviderValue1), - acctest.CtOverlapKey2: config.StringVariable("providervalue2"), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtOverlapKey1: config.StringVariable(acctest.CtResourceValue1), - acctest.CtOverlapKey2: config.StringVariable(acctest.CtResourceValue2), - }), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtOverlapKey1: config.StringVariable(acctest.CtProviderValue1), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtOverlapKey1: config.StringVariable(acctest.CtResourceValue2), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue2), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue2), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue2), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtOverlapKey1: knownvalue.StringExact(acctest.CtResourceValue2), - })), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtOverlapKey1: config.StringVariable(acctest.CtProviderValue1), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtOverlapKey1: config.StringVariable(acctest.CtResourceValue2), - }), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorScope_tags_DefaultTags_updateToProviderOnly(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_scope.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckScopeDestroy(ctx), - Steps: []resource.TestStep{ - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - acctest.CtResourceTags: nil, - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - acctest.CtResourceTags: nil, - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorScope_tags_DefaultTags_updateToResourceOnly(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_scope.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckScopeDestroy(ctx), - Steps: []resource.TestStep{ - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - acctest.CtResourceTags: nil, - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorScope_tags_DefaultTags_emptyResourceTag(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_scope.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckScopeDestroy(ctx), - Steps: []resource.TestStep{ - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(""), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(""), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(""), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(""), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(""), - })), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(""), - }), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorScope_tags_DefaultTags_emptyProviderOnlyTag(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_scope.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckScopeDestroy(ctx), - Steps: []resource.TestStep{ - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(""), - }), - acctest.CtResourceTags: nil, - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(""), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(""), - })), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(""), - }), - acctest.CtResourceTags: nil, - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorScope_tags_DefaultTags_nullOverlappingResourceTag(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_scope.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckScopeDestroy(ctx), - Steps: []resource.TestStep{ - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtProviderValue1), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: nil, - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.Null(), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(""), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.Null(), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(""), - })), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtProviderValue1), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: nil, - }), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - acctest.CtTagsKey1, // The canonical value returned by the AWS API is "" - }, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorScope_tags_DefaultTags_nullNonOverlappingResourceTag(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_scope.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckScopeDestroy(ctx), - Steps: []resource.TestStep{ - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtResourceKey1: nil, - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.Null(), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(""), - acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.Null(), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(""), - acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1), - })), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_defaults/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtResourceKey1: nil, - }), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "tags.resourcekey1", // The canonical value returned by the AWS API is "" - }, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorScope_tags_ComputedTag_OnCreate(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_scope.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckScopeDestroy(ctx), - Steps: []resource.TestStep{ - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tagsComputed1/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - "unknownTagKey": config.StringVariable("computedkey1"), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - resource.TestCheckResourceAttrPair(resourceName, "tags.computedkey1", "null_resource.test", names.AttrID), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapSizeExact(1)), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapSizeExact(1)), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectUnknownValue(resourceName, tfjsonpath.New(names.AttrTags).AtMapKey("computedkey1")), - plancheck.ExpectUnknownValue(resourceName, tfjsonpath.New(names.AttrTagsAll)), - }, - PostApplyPreRefresh: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), - }, - PostApplyPostRefresh: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tagsComputed1/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - "unknownTagKey": config.StringVariable("computedkey1"), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorScope_tags_ComputedTag_OnUpdate_Add(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_scope.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckScopeDestroy(ctx), - Steps: []resource.TestStep{ - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tagsComputed2/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - "unknownTagKey": config.StringVariable("computedkey1"), - "knownTagKey": config.StringVariable(acctest.CtKey1), - "knownTagValue": config.StringVariable(acctest.CtValue1), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - resource.TestCheckResourceAttrPair(resourceName, "tags.computedkey1", "null_resource.test", names.AttrID), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapSizeExact(2)), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapPartial(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapSizeExact(2)), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapPartial(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectUnknownValue(resourceName, tfjsonpath.New(names.AttrTags).AtMapKey("computedkey1")), - plancheck.ExpectUnknownValue(resourceName, tfjsonpath.New(names.AttrTagsAll)), - }, - PostApplyPreRefresh: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), - }, - PostApplyPostRefresh: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tagsComputed2/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - "unknownTagKey": config.StringVariable("computedkey1"), - "knownTagKey": config.StringVariable(acctest.CtKey1), - "knownTagValue": config.StringVariable(acctest.CtValue1), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorScope_tags_ComputedTag_OnUpdate_Replace(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_scope.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckScopeDestroy(ctx), - Steps: []resource.TestStep{ - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtKey1: config.StringVariable(acctest.CtValue1), - }), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), - })), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tagsComputed1/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - "unknownTagKey": config.StringVariable(acctest.CtKey1), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - resource.TestCheckResourceAttrPair(resourceName, acctest.CtTagsKey1, "null_resource.test", names.AttrID), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapSizeExact(1)), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapSizeExact(1)), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectUnknownValue(resourceName, tfjsonpath.New(names.AttrTags).AtMapKey(acctest.CtKey1)), - plancheck.ExpectUnknownValue(resourceName, tfjsonpath.New(names.AttrTagsAll)), - }, - PostApplyPreRefresh: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), - }, - PostApplyPostRefresh: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), - }, - }, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tagsComputed1/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - "unknownTagKey": config.StringVariable(acctest.CtKey1), - }, - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorScope_tags_IgnoreTags_Overlap_DefaultTag(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_scope.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckScopeDestroy(ctx), - Steps: []resource.TestStep{ - // 1: Create - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_ignore/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1), - }), - "ignore_tag_keys": config.SetVariable( - config.StringVariable(acctest.CtProviderKey1), - ), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), - })), - expectFullResourceTags(ctx, resourceName, knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1), // TODO: Should not be set - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), - })), - }, - PostApplyPreRefresh: []plancheck.PlanCheck{ - plancheck.ExpectEmptyPlan(), - }, - PostApplyPostRefresh: []plancheck.PlanCheck{ - plancheck.ExpectEmptyPlan(), - }, - }, - }, - // 2: Update ignored tag only - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_ignore/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1Updated), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1), - }), - "ignore_tag_keys": config.SetVariable( - config.StringVariable(acctest.CtProviderKey1), - ), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), - })), - expectFullResourceTags(ctx, resourceName, knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1), // TODO: Should not be set - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionNoop), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), - })), - }, - PostApplyPreRefresh: []plancheck.PlanCheck{ - plancheck.ExpectEmptyPlan(), - }, - PostApplyPostRefresh: []plancheck.PlanCheck{ - plancheck.ExpectEmptyPlan(), - }, - }, - }, - // 3: Update both tags - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_ignore/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtProviderTags: config.MapVariable(map[string]config.Variable{ - acctest.CtProviderKey1: config.StringVariable(acctest.CtProviderValue1Again), - }), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1Updated), - }), - "ignore_tag_keys": config.SetVariable( - config.StringVariable(acctest.CtProviderKey1), - ), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), - })), - expectFullResourceTags(ctx, resourceName, knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtProviderKey1: knownvalue.StringExact(acctest.CtProviderValue1), // TODO: Should not be set - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), - })), - }, - PostApplyPreRefresh: []plancheck.PlanCheck{ - plancheck.ExpectEmptyPlan(), - }, - PostApplyPostRefresh: []plancheck.PlanCheck{ - plancheck.ExpectEmptyPlan(), - }, - }, - }, - }, - }) -} - -func TestAccNetworkFlowMonitorScope_tags_IgnoreTags_Overlap_ResourceTag(t *testing.T) { - ctx := acctest.Context(t) - - resourceName := "aws_networkflowmonitor_scope.test" - rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) - - acctest.ParallelTest(ctx, t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), - CheckDestroy: testAccCheckScopeDestroy(ctx), - Steps: []resource.TestStep{ - // 1: Create - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_ignore/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1), - acctest.CtResourceKey2: config.StringVariable(acctest.CtResourceValue2), - }), - "ignore_tag_keys": config.SetVariable( - config.StringVariable(acctest.CtResourceKey1), - ), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - expectFullResourceTags(ctx, resourceName, knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), // TODO: Should not be set - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - }, - PostApplyPreRefresh: []plancheck.PlanCheck{ - plancheck.ExpectEmptyPlan(), - }, - PostApplyPostRefresh: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), // TODO: Should be NoOp - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - }, - }, - ExpectNonEmptyPlan: true, - }, - // 2: Update ignored tag - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_ignore/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1Updated), - acctest.CtResourceKey2: config.StringVariable(acctest.CtResourceValue2), - }), - "ignore_tag_keys": config.SetVariable( - config.StringVariable(acctest.CtResourceKey1), - ), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - expectFullResourceTags(ctx, resourceName, knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), // TODO: Should not be set - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - }, - PostApplyPreRefresh: []plancheck.PlanCheck{ - plancheck.ExpectEmptyPlan(), - }, - PostApplyPostRefresh: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), // TODO: Should be NoOp - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Updated), - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2), - })), - }, - }, - ExpectNonEmptyPlan: true, - }, - // 3: Update both tags - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - ConfigDirectory: config.StaticDirectory("testdata/Scope/tags_ignore/"), - ConfigVariables: config.Variables{ - acctest.CtRName: config.StringVariable(rName), - acctest.CtResourceTags: config.MapVariable(map[string]config.Variable{ - acctest.CtResourceKey1: config.StringVariable(acctest.CtResourceValue1Again), - acctest.CtResourceKey2: config.StringVariable(acctest.CtResourceValue2Updated), - }), - "ignore_tag_keys": config.SetVariable( - config.StringVariable(acctest.CtResourceKey1), - ), - }, - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckScopeExists(ctx, resourceName), - ), - ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Again), - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2Updated), - })), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2Updated), - })), - expectFullResourceTags(ctx, resourceName, knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1), // TODO: Should not be set - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2Updated), - })), - }, - ConfigPlanChecks: resource.ConfigPlanChecks{ - PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Again), - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2Updated), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2Updated), - })), - }, - PostApplyPreRefresh: []plancheck.PlanCheck{ - plancheck.ExpectEmptyPlan(), - }, - PostApplyPostRefresh: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), // TODO: Should be NoOp - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey1: knownvalue.StringExact(acctest.CtResourceValue1Again), - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2Updated), - })), - plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), knownvalue.MapExact(map[string]knownvalue.Check{ - acctest.CtResourceKey2: knownvalue.StringExact(acctest.CtResourceValue2Updated), - })), - }, - }, - ExpectNonEmptyPlan: true, - }, - }, - }) -} From 2ffce285ba925e43b9c621889b8f7b39f69c5c72 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 11 Nov 2025 14:04:08 -0500 Subject: [PATCH 11/21] networkflowmonitor: Consolidate acceptance tests. --- .../networkflowmonitor/monitor_test.go | 23 +++----------- .../networkflowmonitor_test.go | 30 +++++++++++++++++++ .../service/networkflowmonitor/scope_test.go | 20 ++----------- 3 files changed, 37 insertions(+), 36 deletions(-) create mode 100644 internal/service/networkflowmonitor/networkflowmonitor_test.go diff --git a/internal/service/networkflowmonitor/monitor_test.go b/internal/service/networkflowmonitor/monitor_test.go index 7db8be912850..e60c97186aed 100644 --- a/internal/service/networkflowmonitor/monitor_test.go +++ b/internal/service/networkflowmonitor/monitor_test.go @@ -20,22 +20,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/names" ) -func TestAccNetworkFlowMonitorMonitor_serial(t *testing.T) { - t.Parallel() - - testCases := map[string]map[string]func(t *testing.T){ - "Monitor": { - acctest.CtBasic: testAccNetworkFlowMonitorMonitor_basic, - acctest.CtDisappears: testAccNetworkFlowMonitorMonitor_disappears, - "tags": testAccNetworkFlowMonitorMonitor_tags, - "update": testAccNetworkFlowMonitorMonitor_update, - }, - } - - acctest.RunSerialTests2Levels(t, testCases, 0) -} - -func testAccNetworkFlowMonitorMonitor_basic(t *testing.T) { +func testAccMonitor_basic(t *testing.T) { ctx := acctest.Context(t) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_networkflowmonitor_monitor.test" @@ -68,7 +53,7 @@ func testAccNetworkFlowMonitorMonitor_basic(t *testing.T) { }) } -func testAccNetworkFlowMonitorMonitor_disappears(t *testing.T) { +func testAccMonitor_disappears(t *testing.T) { ctx := acctest.Context(t) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_networkflowmonitor_monitor.test" @@ -94,7 +79,7 @@ func testAccNetworkFlowMonitorMonitor_disappears(t *testing.T) { }) } -func testAccNetworkFlowMonitorMonitor_tags(t *testing.T) { +func testAccMonitor_tags(t *testing.T) { ctx := acctest.Context(t) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_networkflowmonitor_monitor.test" @@ -143,7 +128,7 @@ func testAccNetworkFlowMonitorMonitor_tags(t *testing.T) { }) } -func testAccNetworkFlowMonitorMonitor_update(t *testing.T) { +func testAccMonitor_update(t *testing.T) { ctx := acctest.Context(t) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_networkflowmonitor_monitor.test" diff --git a/internal/service/networkflowmonitor/networkflowmonitor_test.go b/internal/service/networkflowmonitor/networkflowmonitor_test.go new file mode 100644 index 000000000000..deb1828a42c9 --- /dev/null +++ b/internal/service/networkflowmonitor/networkflowmonitor_test.go @@ -0,0 +1,30 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package networkflowmonitor_test + +import ( + "testing" + + "github.com/hashicorp/terraform-provider-aws/internal/acctest" +) + +func TestAccNetworkFlowMonitor_serial(t *testing.T) { + t.Parallel() + + testCases := map[string]map[string]func(t *testing.T){ + "Monitor": { + acctest.CtBasic: testAccMonitor_basic, + acctest.CtDisappears: testAccMonitor_disappears, + "tags": testAccMonitor_tags, + "update": testAccMonitor_update, + }, + "Scope": { + acctest.CtBasic: testAccScope_basic, + acctest.CtDisappears: testAccScope_disappears, + "tags": testAccScope_tags, + }, + } + + acctest.RunSerialTests2Levels(t, testCases, 0) +} diff --git a/internal/service/networkflowmonitor/scope_test.go b/internal/service/networkflowmonitor/scope_test.go index 6d7e7257231e..15d056411b64 100644 --- a/internal/service/networkflowmonitor/scope_test.go +++ b/internal/service/networkflowmonitor/scope_test.go @@ -19,21 +19,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/names" ) -func TestAccNetworkFlowMonitorScope_serial(t *testing.T) { - t.Parallel() - - testCases := map[string]map[string]func(t *testing.T){ - "Scope": { - acctest.CtBasic: testAccNetworkFlowMonitorScope_basic, - acctest.CtDisappears: testAccNetworkFlowMonitorScope_disappears, - "tags": testAccNetworkFlowMonitorScope_tags, - }, - } - - acctest.RunSerialTests2Levels(t, testCases, 0) -} - -func testAccNetworkFlowMonitorScope_basic(t *testing.T) { +func testAccScope_basic(t *testing.T) { ctx := acctest.Context(t) resourceName := "aws_networkflowmonitor_scope.test" @@ -64,7 +50,7 @@ func testAccNetworkFlowMonitorScope_basic(t *testing.T) { }) } -func testAccNetworkFlowMonitorScope_disappears(t *testing.T) { +func testAccScope_disappears(t *testing.T) { ctx := acctest.Context(t) resourceName := "aws_networkflowmonitor_scope.test" @@ -89,7 +75,7 @@ func testAccNetworkFlowMonitorScope_disappears(t *testing.T) { }) } -func testAccNetworkFlowMonitorScope_tags(t *testing.T) { +func testAccScope_tags(t *testing.T) { ctx := acctest.Context(t) resourceName := "aws_networkflowmonitor_scope.test" From aabce1a9ea2eae9a1bbb3f4a66bd2016d1b940f4 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 11 Nov 2025 14:10:45 -0500 Subject: [PATCH 12/21] Use a UUID for ClientToken. --- go.mod | 2 +- internal/service/networkflowmonitor/scope.go | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index ddb48900fbd2..489a3d36f2f0 100644 --- a/go.mod +++ b/go.mod @@ -281,7 +281,6 @@ require ( github.com/gertd/go-pluralize v0.2.1 github.com/goccy/go-yaml v1.18.0 github.com/google/go-cmp v0.7.0 - github.com/google/uuid v1.6.0 github.com/hashicorp/aws-cloudformation-resource-schema-sdk-go v0.23.0 github.com/hashicorp/aws-sdk-go-base/v2 v2.0.0-beta.68 github.com/hashicorp/awspolicyequivalence v1.7.0 @@ -347,6 +346,7 @@ require ( github.com/go-logr/logr v1.4.3 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/golang/protobuf v1.5.4 // indirect + github.com/google/uuid v1.6.0 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-checkpoint v0.5.0 // indirect github.com/hashicorp/go-plugin v1.7.0 // indirect diff --git a/internal/service/networkflowmonitor/scope.go b/internal/service/networkflowmonitor/scope.go index 9ee58bf4b442..cf2e7d84c638 100644 --- a/internal/service/networkflowmonitor/scope.go +++ b/internal/service/networkflowmonitor/scope.go @@ -11,6 +11,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/networkflowmonitor" awstypes "github.com/aws/aws-sdk-go-v2/service/networkflowmonitor/types" + uuid "github.com/hashicorp/go-uuid" "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "github.com/hashicorp/terraform-plugin-framework/diag" @@ -19,7 +20,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/schema/validator" "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/enum" "github.com/hashicorp/terraform-provider-aws/internal/errs" @@ -139,7 +139,8 @@ func (r *scopeResource) Create(ctx context.Context, request resource.CreateReque } // Additional fields. - input.ClientToken = aws.String(sdkid.UniqueId()) + uuid, _ := uuid.GenerateUUID() + input.ClientToken = aws.String(uuid) input.Tags = getTagsIn(ctx) output, err := conn.CreateScope(ctx, &input) From ae5ce8d7b84c0befb810f8839adcae8b05be026b Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 11 Nov 2025 14:47:50 -0500 Subject: [PATCH 13/21] r/aws_networkflowmonitor_scope: 'target' is a SetNestedBlock. --- internal/service/networkflowmonitor/scope.go | 23 ++--- .../service/networkflowmonitor/scope_test.go | 92 ++++++++++++++----- 2 files changed, 81 insertions(+), 34 deletions(-) diff --git a/internal/service/networkflowmonitor/scope.go b/internal/service/networkflowmonitor/scope.go index cf2e7d84c638..887c3d0de167 100644 --- a/internal/service/networkflowmonitor/scope.go +++ b/internal/service/networkflowmonitor/scope.go @@ -14,6 +14,7 @@ import ( uuid "github.com/hashicorp/go-uuid" "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" + "github.com/hashicorp/terraform-plugin-framework-validators/setvalidator" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" @@ -59,11 +60,11 @@ func (r *scopeResource) Schema(ctx context.Context, request resource.SchemaReque names.AttrTagsAll: tftags.TagsAttributeComputedOnly(), }, Blocks: map[string]schema.Block{ - "target": schema.ListNestedBlock{ - CustomType: fwtypes.NewListNestedObjectTypeOf[targetResourceModel](ctx), - Validators: []validator.List{ - listvalidator.SizeAtLeast(1), - listvalidator.IsRequired(), + "target": schema.SetNestedBlock{ + CustomType: fwtypes.NewSetNestedObjectTypeOf[targetResourceModel](ctx), + Validators: []validator.Set{ + setvalidator.SizeAtLeast(1), + setvalidator.IsRequired(), }, NestedObject: schema.NestedBlockObject{ Attributes: map[string]schema.Attribute{ @@ -478,12 +479,12 @@ func waitScopeDeleted(ctx context.Context, conn *networkflowmonitor.Client, id s type scopeResourceModel struct { framework.WithRegionModel - ScopeARN types.String `tfsdk:"scope_arn"` - ScopeID types.String `tfsdk:"scope_id"` - Tags tftags.Map `tfsdk:"tags"` - TagsAll tftags.Map `tfsdk:"tags_all"` - Targets fwtypes.ListNestedObjectValueOf[targetResourceModel] `tfsdk:"target"` - Timeouts timeouts.Value `tfsdk:"timeouts"` + ScopeARN types.String `tfsdk:"scope_arn"` + ScopeID types.String `tfsdk:"scope_id"` + Tags tftags.Map `tfsdk:"tags"` + TagsAll tftags.Map `tfsdk:"tags_all"` + Targets fwtypes.SetNestedObjectValueOf[targetResourceModel] `tfsdk:"target"` + Timeouts timeouts.Value `tfsdk:"timeouts"` } type targetResourceModel struct { diff --git a/internal/service/networkflowmonitor/scope_test.go b/internal/service/networkflowmonitor/scope_test.go index 15d056411b64..799274896dba 100644 --- a/internal/service/networkflowmonitor/scope_test.go +++ b/internal/service/networkflowmonitor/scope_test.go @@ -9,13 +9,17 @@ import ( "testing" "github.com/YakDriver/regexache" - awstypes "github.com/aws/aws-sdk-go-v2/service/networkflowmonitor/types" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/knownvalue" + "github.com/hashicorp/terraform-plugin-testing/plancheck" + "github.com/hashicorp/terraform-plugin-testing/statecheck" "github.com/hashicorp/terraform-plugin-testing/terraform" + "github.com/hashicorp/terraform-plugin-testing/tfjsonpath" "github.com/hashicorp/terraform-provider-aws/internal/acctest" + tfknownvalue "github.com/hashicorp/terraform-provider-aws/internal/acctest/knownvalue" "github.com/hashicorp/terraform-provider-aws/internal/conns" - "github.com/hashicorp/terraform-provider-aws/internal/errs" tfnetworkflowmonitor "github.com/hashicorp/terraform-provider-aws/internal/service/networkflowmonitor" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -36,15 +40,23 @@ func testAccScope_basic(t *testing.T) { Config: testAccScopeConfig_basic(), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckScopeExists(ctx, resourceName), - resource.TestMatchResourceAttr(resourceName, names.AttrARN, regexache.MustCompile(`^arn:[^:]+:networkflowmonitor:[^:]+:[^:]+:scope/.+$`)), - resource.TestCheckResourceAttrSet(resourceName, "scope_id"), - resource.TestCheckResourceAttrSet(resourceName, names.AttrStatus), ), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + }, + }, + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("scope_arn"), tfknownvalue.RegionalARNRegexp("networkflowmonitor", regexache.MustCompile(`scope/.+`))), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("scope_id"), knownvalue.NotNull()), + }, }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: acctest.AttrImportStateIdFunc(resourceName, "scope_id"), + ImportStateVerify: true, + ImportStateVerifyIdentifierAttribute: "scope_id", }, }, }) @@ -70,6 +82,14 @@ func testAccScope_disappears(t *testing.T) { acctest.CheckFrameworkResourceDisappears(ctx, acctest.Provider, tfnetworkflowmonitor.ResourceScope, resourceName), ), ExpectNonEmptyPlan: true, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + }, + PostApplyPostRefresh: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + }, + }, }, }, }) @@ -92,31 +112,57 @@ func testAccScope_tags(t *testing.T) { Config: testAccScopeConfig_tags1(acctest.CtKey1, acctest.CtValue1), Check: resource.ComposeTestCheckFunc( testAccCheckScopeExists(ctx, resourceName), - resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "1"), - resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey1, acctest.CtValue1), ), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + }, + }, + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: acctest.AttrImportStateIdFunc(resourceName, "scope_id"), + ImportStateVerify: true, + ImportStateVerifyIdentifierAttribute: "scope_id", }, { Config: testAccScopeConfig_tags2(acctest.CtKey1, acctest.CtValue1Updated, acctest.CtKey2, acctest.CtValue2), Check: resource.ComposeTestCheckFunc( testAccCheckScopeExists(ctx, resourceName), - resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "2"), - resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey1, acctest.CtValue1Updated), - resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey2, acctest.CtValue2), ), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + }, + }, + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1Updated), + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + }, }, { Config: testAccScopeConfig_tags1(acctest.CtKey2, acctest.CtValue2), Check: resource.ComposeTestCheckFunc( testAccCheckScopeExists(ctx, resourceName), - resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "1"), - resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey2, acctest.CtValue2), ), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + }, + }, + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + }, }, }, }) @@ -148,7 +194,7 @@ func testAccCheckScopeDestroy(ctx context.Context) resource.TestCheckFunc { _, err := tfnetworkflowmonitor.FindScopeByID(ctx, conn, rs.Primary.Attributes["scope_id"]) - if errs.IsA[*awstypes.ResourceNotFoundException](err) { + if tfresource.NotFound(err) { continue } @@ -156,7 +202,7 @@ func testAccCheckScopeDestroy(ctx context.Context) resource.TestCheckFunc { return err } - return fmt.Errorf("Network Flow Monitor Scope %s still exists", rs.Primary.ID) + return fmt.Errorf("Network Flow Monitor Scope %s still exists", rs.Primary.Attributes["scope_id"]) } return nil @@ -174,7 +220,7 @@ resource "aws_networkflowmonitor_scope" "test" { target_identifier { target_type = "ACCOUNT" target_id { - account_id = data.aws_caller_identity.current.account_id + account_id = data.aws_caller_identity.current.account_id } } } @@ -193,7 +239,7 @@ resource "aws_networkflowmonitor_scope" "test" { target_identifier { target_type = "ACCOUNT" target_id { - account_id = data.aws_caller_identity.current.account_id + account_id = data.aws_caller_identity.current.account_id } } } @@ -216,7 +262,7 @@ resource "aws_networkflowmonitor_scope" "test" { target_identifier { target_type = "ACCOUNT" target_id { - account_id = data.aws_caller_identity.current.account_id + account_id = data.aws_caller_identity.current.account_id } } } From 8eee934d752be16e73393eb21a5a931e92f3cba2 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 11 Nov 2025 15:07:02 -0500 Subject: [PATCH 14/21] Acceptance test output: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit % make testacc TESTARGS='-run=TestAccNetworkFlowMonitor_serial/Scope' PKG=networkflowmonitor make: Verifying source code with gofmt... ==> Checking that code complies with gofmt requirements... make: Running acceptance tests on branch: 🌿 HEAD 🌿... TF_ACC=1 go1.24.10 test ./internal/service/networkflowmonitor/... -v -count 1 -parallel 20 -run=TestAccNetworkFlowMonitor_serial/Scope -timeout 360m -vet=off 2025/11/11 14:48:21 Creating Terraform AWS Provider (SDKv2-style)... 2025/11/11 14:48:21 Initializing Terraform AWS Provider (SDKv2-style)... === RUN TestAccNetworkFlowMonitor_serial === PAUSE TestAccNetworkFlowMonitor_serial === CONT TestAccNetworkFlowMonitor_serial === RUN TestAccNetworkFlowMonitor_serial/Scope === RUN TestAccNetworkFlowMonitor_serial/Scope/tags === RUN TestAccNetworkFlowMonitor_serial/Scope/basic === RUN TestAccNetworkFlowMonitor_serial/Scope/disappears --- PASS: TestAccNetworkFlowMonitor_serial (1101.96s) --- PASS: TestAccNetworkFlowMonitor_serial/Scope (1101.96s) --- PASS: TestAccNetworkFlowMonitor_serial/Scope/tags (460.63s) --- PASS: TestAccNetworkFlowMonitor_serial/Scope/basic (328.29s) --- PASS: TestAccNetworkFlowMonitor_serial/Scope/disappears (313.05s) PASS ok github.com/hashicorp/terraform-provider-aws/internal/service/networkflowmonitor 1107.628s From 6827b4b7500b5b8138e62723c1e6246d92e6bf76 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 11 Nov 2025 16:30:46 -0500 Subject: [PATCH 15/21] r/aws_networkflowmonitor_scope: Implement Update. --- go.mod | 1 + go.sum | 4 + internal/service/networkflowmonitor/scope.go | 164 ++++-------------- .../service/networkflowmonitor/scope_test.go | 31 ++-- tools/tfsdk2fw/go.mod | 1 + tools/tfsdk2fw/go.sum | 4 + 6 files changed, 65 insertions(+), 140 deletions(-) diff --git a/go.mod b/go.mod index 489a3d36f2f0..2094417d2a98 100644 --- a/go.mod +++ b/go.mod @@ -289,6 +289,7 @@ require ( github.com/hashicorp/go-cty v1.5.0 github.com/hashicorp/go-hclog v1.6.3 github.com/hashicorp/go-multierror v1.1.1 + github.com/hashicorp/go-set/v3 v3.0.1 github.com/hashicorp/go-uuid v1.0.3 github.com/hashicorp/go-version v1.7.0 github.com/hashicorp/hcl/v2 v2.24.0 diff --git a/go.sum b/go.sum index f239954cf487..499e94115c97 100644 --- a/go.sum +++ b/go.sum @@ -658,6 +658,8 @@ github.com/hashicorp/go-plugin v1.7.0 h1:YghfQH/0QmPNc/AZMTFE3ac8fipZyZECHdDPshf github.com/hashicorp/go-plugin v1.7.0/go.mod h1:BExt6KEaIYx804z8k4gRzRLEvxKVb+kn0NMcihqOqb8= github.com/hashicorp/go-retryablehttp v0.7.7 h1:C8hUCYzor8PIfXHa4UrZkU4VvK8o9ISHxT2Q8+VepXU= github.com/hashicorp/go-retryablehttp v0.7.7/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk= +github.com/hashicorp/go-set/v3 v3.0.1 h1:ZwO15ZYmIrFYL9zSm2wBuwcRiHxVdp46m/XA/MUlM6I= +github.com/hashicorp/go-set/v3 v3.0.1/go.mod h1:0oPQqhtitglZeT2ZiWnRIfUG6gJAHnn7LzrS7SbgNY4= github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8= github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= @@ -763,6 +765,8 @@ github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0t github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8= github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4= +github.com/shoenig/test v1.12.1 h1:mLHfnMv7gmhhP44WrvT+nKSxKkPDiNkIuHGdIGI9RLU= +github.com/shoenig/test v1.12.1/go.mod h1:UxJ6u/x2v/TNs/LoLxBNJRV9DiwBBKYxXSyczsBHFoI= github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k= github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME= diff --git a/internal/service/networkflowmonitor/scope.go b/internal/service/networkflowmonitor/scope.go index 887c3d0de167..cdfa9b37b4d1 100644 --- a/internal/service/networkflowmonitor/scope.go +++ b/internal/service/networkflowmonitor/scope.go @@ -6,11 +6,13 @@ package networkflowmonitor import ( "context" "fmt" + "strings" "time" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/networkflowmonitor" awstypes "github.com/aws/aws-sdk-go-v2/service/networkflowmonitor/types" + set "github.com/hashicorp/go-set/v3" uuid "github.com/hashicorp/go-uuid" "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" @@ -206,147 +208,53 @@ func (r *scopeResource) Update(ctx context.Context, request resource.UpdateReque return } - //conn := r.Meta().NetworkFlowMonitorClient(ctx) - - // Handle targets updates - // if !new.Targets.Equal(old.Targets) { - // // Calculate targets to add and remove - // resourcesToAdd, resourcesToDelete, diags := r.calculateTargetChanges(ctx, old.Targets, new.Targets) - // response.Diagnostics.Append(diags...) - // if response.Diagnostics.HasError() { - // return - // } - - // // Update scope targets if there are changes - // if len(resourcesToAdd) > 0 || len(resourcesToDelete) > 0 { - // input := networkflowmonitor.UpdateScopeInput{ - // ScopeId: old.ScopeID.ValueStringPointer(), - // ResourcesToAdd: resourcesToAdd, - // ResourcesToDelete: resourcesToDelete, - // } - - // _, err := conn.UpdateScope(ctx, &input) - // if err != nil { - // response.Diagnostics.AddError(fmt.Sprintf("updating Network Flow Monitor Scope (%s) targets", new.ID.ValueString()), err.Error()) - // return - // } - - // // Wait for scope to be updated - // _, err = waitScopeUpdated(ctx, conn, old.ScopeID.ValueString(), r.UpdateTimeout(ctx, new.Timeouts)) - // if err != nil { - // response.Diagnostics.AddError(fmt.Sprintf("waiting for Network Flow Monitor Scope (%s) update", new.ID.ValueString()), err.Error()) - // return - // } - // } - // } + conn := r.Meta().NetworkFlowMonitorClient(ctx) - response.Diagnostics.Append(response.State.Set(ctx, &new)...) -} + diff, d := fwflex.Diff(ctx, new, old) + response.Diagnostics.Append(d...) + if response.Diagnostics.HasError() { + return + } -/* -func (r *scopeResource) calculateTargetChanges(ctx context.Context, oldTargets, newTargets fwtypes.ListNestedObjectValueOf[targetResourceModel]) ([]awstypes.TargetResource, []awstypes.TargetResource, diag.Diagnostics) { - var diags diag.Diagnostics - var resourcesToAdd, resourcesToDelete []awstypes.TargetResource - - // Convert old targets to map for easy lookup - oldTargetsMap := make(map[string]awstypes.TargetResource) - if !oldTargets.IsNull() && !oldTargets.IsUnknown() { - oldTargetsList, d := oldTargets.ToSlice(ctx) - diags.Append(d...) - if diags.HasError() { - return nil, nil, diags + if diff.HasChanges() { + var oldTargets, newTargets []awstypes.TargetResource + response.Diagnostics.Append(fwflex.Expand(ctx, old.Targets, &oldTargets)...) + if response.Diagnostics.HasError() { + return } - - for _, target := range oldTargetsList { - awsTarget := awstypes.TargetResource{ - Region: target.Region.ValueStringPointer(), - } - - // Handle union type for TargetIdentifier - if !target.TargetIdentifier.IsNull() && !target.TargetIdentifier.IsUnknown() { - identifiers, d := target.TargetIdentifier.ToSlice(ctx) - diags.Append(d...) - if diags.HasError() { - return nil, nil, diags - } - - if len(identifiers) > 0 { - identifier := identifiers[0] - awsTarget.TargetIdentifier = &awstypes.TargetIdentifier{ - TargetId: &awstypes.TargetIdMemberAccountId{ - Value: identifier.TargetId.ValueString(), - }, - TargetType: awstypes.TargetType(identifier.TargetType.ValueString()), - } - - // Create a key for the target (region + target_id + target_type) - key := fmt.Sprintf("%s:%s:%s", - target.Region.ValueString(), - identifier.TargetId.ValueString(), - identifier.TargetType.ValueString()) - oldTargetsMap[key] = awsTarget - } - } + response.Diagnostics.Append(fwflex.Expand(ctx, new.Targets, &newTargets)...) + if response.Diagnostics.HasError() { + return } - } - // Convert new targets to map and identify additions - newTargetsMap := make(map[string]awstypes.TargetResource) - if !newTargets.IsNull() && !newTargets.IsUnknown() { - newTargetsList, d := newTargets.ToSlice(ctx) - diags.Append(d...) - if diags.HasError() { - return nil, nil, diags + hash := func(v awstypes.TargetResource) string { + accountID := any(v.TargetIdentifier.TargetId).(*awstypes.TargetIdMemberAccountId).Value + return strings.Join([]string{aws.ToString(v.Region), string(v.TargetIdentifier.TargetType), accountID}, ":") + } + os, ns := set.HashSetFromFunc(oldTargets, hash), set.HashSetFromFunc(newTargets, hash) + add, del := ns.Difference(os), os.Difference(ns) + + scopeID := fwflex.StringValueFromFramework(ctx, new.ScopeID) + input := networkflowmonitor.UpdateScopeInput{ + ScopeId: aws.String(scopeID), + ResourcesToAdd: add.Slice(), + ResourcesToDelete: del.Slice(), } - for _, target := range newTargetsList { - awsTarget := awstypes.TargetResource{ - Region: target.Region.ValueStringPointer(), - } - - // Handle union type for TargetIdentifier - if !target.TargetIdentifier.IsNull() && !target.TargetIdentifier.IsUnknown() { - identifiers, d := target.TargetIdentifier.ToSlice(ctx) - diags.Append(d...) - if diags.HasError() { - return nil, nil, diags - } - - if len(identifiers) > 0 { - identifier := identifiers[0] - awsTarget.TargetIdentifier = &awstypes.TargetIdentifier{ - TargetId: &awstypes.TargetIdMemberAccountId{ - Value: identifier.TargetId.ValueString(), - }, - TargetType: awstypes.TargetType(identifier.TargetType.ValueString()), - } - - // Create a key for the target - key := fmt.Sprintf("%s:%s:%s", - target.Region.ValueString(), - identifier.TargetId.ValueString(), - identifier.TargetType.ValueString()) - newTargetsMap[key] = awsTarget - - // If this target doesn't exist in old targets, it's an addition - if _, exists := oldTargetsMap[key]; !exists { - resourcesToAdd = append(resourcesToAdd, awsTarget) - } - } - } + _, err := conn.UpdateScope(ctx, &input) + if err != nil { + response.Diagnostics.AddError(fmt.Sprintf("updating Network Flow Monitor Scope (%s) targets", scopeID), err.Error()) + return } - } - // Identify deletions - for key, target := range oldTargetsMap { - if _, exists := newTargetsMap[key]; !exists { - resourcesToDelete = append(resourcesToDelete, target) + if _, err := waitScopeUpdated(ctx, conn, scopeID, r.UpdateTimeout(ctx, new.Timeouts)); err != nil { + response.Diagnostics.AddError(fmt.Sprintf("waiting for Network Flow Monitor Scope (%s) update", scopeID), err.Error()) + return } } - return resourcesToAdd, resourcesToDelete, diags + response.Diagnostics.Append(response.State.Set(ctx, &new)...) } -*/ func (r *scopeResource) Delete(ctx context.Context, request resource.DeleteRequest, response *resource.DeleteResponse) { var data scopeResourceModel diff --git a/internal/service/networkflowmonitor/scope_test.go b/internal/service/networkflowmonitor/scope_test.go index 799274896dba..100a419a5bcc 100644 --- a/internal/service/networkflowmonitor/scope_test.go +++ b/internal/service/networkflowmonitor/scope_test.go @@ -9,6 +9,7 @@ import ( "testing" "github.com/YakDriver/regexache" + "github.com/hashicorp/aws-sdk-go-base/v2/endpoints" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/knownvalue" "github.com/hashicorp/terraform-plugin-testing/plancheck" @@ -30,6 +31,7 @@ func testAccScope_basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) + acctest.PreCheckPartition(t, endpoints.AwsPartitionID) testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), @@ -37,7 +39,7 @@ func testAccScope_basic(t *testing.T) { CheckDestroy: testAccCheckScopeDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccScopeConfig_basic(), + Config: testAccScopeConfig_basic(acctest.Region()), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckScopeExists(ctx, resourceName), ), @@ -49,6 +51,7 @@ func testAccScope_basic(t *testing.T) { ConfigStateChecks: []statecheck.StateCheck{ statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("scope_arn"), tfknownvalue.RegionalARNRegexp("networkflowmonitor", regexache.MustCompile(`scope/.+`))), statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("scope_id"), knownvalue.NotNull()), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("target"), knownvalue.SetSizeExact(1)), }, }, { @@ -69,6 +72,7 @@ func testAccScope_disappears(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) + acctest.PreCheckPartition(t, endpoints.AwsPartitionID) testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), @@ -76,7 +80,7 @@ func testAccScope_disappears(t *testing.T) { CheckDestroy: testAccCheckScopeDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccScopeConfig_basic(), + Config: testAccScopeConfig_basic(endpoints.UsWest2RegionID), Check: resource.ComposeTestCheckFunc( testAccCheckScopeExists(ctx, resourceName), acctest.CheckFrameworkResourceDisappears(ctx, acctest.Provider, tfnetworkflowmonitor.ResourceScope, resourceName), @@ -102,6 +106,7 @@ func testAccScope_tags(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) + acctest.PreCheckPartition(t, endpoints.AwsPartitionID) testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), @@ -209,23 +214,25 @@ func testAccCheckScopeDestroy(ctx context.Context) resource.TestCheckFunc { } } -func testAccScopeConfig_basic() string { - return ` +func testAccScopeConfig_basic(regions ...string) string { + return fmt.Sprintf(` data "aws_caller_identity" "current" {} -data "aws_region" "current" {} resource "aws_networkflowmonitor_scope" "test" { - target { - region = data.aws_region.current.name - target_identifier { - target_type = "ACCOUNT" - target_id { - account_id = data.aws_caller_identity.current.account_id + dynamic "target" { + for_each = [%[1]s] + content { + region = target.value + target_identifier { + target_type = "ACCOUNT" + target_id { + account_id = data.aws_caller_identity.current.account_id + } } } } } -` +`, acctest.ListOfStrings(regions...)) } func testAccScopeConfig_tags1(tagKey1, tagValue1 string) string { diff --git a/tools/tfsdk2fw/go.mod b/tools/tfsdk2fw/go.mod index 1deb51424e4c..fdea9962df2c 100644 --- a/tools/tfsdk2fw/go.mod +++ b/tools/tfsdk2fw/go.mod @@ -317,6 +317,7 @@ require ( github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/hashicorp/go-plugin v1.7.0 // indirect github.com/hashicorp/go-retryablehttp v0.7.7 // indirect + github.com/hashicorp/go-set/v3 v3.0.1 // indirect github.com/hashicorp/go-uuid v1.0.3 // indirect github.com/hashicorp/go-version v1.7.0 // indirect github.com/hashicorp/hc-install v0.9.2 // indirect diff --git a/tools/tfsdk2fw/go.sum b/tools/tfsdk2fw/go.sum index 52b52f214391..394055368c1c 100644 --- a/tools/tfsdk2fw/go.sum +++ b/tools/tfsdk2fw/go.sum @@ -656,6 +656,8 @@ github.com/hashicorp/go-plugin v1.7.0 h1:YghfQH/0QmPNc/AZMTFE3ac8fipZyZECHdDPshf github.com/hashicorp/go-plugin v1.7.0/go.mod h1:BExt6KEaIYx804z8k4gRzRLEvxKVb+kn0NMcihqOqb8= github.com/hashicorp/go-retryablehttp v0.7.7 h1:C8hUCYzor8PIfXHa4UrZkU4VvK8o9ISHxT2Q8+VepXU= github.com/hashicorp/go-retryablehttp v0.7.7/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk= +github.com/hashicorp/go-set/v3 v3.0.1 h1:ZwO15ZYmIrFYL9zSm2wBuwcRiHxVdp46m/XA/MUlM6I= +github.com/hashicorp/go-set/v3 v3.0.1/go.mod h1:0oPQqhtitglZeT2ZiWnRIfUG6gJAHnn7LzrS7SbgNY4= github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8= github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= @@ -758,6 +760,8 @@ github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0t github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8= github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4= +github.com/shoenig/test v1.12.1 h1:mLHfnMv7gmhhP44WrvT+nKSxKkPDiNkIuHGdIGI9RLU= +github.com/shoenig/test v1.12.1/go.mod h1:UxJ6u/x2v/TNs/LoLxBNJRV9DiwBBKYxXSyczsBHFoI= github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k= github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME= From 812d3cee3d1f42158512ba9068fac0943ea73d70 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 12 Nov 2025 08:58:02 -0500 Subject: [PATCH 16/21] r/aws_networkflowmonitor_scope: 'local_resources' -> 'local_resource' and 'remote_resources' -> 'remote_resource'. --- .../service/networkflowmonitor/monitor.go | 474 +++++++++--------- .../networkflowmonitor/monitor_test.go | 250 +++++---- internal/service/networkflowmonitor/scope.go | 2 + .../service/networkflowmonitor/scope_test.go | 1 + .../networkflowmonitor/service_package_gen.go | 2 +- .../networkflowmonitor_monitor.html.markdown | 26 +- 6 files changed, 371 insertions(+), 384 deletions(-) diff --git a/internal/service/networkflowmonitor/monitor.go b/internal/service/networkflowmonitor/monitor.go index a23849bba5b2..067c2f265f52 100644 --- a/internal/service/networkflowmonitor/monitor.go +++ b/internal/service/networkflowmonitor/monitor.go @@ -6,15 +6,16 @@ package networkflowmonitor import ( "context" "fmt" - "strings" "time" + "github.com/YakDriver/regexache" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/networkflowmonitor" awstypes "github.com/aws/aws-sdk-go-v2/service/networkflowmonitor/types" + uuid "github.com/hashicorp/go-uuid" "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" "github.com/hashicorp/terraform-plugin-framework-validators/setvalidator" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" @@ -35,7 +36,7 @@ import ( ) // @FrameworkResource("aws_networkflowmonitor_monitor", name="Monitor") -// @Tags(identifierAttribute="arn") +// @Tags(identifierAttribute="monitor_arn") func newMonitorResource(_ context.Context) (resource.ResourceWithConfigure, error) { r := &monitorResource{} @@ -47,7 +48,6 @@ func newMonitorResource(_ context.Context) (resource.ResourceWithConfigure, erro } type monitorResource struct { - framework.ResourceWithConfigure framework.ResourceWithModel[monitorResourceModel] framework.WithTimeouts } @@ -55,56 +55,57 @@ type monitorResource struct { func (r *monitorResource) Schema(ctx context.Context, request resource.SchemaRequest, response *resource.SchemaResponse) { response.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ - names.AttrARN: framework.ARNAttributeComputedOnly(), - names.AttrID: framework.IDAttribute(), + "monitor_arn": framework.ARNAttributeComputedOnly(), "monitor_name": schema.StringAttribute{ Required: true, + Validators: []validator.String{ + stringvalidator.LengthBetween(1, 255), + stringvalidator.RegexMatches(regexache.MustCompile(`[a-zA-Z0-9_.-]+`), ""), + }, PlanModifiers: []planmodifier.String{ stringplanmodifier.RequiresReplace(), }, }, "scope_arn": schema.StringAttribute{ - Required: true, + CustomType: fwtypes.ARNType, + Required: true, PlanModifiers: []planmodifier.String{ stringplanmodifier.RequiresReplace(), }, }, - "monitor_status": schema.StringAttribute{ - Computed: true, - PlanModifiers: []planmodifier.String{ - stringplanmodifier.UseStateForUnknown(), - }, - }, names.AttrTags: tftags.TagsAttribute(), names.AttrTagsAll: tftags.TagsAttributeComputedOnly(), }, Blocks: map[string]schema.Block{ - "local_resources": schema.SetNestedBlock{ - CustomType: fwtypes.NewSetNestedObjectTypeOf[monitorResourceConfigModel](ctx), + "local_resource": schema.SetNestedBlock{ + CustomType: fwtypes.NewSetNestedObjectTypeOf[monitorLocalResourceModel](ctx), Validators: []validator.Set{ setvalidator.SizeAtLeast(1), + setvalidator.IsRequired(), }, NestedObject: schema.NestedBlockObject{ Attributes: map[string]schema.Attribute{ - names.AttrType: schema.StringAttribute{ - Required: true, - }, names.AttrIdentifier: schema.StringAttribute{ Required: true, }, + names.AttrType: schema.StringAttribute{ + CustomType: fwtypes.StringEnumType[awstypes.MonitorLocalResourceType](), + Required: true, + }, }, }, }, - "remote_resources": schema.SetNestedBlock{ - CustomType: fwtypes.NewSetNestedObjectTypeOf[monitorResourceConfigModel](ctx), + "remote_resource": schema.SetNestedBlock{ + CustomType: fwtypes.NewSetNestedObjectTypeOf[monitorRemoteResourceModel](ctx), NestedObject: schema.NestedBlockObject{ Attributes: map[string]schema.Attribute{ - names.AttrType: schema.StringAttribute{ - Required: true, - }, names.AttrIdentifier: schema.StringAttribute{ Required: true, }, + names.AttrType: schema.StringAttribute{ + CustomType: fwtypes.StringEnumType[awstypes.MonitorRemoteResourceType](), + Required: true, + }, }, }, }, @@ -117,25 +118,6 @@ func (r *monitorResource) Schema(ctx context.Context, request resource.SchemaReq } } -type monitorResourceModel struct { - framework.WithRegionModel - ARN types.String `tfsdk:"arn"` - ID types.String `tfsdk:"id"` - MonitorName types.String `tfsdk:"monitor_name"` - ScopeArn types.String `tfsdk:"scope_arn"` - MonitorStatus types.String `tfsdk:"monitor_status"` - LocalResources fwtypes.SetNestedObjectValueOf[monitorResourceConfigModel] `tfsdk:"local_resources"` - RemoteResources fwtypes.SetNestedObjectValueOf[monitorResourceConfigModel] `tfsdk:"remote_resources"` - Tags tftags.Map `tfsdk:"tags"` - TagsAll tftags.Map `tfsdk:"tags_all"` - Timeouts timeouts.Value `tfsdk:"timeouts"` -} - -type monitorResourceConfigModel struct { - Type types.String `tfsdk:"type"` - Identifier types.String `tfsdk:"identifier"` -} - func (r *monitorResource) Create(ctx context.Context, request resource.CreateRequest, response *resource.CreateResponse) { var data monitorResourceModel response.Diagnostics.Append(request.Plan.Get(ctx, &data)...) @@ -145,13 +127,15 @@ func (r *monitorResource) Create(ctx context.Context, request resource.CreateReq conn := r.Meta().NetworkFlowMonitorClient(ctx) - input := networkflowmonitor.CreateMonitorInput{} + var input networkflowmonitor.CreateMonitorInput response.Diagnostics.Append(fwflex.Expand(ctx, data, &input)...) if response.Diagnostics.HasError() { return } - // Set additional fields that need special handling + // Additional fields. + uuid, _ := uuid.GenerateUUID() + input.ClientToken = aws.String(uuid) input.Tags = getTagsIn(ctx) output, err := conn.CreateMonitor(ctx, &input) @@ -161,18 +145,12 @@ func (r *monitorResource) Create(ctx context.Context, request resource.CreateReq return } - data.ID = types.StringValue(aws.ToString(output.MonitorArn)) - data.ARN = types.StringValue(aws.ToString(output.MonitorArn)) - - monitor, err := waitMonitorCreated(ctx, conn, data.MonitorName.ValueString(), r.CreateTimeout(ctx, data.Timeouts)) - if err != nil { - response.Diagnostics.AddError(fmt.Sprintf("waiting for Network Flow Monitor Monitor (%s) create", data.ID.ValueString()), err.Error()) - return - } + // Set values for unknowns. + data.MonitorARN = fwflex.StringToFramework(ctx, output.MonitorArn) - // Use fwflex.Flatten to set all attributes including tags_all - response.Diagnostics.Append(fwflex.Flatten(ctx, monitor, &data)...) - if response.Diagnostics.HasError() { + monitorName := fwflex.StringValueFromFramework(ctx, data.MonitorName) + if _, err := waitMonitorCreated(ctx, conn, monitorName, r.CreateTimeout(ctx, data.Timeouts)); err != nil { + response.Diagnostics.AddError(fmt.Sprintf("waiting for Network Flow Monitor Monitor (%s) create", monitorName), err.Error()) return } @@ -188,7 +166,8 @@ func (r *monitorResource) Read(ctx context.Context, request resource.ReadRequest conn := r.Meta().NetworkFlowMonitorClient(ctx) - monitor, err := findMonitorByName(ctx, conn, data.MonitorName.ValueString()) + monitorName := fwflex.StringValueFromFramework(ctx, data.MonitorName) + output, err := findMonitorByName(ctx, conn, monitorName) if tfresource.NotFound(err) { response.Diagnostics.Append(fwdiag.NewResourceNotFoundWarningDiagnostic(err)) @@ -197,25 +176,18 @@ func (r *monitorResource) Read(ctx context.Context, request resource.ReadRequest } if err != nil { - response.Diagnostics.AddError(fmt.Sprintf("reading Network Flow Monitor Monitor (%s)", data.ID.ValueString()), err.Error()) + response.Diagnostics.AddError(fmt.Sprintf("reading Network Flow Monitor Monitor (%s)", monitorName), err.Error()) return } - // Use fwflex.Flatten to automatically map API response to model - response.Diagnostics.Append(fwflex.Flatten(ctx, monitor, &data)...) + response.Diagnostics.Append(fwflex.Flatten(ctx, output, &data)...) if response.Diagnostics.HasError() { return } - // Ensure ID and ARN are set properly (especially important for import) - if data.ID.IsNull() || data.ID.IsUnknown() { - data.ID = types.StringValue(aws.ToString(monitor.MonitorArn)) - } - if data.ARN.IsNull() || data.ARN.IsUnknown() { - data.ARN = types.StringValue(aws.ToString(monitor.MonitorArn)) - } + setTagsOut(ctx, output.Tags) - response.Diagnostics.Append(response.State.Set(ctx, data)...) + response.Diagnostics.Append(response.State.Set(ctx, &data)...) } func (r *monitorResource) Update(ctx context.Context, request resource.UpdateRequest, response *resource.UpdateResponse) { @@ -231,155 +203,179 @@ func (r *monitorResource) Update(ctx context.Context, request resource.UpdateReq conn := r.Meta().NetworkFlowMonitorClient(ctx) - // Check if local_resources or remote_resources have changed - if !new.LocalResources.Equal(old.LocalResources) || !new.RemoteResources.Equal(old.RemoteResources) { - input := networkflowmonitor.UpdateMonitorInput{ - MonitorName: new.MonitorName.ValueStringPointer(), - } - - // Calculate local resources diff - oldLocalResources := make(map[string]awstypes.MonitorLocalResource) - newLocalResources := make(map[string]awstypes.MonitorLocalResource) - - // Build map of old local resources - if !old.LocalResources.IsNull() && !old.LocalResources.IsUnknown() { - oldLocalSlice, diags := old.LocalResources.ToSlice(ctx) - response.Diagnostics.Append(diags...) - if response.Diagnostics.HasError() { - return - } - for _, resource := range oldLocalSlice { - key := resource.Type.ValueString() + "|" + resource.Identifier.ValueString() - oldLocalResources[key] = awstypes.MonitorLocalResource{ - Type: awstypes.MonitorLocalResourceType(resource.Type.ValueString()), - Identifier: resource.Identifier.ValueStringPointer(), - } - } - } - - // Build map of new local resources - if !new.LocalResources.IsNull() && !new.LocalResources.IsUnknown() { - newLocalSlice, diags := new.LocalResources.ToSlice(ctx) - response.Diagnostics.Append(diags...) - if response.Diagnostics.HasError() { - return - } - for _, resource := range newLocalSlice { - key := resource.Type.ValueString() + "|" + resource.Identifier.ValueString() - newLocalResources[key] = awstypes.MonitorLocalResource{ - Type: awstypes.MonitorLocalResourceType(resource.Type.ValueString()), - Identifier: resource.Identifier.ValueStringPointer(), - } - } - } - - // Find resources to add (in new but not in old) - var localResourcesToAdd []awstypes.MonitorLocalResource - for key, resource := range newLocalResources { - if _, exists := oldLocalResources[key]; !exists { - localResourcesToAdd = append(localResourcesToAdd, resource) - } - } - - // Find resources to remove (in old but not in new) - var localResourcesToRemove []awstypes.MonitorLocalResource - for key, resource := range oldLocalResources { - if _, exists := newLocalResources[key]; !exists { - localResourcesToRemove = append(localResourcesToRemove, resource) - } - } - - // Calculate remote resources diff - oldRemoteResources := make(map[string]awstypes.MonitorRemoteResource) - newRemoteResources := make(map[string]awstypes.MonitorRemoteResource) - - // Build map of old remote resources - if !old.RemoteResources.IsNull() && !old.RemoteResources.IsUnknown() { - oldRemoteSlice, diags := old.RemoteResources.ToSlice(ctx) - response.Diagnostics.Append(diags...) - if response.Diagnostics.HasError() { - return - } - for _, resource := range oldRemoteSlice { - key := resource.Type.ValueString() + "|" + resource.Identifier.ValueString() - oldRemoteResources[key] = awstypes.MonitorRemoteResource{ - Type: awstypes.MonitorRemoteResourceType(resource.Type.ValueString()), - Identifier: resource.Identifier.ValueStringPointer(), - } - } - } - - // Build map of new remote resources - if !new.RemoteResources.IsNull() && !new.RemoteResources.IsUnknown() { - newRemoteSlice, diags := new.RemoteResources.ToSlice(ctx) - response.Diagnostics.Append(diags...) - if response.Diagnostics.HasError() { - return - } - for _, resource := range newRemoteSlice { - key := resource.Type.ValueString() + "|" + resource.Identifier.ValueString() - newRemoteResources[key] = awstypes.MonitorRemoteResource{ - Type: awstypes.MonitorRemoteResourceType(resource.Type.ValueString()), - Identifier: resource.Identifier.ValueStringPointer(), - } - } - } - - // Find resources to add (in new but not in old) - var remoteResourcesToAdd []awstypes.MonitorRemoteResource - for key, resource := range newRemoteResources { - if _, exists := oldRemoteResources[key]; !exists { - remoteResourcesToAdd = append(remoteResourcesToAdd, resource) - } - } - - // Find resources to remove (in old but not in new) - var remoteResourcesToRemove []awstypes.MonitorRemoteResource - for key, resource := range oldRemoteResources { - if _, exists := newRemoteResources[key]; !exists { - remoteResourcesToRemove = append(remoteResourcesToRemove, resource) - } - } + diff, d := fwflex.Diff(ctx, new, old) + response.Diagnostics.Append(d...) + if response.Diagnostics.HasError() { + return + } - // Set the calculated diffs in the input - if len(localResourcesToAdd) > 0 { - input.LocalResourcesToAdd = localResourcesToAdd - } - if len(localResourcesToRemove) > 0 { - input.LocalResourcesToRemove = localResourcesToRemove - } - if len(remoteResourcesToAdd) > 0 { - input.RemoteResourcesToAdd = remoteResourcesToAdd - } - if len(remoteResourcesToRemove) > 0 { - input.RemoteResourcesToRemove = remoteResourcesToRemove + if diff.HasChanges() { + monitorName := fwflex.StringValueFromFramework(ctx, new.MonitorName) + input := networkflowmonitor.UpdateMonitorInput{ + MonitorName: aws.String(monitorName), } _, err := conn.UpdateMonitor(ctx, &input) if err != nil { - response.Diagnostics.AddError(fmt.Sprintf("updating Network Flow Monitor Monitor (%s)", new.ID.ValueString()), err.Error()) + response.Diagnostics.AddError(fmt.Sprintf("updating Network Flow Monitor Monitor (%s)", monitorName), err.Error()) return } - // Wait for the update to complete - monitor, err := waitMonitorUpdated(ctx, conn, new.MonitorName.ValueString(), r.UpdateTimeout(ctx, new.Timeouts)) - if err != nil { - response.Diagnostics.AddError(fmt.Sprintf("waiting for Network Flow Monitor Monitor (%s) update", new.ID.ValueString()), err.Error()) + if _, err := waitMonitorUpdated(ctx, conn, monitorName, r.UpdateTimeout(ctx, new.Timeouts)); err != nil { + response.Diagnostics.AddError(fmt.Sprintf("waiting for Network Flow Monitor Monitor (%s) update", monitorName), err.Error()) return } - - // Update only the computed attributes, preserve the order of resources from configuration - new.MonitorStatus = types.StringValue(string(monitor.MonitorStatus)) - - // Ensure ID and ARN are set properly - if new.ID.IsNull() || new.ID.IsUnknown() { - new.ID = types.StringValue(aws.ToString(monitor.MonitorArn)) - } - if new.ARN.IsNull() || new.ARN.IsUnknown() { - new.ARN = types.StringValue(aws.ToString(monitor.MonitorArn)) - } } + // Check if local_resources or remote_resources have changed + // if !new.LocalResources.Equal(old.LocalResources) || !new.RemoteResources.Equal(old.RemoteResources) { + // input := networkflowmonitor.UpdateMonitorInput{ + // MonitorName: new.MonitorName.ValueStringPointer(), + // } + + // // Calculate local resources diff + // oldLocalResources := make(map[string]awstypes.MonitorLocalResource) + // newLocalResources := make(map[string]awstypes.MonitorLocalResource) + + // // Build map of old local resources + // if !old.LocalResources.IsNull() && !old.LocalResources.IsUnknown() { + // oldLocalSlice, diags := old.LocalResources.ToSlice(ctx) + // response.Diagnostics.Append(diags...) + // if response.Diagnostics.HasError() { + // return + // } + // for _, resource := range oldLocalSlice { + // key := resource.Type.ValueString() + "|" + resource.Identifier.ValueString() + // oldLocalResources[key] = awstypes.MonitorLocalResource{ + // Type: awstypes.MonitorLocalResourceType(resource.Type.ValueString()), + // Identifier: resource.Identifier.ValueStringPointer(), + // } + // } + // } + + // // Build map of new local resources + // if !new.LocalResources.IsNull() && !new.LocalResources.IsUnknown() { + // newLocalSlice, diags := new.LocalResources.ToSlice(ctx) + // response.Diagnostics.Append(diags...) + // if response.Diagnostics.HasError() { + // return + // } + // for _, resource := range newLocalSlice { + // key := resource.Type.ValueString() + "|" + resource.Identifier.ValueString() + // newLocalResources[key] = awstypes.MonitorLocalResource{ + // Type: awstypes.MonitorLocalResourceType(resource.Type.ValueString()), + // Identifier: resource.Identifier.ValueStringPointer(), + // } + // } + // } + + // // Find resources to add (in new but not in old) + // var localResourcesToAdd []awstypes.MonitorLocalResource + // for key, resource := range newLocalResources { + // if _, exists := oldLocalResources[key]; !exists { + // localResourcesToAdd = append(localResourcesToAdd, resource) + // } + // } + + // // Find resources to remove (in old but not in new) + // var localResourcesToRemove []awstypes.MonitorLocalResource + // for key, resource := range oldLocalResources { + // if _, exists := newLocalResources[key]; !exists { + // localResourcesToRemove = append(localResourcesToRemove, resource) + // } + // } + + // // Calculate remote resources diff + // oldRemoteResources := make(map[string]awstypes.MonitorRemoteResource) + // newRemoteResources := make(map[string]awstypes.MonitorRemoteResource) + + // // Build map of old remote resources + // if !old.RemoteResources.IsNull() && !old.RemoteResources.IsUnknown() { + // oldRemoteSlice, diags := old.RemoteResources.ToSlice(ctx) + // response.Diagnostics.Append(diags...) + // if response.Diagnostics.HasError() { + // return + // } + // for _, resource := range oldRemoteSlice { + // key := resource.Type.ValueString() + "|" + resource.Identifier.ValueString() + // oldRemoteResources[key] = awstypes.MonitorRemoteResource{ + // Type: awstypes.MonitorRemoteResourceType(resource.Type.ValueString()), + // Identifier: resource.Identifier.ValueStringPointer(), + // } + // } + // } + + // // Build map of new remote resources + // if !new.RemoteResources.IsNull() && !new.RemoteResources.IsUnknown() { + // newRemoteSlice, diags := new.RemoteResources.ToSlice(ctx) + // response.Diagnostics.Append(diags...) + // if response.Diagnostics.HasError() { + // return + // } + // for _, resource := range newRemoteSlice { + // key := resource.Type.ValueString() + "|" + resource.Identifier.ValueString() + // newRemoteResources[key] = awstypes.MonitorRemoteResource{ + // Type: awstypes.MonitorRemoteResourceType(resource.Type.ValueString()), + // Identifier: resource.Identifier.ValueStringPointer(), + // } + // } + // } + + // // Find resources to add (in new but not in old) + // var remoteResourcesToAdd []awstypes.MonitorRemoteResource + // for key, resource := range newRemoteResources { + // if _, exists := oldRemoteResources[key]; !exists { + // remoteResourcesToAdd = append(remoteResourcesToAdd, resource) + // } + // } + + // // Find resources to remove (in old but not in new) + // var remoteResourcesToRemove []awstypes.MonitorRemoteResource + // for key, resource := range oldRemoteResources { + // if _, exists := newRemoteResources[key]; !exists { + // remoteResourcesToRemove = append(remoteResourcesToRemove, resource) + // } + // } + + // // Set the calculated diffs in the input + // if len(localResourcesToAdd) > 0 { + // input.LocalResourcesToAdd = localResourcesToAdd + // } + // if len(localResourcesToRemove) > 0 { + // input.LocalResourcesToRemove = localResourcesToRemove + // } + // if len(remoteResourcesToAdd) > 0 { + // input.RemoteResourcesToAdd = remoteResourcesToAdd + // } + // if len(remoteResourcesToRemove) > 0 { + // input.RemoteResourcesToRemove = remoteResourcesToRemove + // } + + // _, err := conn.UpdateMonitor(ctx, &input) + // if err != nil { + // response.Diagnostics.AddError(fmt.Sprintf("updating Network Flow Monitor Monitor (%s)", new.ID.ValueString()), err.Error()) + // return + // } + + // // Wait for the update to complete + // monitor, err := waitMonitorUpdated(ctx, conn, new.MonitorName.ValueString(), r.UpdateTimeout(ctx, new.Timeouts)) + // if err != nil { + // response.Diagnostics.AddError(fmt.Sprintf("waiting for Network Flow Monitor Monitor (%s) update", new.ID.ValueString()), err.Error()) + // return + // } + + // // Update only the computed attributes, preserve the order of resources from configuration + // new.MonitorStatus = types.StringValue(string(monitor.MonitorStatus)) + + // // Ensure ID and ARN are set properly + // if new.ID.IsNull() || new.ID.IsUnknown() { + // new.ID = types.StringValue(aws.ToString(monitor.MonitorArn)) + // } + // if new.ARN.IsNull() || new.ARN.IsUnknown() { + // new.ARN = types.StringValue(aws.ToString(monitor.MonitorArn)) + // } + // } + response.Diagnostics.Append(response.State.Set(ctx, &new)...) } @@ -392,8 +388,9 @@ func (r *monitorResource) Delete(ctx context.Context, request resource.DeleteReq conn := r.Meta().NetworkFlowMonitorClient(ctx) + monitorName := fwflex.StringValueFromFramework(ctx, data.MonitorName) input := networkflowmonitor.DeleteMonitorInput{ - MonitorName: data.MonitorName.ValueStringPointer(), + MonitorName: aws.String(monitorName), } _, err := conn.DeleteMonitor(ctx, &input) @@ -402,49 +399,18 @@ func (r *monitorResource) Delete(ctx context.Context, request resource.DeleteReq } if err != nil { - response.Diagnostics.AddError(fmt.Sprintf("deleting Network Flow Monitor Monitor (%s)", data.ID.ValueString()), err.Error()) + response.Diagnostics.AddError(fmt.Sprintf("deleting Network Flow Monitor Monitor (%s)", monitorName), err.Error()) return } - if _, err := waitMonitorDeleted(ctx, conn, data.MonitorName.ValueString(), r.DeleteTimeout(ctx, data.Timeouts)); err != nil { - response.Diagnostics.AddError(fmt.Sprintf("waiting for Network Flow Monitor Monitor (%s) delete", data.ID.ValueString()), err.Error()) + if _, err := waitMonitorDeleted(ctx, conn, monitorName, r.DeleteTimeout(ctx, data.Timeouts)); err != nil { + response.Diagnostics.AddError(fmt.Sprintf("waiting for Network Flow Monitor Monitor (%s) delete", monitorName), err.Error()) return } } func (r *monitorResource) ImportState(ctx context.Context, request resource.ImportStateRequest, response *resource.ImportStateResponse) { - // The import ID can be either an ARN or a monitor name - id := request.ID - - // If it's an ARN, extract the monitor name - if arn.IsARN(id) { - parsedARN, err := arn.Parse(id) - if err != nil { - response.Diagnostics.AddError("Invalid ARN", fmt.Sprintf("Unable to parse ARN (%s): %s", id, err)) - return - } - - if parsedARN.Service != "networkflowmonitor" { - response.Diagnostics.AddError("Invalid ARN", fmt.Sprintf("Expected networkflowmonitor service ARN, got: %s", parsedARN.Service)) - return - } - - // ARN format: arn:partition:networkflowmonitor:region:account:monitor/monitor-name - parts := strings.Split(parsedARN.Resource, "/") - if len(parts) != 2 || parts[0] != "monitor" { - response.Diagnostics.AddError("Invalid import ID", fmt.Sprintf("Expected ARN format 'arn:partition:networkflowmonitor:region:account:monitor/monitor-name', got: %s", id)) - return - } - monitorName := parts[1] - - // Set both ID (ARN) and monitor_name - response.Diagnostics.Append(response.State.SetAttribute(ctx, path.Root(names.AttrID), id)...) - response.Diagnostics.Append(response.State.SetAttribute(ctx, path.Root("monitor_name"), monitorName)...) - } else { - // Assume it's a monitor name, we'll need to construct the ARN during read - response.Diagnostics.Append(response.State.SetAttribute(ctx, path.Root("monitor_name"), id)...) - // ID will be set during the subsequent Read operation - } + response.Diagnostics.Append(response.State.SetAttribute(ctx, path.Root("monitor_name"), request.ID)...) } func findMonitorByName(ctx context.Context, conn *networkflowmonitor.Client, name string) (*networkflowmonitor.GetMonitorOutput, error) { @@ -452,7 +418,11 @@ func findMonitorByName(ctx context.Context, conn *networkflowmonitor.Client, nam MonitorName: aws.String(name), } - output, err := conn.GetMonitor(ctx, &input) + return findMonitor(ctx, conn, &input) +} + +func findMonitor(ctx context.Context, conn *networkflowmonitor.Client, input *networkflowmonitor.GetMonitorInput) (*networkflowmonitor.GetMonitorOutput, error) { + output, err := conn.GetMonitor(ctx, input) if errs.IsA[*awstypes.ResourceNotFoundException](err) { return nil, &retry.NotFoundError{ @@ -538,3 +508,25 @@ func waitMonitorDeleted(ctx context.Context, conn *networkflowmonitor.Client, na return nil, err } + +type monitorResourceModel struct { + framework.WithRegionModel + LocalResources fwtypes.SetNestedObjectValueOf[monitorLocalResourceModel] `tfsdk:"local_resource"` + MonitorARN types.String `tfsdk:"monitor_arn"` + MonitorName types.String `tfsdk:"monitor_name"` + RemoteResources fwtypes.SetNestedObjectValueOf[monitorRemoteResourceModel] `tfsdk:"remote_resource"` + ScopeARN fwtypes.ARN `tfsdk:"scope_arn"` + Tags tftags.Map `tfsdk:"tags"` + TagsAll tftags.Map `tfsdk:"tags_all"` + Timeouts timeouts.Value `tfsdk:"timeouts"` +} + +type monitorLocalResourceModel struct { + Identifier types.String `tfsdk:"identifier"` + Type fwtypes.StringEnum[awstypes.MonitorLocalResourceType] `tfsdk:"type"` +} + +type monitorRemoteResourceModel struct { + Identifier types.String `tfsdk:"identifier"` + Type fwtypes.StringEnum[awstypes.MonitorRemoteResourceType] `tfsdk:"type"` +} diff --git a/internal/service/networkflowmonitor/monitor_test.go b/internal/service/networkflowmonitor/monitor_test.go index e60c97186aed..58baa5c97a41 100644 --- a/internal/service/networkflowmonitor/monitor_test.go +++ b/internal/service/networkflowmonitor/monitor_test.go @@ -9,14 +9,19 @@ import ( "testing" "github.com/aws/aws-sdk-go-v2/service/networkflowmonitor" - awstypes "github.com/aws/aws-sdk-go-v2/service/networkflowmonitor/types" + "github.com/hashicorp/aws-sdk-go-base/v2/endpoints" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/knownvalue" + "github.com/hashicorp/terraform-plugin-testing/plancheck" + "github.com/hashicorp/terraform-plugin-testing/statecheck" "github.com/hashicorp/terraform-plugin-testing/terraform" + "github.com/hashicorp/terraform-plugin-testing/tfjsonpath" "github.com/hashicorp/terraform-provider-aws/internal/acctest" + tfknownvalue "github.com/hashicorp/terraform-provider-aws/internal/acctest/knownvalue" "github.com/hashicorp/terraform-provider-aws/internal/conns" - "github.com/hashicorp/terraform-provider-aws/internal/errs" tfnetworkflowmonitor "github.com/hashicorp/terraform-provider-aws/internal/service/networkflowmonitor" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -28,6 +33,7 @@ func testAccMonitor_basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) + acctest.PreCheckPartition(t, endpoints.AwsPartitionID) testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), @@ -38,16 +44,23 @@ func testAccMonitor_basic(t *testing.T) { Config: testAccMonitorConfig_basic(rName), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckMonitorExists(ctx, resourceName), - resource.TestCheckResourceAttr(resourceName, "monitor_name", rName), - acctest.CheckResourceAttrRegionalARN(ctx, resourceName, names.AttrARN, "networkflowmonitor", fmt.Sprintf("monitor/%s", rName)), - resource.TestCheckResourceAttrSet(resourceName, "monitor_status"), ), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + }, + }, + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("scope_arn"), tfknownvalue.RegionalARNExact("networkflowmonitor", `monitor/`+rName)), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), + }, }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"scope_arn"}, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: acctest.AttrImportStateIdFunc(resourceName, "monitor_name"), + ImportStateVerify: true, + ImportStateVerifyIdentifierAttribute: "monitor_name", }, }, }) @@ -61,6 +74,7 @@ func testAccMonitor_disappears(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) + acctest.PreCheckPartition(t, endpoints.AwsPartitionID) testAccPreCheck(ctx, t) }, ErrorCheck: acctest.ErrorCheck(t, names.NetworkFlowMonitorServiceID), @@ -74,6 +88,14 @@ func testAccMonitor_disappears(t *testing.T) { acctest.CheckFrameworkResourceDisappears(ctx, acctest.Provider, tfnetworkflowmonitor.ResourceMonitor, resourceName), ), ExpectNonEmptyPlan: true, + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + }, + PostApplyPostRefresh: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + }, + }, }, }, }) @@ -97,32 +119,57 @@ func testAccMonitor_tags(t *testing.T) { Config: testAccMonitorConfig_tags1(rName, acctest.CtKey1, acctest.CtValue1), Check: resource.ComposeTestCheckFunc( testAccCheckMonitorExists(ctx, resourceName), - resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "1"), - resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey1, acctest.CtValue1), ), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + }, + }, + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1), + })), + }, }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"scope_arn"}, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: acctest.AttrImportStateIdFunc(resourceName, "monitor_name"), + ImportStateVerify: true, + ImportStateVerifyIdentifierAttribute: "monitor_name", }, { Config: testAccMonitorConfig_tags2(rName, acctest.CtKey1, acctest.CtValue1Updated, acctest.CtKey2, acctest.CtValue2), Check: resource.ComposeTestCheckFunc( testAccCheckMonitorExists(ctx, resourceName), - resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "2"), - resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey1, acctest.CtValue1Updated), - resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey2, acctest.CtValue2), ), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + }, + }, + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey1: knownvalue.StringExact(acctest.CtValue1Updated), + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + }, }, { Config: testAccMonitorConfig_tags1(rName, acctest.CtKey2, acctest.CtValue2), Check: resource.ComposeTestCheckFunc( testAccCheckMonitorExists(ctx, resourceName), - resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "1"), - resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey2, acctest.CtValue2), ), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + }, + }, + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.MapExact(map[string]knownvalue.Check{ + acctest.CtKey2: knownvalue.StringExact(acctest.CtValue2), + })), + }, }, }, }) @@ -147,7 +194,7 @@ func testAccMonitor_update(t *testing.T) { Check: resource.ComposeAggregateTestCheckFunc( testAccCheckMonitorExists(ctx, resourceName), resource.TestCheckResourceAttr(resourceName, "monitor_name", rName), - resource.TestCheckResourceAttr(resourceName, "local_resources.0.type", "AWS::EC2::VPC"), + resource.TestCheckResourceAttr(resourceName, "local_resource.0.type", "AWS::EC2::VPC"), ), }, //adding one more local resource to monitor @@ -156,8 +203,8 @@ func testAccMonitor_update(t *testing.T) { Check: resource.ComposeAggregateTestCheckFunc( testAccCheckMonitorExists(ctx, resourceName), resource.TestCheckResourceAttr(resourceName, "monitor_name", rName), - resource.TestCheckResourceAttr(resourceName, "local_resources.#", "2"), - resource.TestCheckResourceAttr(resourceName, "remote_resources.#", "1"), + resource.TestCheckResourceAttr(resourceName, "local_resource.#", "2"), + resource.TestCheckResourceAttr(resourceName, "remote_resource.#", "1"), ), }, //reverting local resources to single resource. @@ -166,9 +213,9 @@ func testAccMonitor_update(t *testing.T) { Check: resource.ComposeAggregateTestCheckFunc( testAccCheckMonitorExists(ctx, resourceName), resource.TestCheckResourceAttr(resourceName, "monitor_name", rName), - resource.TestCheckResourceAttr(resourceName, "local_resources.#", "1"), - resource.TestCheckResourceAttr(resourceName, "remote_resources.#", "1"), - resource.TestCheckResourceAttr(resourceName, "local_resources.0.type", "AWS::EC2::VPC"), + resource.TestCheckResourceAttr(resourceName, "local_resource.#", "1"), + resource.TestCheckResourceAttr(resourceName, "remote_resource.#", "1"), + resource.TestCheckResourceAttr(resourceName, "local_resource.0.type", "AWS::EC2::VPC"), ), }, //adding 2 local resources and 2 remote resources @@ -177,8 +224,8 @@ func testAccMonitor_update(t *testing.T) { Check: resource.ComposeAggregateTestCheckFunc( testAccCheckMonitorExists(ctx, resourceName), resource.TestCheckResourceAttr(resourceName, "monitor_name", rName), - resource.TestCheckResourceAttr(resourceName, "local_resources.#", "2"), - resource.TestCheckResourceAttr(resourceName, "remote_resources.#", "2"), + resource.TestCheckResourceAttr(resourceName, "local_resource.#", "2"), + resource.TestCheckResourceAttr(resourceName, "remote_resource.#", "2"), ), }, //reverting local resources to single resource. @@ -187,9 +234,9 @@ func testAccMonitor_update(t *testing.T) { Check: resource.ComposeAggregateTestCheckFunc( testAccCheckMonitorExists(ctx, resourceName), resource.TestCheckResourceAttr(resourceName, "monitor_name", rName), - resource.TestCheckResourceAttr(resourceName, "local_resources.#", "1"), - resource.TestCheckResourceAttr(resourceName, "remote_resources.#", "1"), - resource.TestCheckResourceAttr(resourceName, "local_resources.0.type", "AWS::EC2::VPC"), + resource.TestCheckResourceAttr(resourceName, "local_resource.#", "1"), + resource.TestCheckResourceAttr(resourceName, "remote_resource.#", "1"), + resource.TestCheckResourceAttr(resourceName, "local_resource.0.type", "AWS::EC2::VPC"), ), }, }, @@ -222,7 +269,7 @@ func testAccCheckMonitorDestroy(ctx context.Context) resource.TestCheckFunc { _, err := tfnetworkflowmonitor.FindMonitorByName(ctx, conn, rs.Primary.Attributes["monitor_name"]) - if errs.IsA[*awstypes.ResourceNotFoundException](err) { + if tfresource.NotFound(err) { continue } @@ -230,58 +277,54 @@ func testAccCheckMonitorDestroy(ctx context.Context) resource.TestCheckFunc { return err } - return fmt.Errorf("Network Flow Monitor Monitor %s still exists", rs.Primary.ID) + return fmt.Errorf("Network Flow Monitor Monitor %s still exists", rs.Primary.Attributes["monitor_name"]) } return nil } } -func testAccMonitorConfig_basic(rName string) string { - return fmt.Sprintf(` +const testAccMonitorConfig_base = ` data "aws_caller_identity" "current" {} data "aws_region" "current" {} -resource "aws_vpc" "test" { - cidr_block = "10.0.0.0/16" - - tags = { - Name = %[1]q - } -} - resource "aws_networkflowmonitor_scope" "test" { - targets { + target { region = data.aws_region.current.name target_identifier { - target_id = data.aws_caller_identity.current.account_id target_type = "ACCOUNT" + target_id { + account_id = data.aws_caller_identity.current.account_id + } } } } +` -resource "aws_networkflowmonitor_monitor" "test" { - monitor_name = %[1]q - scope_arn = aws_networkflowmonitor_scope.test.arn +func testAccMonitorConfig_basic(rName string) string { + return acctest.ConfigCompose(testAccMonitorConfig_base, fmt.Sprintf(` +resource "aws_vpc" "test" { + cidr_block = "10.0.0.0/16" - local_resources { - type = "AWS::EC2::VPC" - identifier = aws_vpc.test.arn + tags = { + Name = %[1]q } +} - remote_resources { +resource "aws_networkflowmonitor_monitor" "test" { + monitor_name = %[1]q + scope_arn = aws_networkflowmonitor_scope.test.scope_arn + + local_resource { type = "AWS::EC2::VPC" identifier = aws_vpc.test.arn } } -`, rName) +`, rName)) } func testAccMonitorConfig_tags1(rName, tagKey1, tagValue1 string) string { - return fmt.Sprintf(` -data "aws_caller_identity" "current" {} -data "aws_region" "current" {} - + return acctest.ConfigCompose(testAccMonitorConfig_base, fmt.Sprintf(` resource "aws_vpc" "test" { cidr_block = "10.0.0.0/16" @@ -290,26 +333,16 @@ resource "aws_vpc" "test" { } } -resource "aws_networkflowmonitor_scope" "test" { - targets { - region = data.aws_region.current.name - target_identifier { - target_id = data.aws_caller_identity.current.account_id - target_type = "ACCOUNT" - } - } -} - resource "aws_networkflowmonitor_monitor" "test" { monitor_name = %[1]q - scope_arn = aws_networkflowmonitor_scope.test.arn + scope_arn = aws_networkflowmonitor_scope.test.scope_arn - local_resources { + local_resource { type = "AWS::EC2::VPC" identifier = aws_vpc.test.arn } - remote_resources { + remote_resource { type = "AWS::EC2::VPC" identifier = aws_vpc.test.arn } @@ -318,14 +351,11 @@ resource "aws_networkflowmonitor_monitor" "test" { %[2]q = %[3]q } } -`, rName, tagKey1, tagValue1) +`, rName, tagKey1, tagValue1)) } func testAccMonitorConfig_tags2(rName, tagKey1, tagValue1, tagKey2, tagValue2 string) string { - return fmt.Sprintf(` -data "aws_caller_identity" "current" {} -data "aws_region" "current" {} - + return acctest.ConfigCompose(testAccMonitorConfig_base, fmt.Sprintf(` resource "aws_vpc" "test" { cidr_block = "10.0.0.0/16" @@ -334,26 +364,16 @@ resource "aws_vpc" "test" { } } -resource "aws_networkflowmonitor_scope" "test" { - targets { - region = data.aws_region.current.name - target_identifier { - target_id = data.aws_caller_identity.current.account_id - target_type = "ACCOUNT" - } - } -} - resource "aws_networkflowmonitor_monitor" "test" { monitor_name = %[1]q - scope_arn = aws_networkflowmonitor_scope.test.arn + scope_arn = aws_networkflowmonitor_scope.test.scope_arn - local_resources { + local_resource { type = "AWS::EC2::VPC" identifier = aws_vpc.test.arn } - remote_resources { + remote_resource { type = "AWS::EC2::VPC" identifier = aws_vpc.test.arn } @@ -363,14 +383,11 @@ resource "aws_networkflowmonitor_monitor" "test" { %[4]q = %[5]q } } -`, rName, tagKey1, tagValue1, tagKey2, tagValue2) +`, rName, tagKey1, tagValue1, tagKey2, tagValue2)) } func testAccMonitorConfig_updated1(rName string) string { - return fmt.Sprintf(` -data "aws_caller_identity" "current" {} -data "aws_region" "current" {} - + return acctest.ConfigCompose(testAccMonitorConfig_base, fmt.Sprintf(` resource "aws_vpc" "test" { cidr_block = "10.0.0.0/16" @@ -388,43 +405,30 @@ resource "aws_subnet" "test" { } } -resource "aws_networkflowmonitor_scope" "test" { - targets { - region = data.aws_region.current.name - target_identifier { - target_id = data.aws_caller_identity.current.account_id - target_type = "ACCOUNT" - } - } -} - resource "aws_networkflowmonitor_monitor" "test" { monitor_name = %[1]q - scope_arn = aws_networkflowmonitor_scope.test.arn + scope_arn = aws_networkflowmonitor_scope.test.scope_arn - local_resources { + local_resource { type = "AWS::EC2::VPC" identifier = aws_vpc.test.arn } - local_resources { + local_resource { type = "AWS::EC2::Subnet" identifier = aws_subnet.test.arn } - remote_resources { + remote_resource { type = "AWS::EC2::VPC" identifier = aws_vpc.test.arn } } -`, rName) +`, rName)) } func testAccMonitorConfig_updated2(rName string) string { - return fmt.Sprintf(` -data "aws_caller_identity" "current" {} -data "aws_region" "current" {} - + return acctest.ConfigCompose(testAccMonitorConfig_base, fmt.Sprintf(` resource "aws_vpc" "test" { cidr_block = "10.0.0.0/16" @@ -442,41 +446,31 @@ resource "aws_subnet" "test" { } } -resource "aws_networkflowmonitor_scope" "test" { - targets { - region = data.aws_region.current.name - target_identifier { - target_id = data.aws_caller_identity.current.account_id - target_type = "ACCOUNT" - } - } -} - resource "aws_networkflowmonitor_monitor" "test" { monitor_name = %[1]q - scope_arn = aws_networkflowmonitor_scope.test.arn + scope_arn = aws_networkflowmonitor_scope.test.scope_arn - local_resources { + local_resource { type = "AWS::EC2::VPC" identifier = aws_vpc.test.arn } - local_resources { + local_resource { type = "AWS::EC2::Subnet" identifier = aws_subnet.test.arn } - remote_resources { + remote_resource { type = "AWS::EC2::VPC" identifier = aws_vpc.test.arn } - remote_resources { + remote_resource { type = "AWS::EC2::Subnet" identifier = aws_subnet.test.arn } } -`, rName) +`, rName)) } func testAccPreCheck(ctx context.Context, t *testing.T) { diff --git a/internal/service/networkflowmonitor/scope.go b/internal/service/networkflowmonitor/scope.go index cdfa9b37b4d1..3d6b23af3692 100644 --- a/internal/service/networkflowmonitor/scope.go +++ b/internal/service/networkflowmonitor/scope.go @@ -194,6 +194,8 @@ func (r *scopeResource) Read(ctx context.Context, request resource.ReadRequest, return } + setTagsOut(ctx, output.Tags) + response.Diagnostics.Append(response.State.Set(ctx, &data)...) } diff --git a/internal/service/networkflowmonitor/scope_test.go b/internal/service/networkflowmonitor/scope_test.go index 100a419a5bcc..2e7fb17883f5 100644 --- a/internal/service/networkflowmonitor/scope_test.go +++ b/internal/service/networkflowmonitor/scope_test.go @@ -51,6 +51,7 @@ func testAccScope_basic(t *testing.T) { ConfigStateChecks: []statecheck.StateCheck{ statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("scope_arn"), tfknownvalue.RegionalARNRegexp("networkflowmonitor", regexache.MustCompile(`scope/.+`))), statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("scope_id"), knownvalue.NotNull()), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("target"), knownvalue.SetSizeExact(1)), }, }, diff --git a/internal/service/networkflowmonitor/service_package_gen.go b/internal/service/networkflowmonitor/service_package_gen.go index 26d25c6646fd..b2b7102fc458 100644 --- a/internal/service/networkflowmonitor/service_package_gen.go +++ b/internal/service/networkflowmonitor/service_package_gen.go @@ -28,7 +28,7 @@ func (p *servicePackage) FrameworkResources(ctx context.Context) []*inttypes.Ser TypeName: "aws_networkflowmonitor_monitor", Name: "Monitor", Tags: unique.Make(inttypes.ServicePackageResourceTags{ - IdentifierAttribute: names.AttrARN, + IdentifierAttribute: "monitor_arn", }), Region: unique.Make(inttypes.ResourceRegionDefault()), }, diff --git a/website/docs/r/networkflowmonitor_monitor.html.markdown b/website/docs/r/networkflowmonitor_monitor.html.markdown index 5bafe30ae8c3..e2a46feaa553 100644 --- a/website/docs/r/networkflowmonitor_monitor.html.markdown +++ b/website/docs/r/networkflowmonitor_monitor.html.markdown @@ -25,14 +25,14 @@ resource "aws_vpc" "example" { resource "aws_networkflowmonitor_monitor" "example" { monitor_name = "example-monitor" - scope_arn = aws_networkflowmonitor_scope.example.arn + scope_arn = aws_networkflowmonitor_scope.example.scope_arn - local_resources { + local_resource { type = "AWS::EC2::VPC" identifier = aws_vpc.example.arn } - remote_resources { + remote_resource { type = "AWS::EC2::VPC" identifier = aws_vpc.example.arn } @@ -52,14 +52,14 @@ The following arguments are required: The following arguments are optional: -* `local_resources` - (Optional) The local resources to monitor. A local resource in a workload is the location of the hosts where the Network Flow Monitor agent is installed. +* `local_resource` - (Optional) The local resources to monitor. A local resource in a workload is the location of the hosts where the Network Flow Monitor agent is installed. * `region` - (Optional) Region where this resource will be [managed](https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints). Defaults to the Region set in the [provider configuration](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#aws-configuration-reference). -* `remote_resources` - (Optional) The remote resources to monitor. A remote resource is the other endpoint specified for the network flow of a workload, with a local resource. +* `remote_resource` - (Optional) The remote resources to monitor. A remote resource is the other endpoint specified for the network flow of a workload, with a local resource. * `tags` - (Optional) A 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. -### local_resources and remote_resources +### local_resource and remote_resource -The `local_resources` and `remote_resources` blocks support the following: +The `local_resource` and `remote_resource` blocks support the following: * `type` - (Required) The type of the resource. Valid values are `AWS::EC2::VPC`, `AWS::EC2::Subnet`, `AWS::EC2::AvailabilityZone`, `AWS::EC2::Region`. * `identifier` - (Required) The identifier of the resource. For VPC resources, this is the VPC ARN. @@ -68,9 +68,7 @@ The `local_resources` and `remote_resources` blocks support the following: This resource exports the following attributes in addition to the arguments above: -* `arn` - The Amazon Resource Name (ARN) of the monitor. -* `id` - The Amazon Resource Name (ARN) of the monitor. -* `monitor_status` - The status of the monitor. Can be `PENDING`, `ACTIVE`, `INACTIVE`, `ERROR`, or `DELETING`. +* `monitor_arn` - The Amazon Resource Name (ARN) of the monitor. * `tags_all` - A 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 @@ -83,17 +81,17 @@ This resource exports the following attributes in addition to the arguments abov ## Import -In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import Network Flow Monitor Monitor using the monitor ARN. For example: +In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import Network Flow Monitor Monitor using the monitor name. For example: ```terraform import { to = aws_networkflowmonitor_monitor.example - id = "arn:aws:networkflowmonitor:us-west-2:123456789012:monitor/example-monitor" + id = "example-monitor" } ``` -Using `terraform import`, import Network Flow Monitor Monitor using the monitor ARN. For example: +Using `terraform import`, import Network Flow Monitor Monitor using the monitor name. For example: ```console -% terraform import aws_networkflowmonitor_monitor.example arn:aws:networkflowmonitor:us-west-2:123456789012:monitor/example-monitor +% terraform import aws_networkflowmonitor_monitor.example example-monitor ``` From fa710e7d2d8975076af7dc2ad65101fc83091f7d Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 12 Nov 2025 11:59:21 -0500 Subject: [PATCH 17/21] r/aws_networkflowmonitor_monitor: Correct Update. --- .../service/networkflowmonitor/monitor.go | 187 ++++-------------- .../networkflowmonitor/monitor_test.go | 66 ++++--- internal/service/networkflowmonitor/scope.go | 5 +- 3 files changed, 78 insertions(+), 180 deletions(-) diff --git a/internal/service/networkflowmonitor/monitor.go b/internal/service/networkflowmonitor/monitor.go index 067c2f265f52..d3959ea9393e 100644 --- a/internal/service/networkflowmonitor/monitor.go +++ b/internal/service/networkflowmonitor/monitor.go @@ -6,12 +6,14 @@ package networkflowmonitor import ( "context" "fmt" + "strings" "time" "github.com/YakDriver/regexache" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/networkflowmonitor" awstypes "github.com/aws/aws-sdk-go-v2/service/networkflowmonitor/types" + set "github.com/hashicorp/go-set/v3" uuid "github.com/hashicorp/go-uuid" "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" "github.com/hashicorp/terraform-plugin-framework-validators/setvalidator" @@ -210,9 +212,43 @@ func (r *monitorResource) Update(ctx context.Context, request resource.UpdateReq } if diff.HasChanges() { + var oldLocalResources, newLocalResources []awstypes.MonitorLocalResource + response.Diagnostics.Append(fwflex.Expand(ctx, old.LocalResources, &oldLocalResources)...) + if response.Diagnostics.HasError() { + return + } + response.Diagnostics.Append(fwflex.Expand(ctx, new.LocalResources, &newLocalResources)...) + if response.Diagnostics.HasError() { + return + } + + hashLocalResource := func(v awstypes.MonitorLocalResource) string { + return strings.Join([]string{string(v.Type), aws.ToString(v.Identifier)}, ":") + } + osLocalResource, nsLocalResource := set.HashSetFromFunc(oldLocalResources, hashLocalResource), set.HashSetFromFunc(newLocalResources, hashLocalResource) + + var oldRemoteResources, newRemoteResources []awstypes.MonitorRemoteResource + response.Diagnostics.Append(fwflex.Expand(ctx, old.RemoteResources, &oldRemoteResources)...) + if response.Diagnostics.HasError() { + return + } + response.Diagnostics.Append(fwflex.Expand(ctx, new.RemoteResources, &newRemoteResources)...) + if response.Diagnostics.HasError() { + return + } + + hashRemoteResource := func(v awstypes.MonitorRemoteResource) string { + return strings.Join([]string{string(v.Type), aws.ToString(v.Identifier)}, ":") + } + osRemoteResource, nsRemoteResource := set.HashSetFromFunc(oldRemoteResources, hashRemoteResource), set.HashSetFromFunc(newRemoteResources, hashRemoteResource) + monitorName := fwflex.StringValueFromFramework(ctx, new.MonitorName) input := networkflowmonitor.UpdateMonitorInput{ - MonitorName: aws.String(monitorName), + LocalResourcesToAdd: nsLocalResource.Difference(osLocalResource).Slice(), + LocalResourcesToRemove: osLocalResource.Difference(nsLocalResource).Slice(), + MonitorName: aws.String(monitorName), + RemoteResourcesToAdd: nsRemoteResource.Difference(osRemoteResource).Slice(), + RemoteResourcesToRemove: osRemoteResource.Difference(nsRemoteResource).Slice(), } _, err := conn.UpdateMonitor(ctx, &input) @@ -227,155 +263,6 @@ func (r *monitorResource) Update(ctx context.Context, request resource.UpdateReq } } - // Check if local_resources or remote_resources have changed - // if !new.LocalResources.Equal(old.LocalResources) || !new.RemoteResources.Equal(old.RemoteResources) { - // input := networkflowmonitor.UpdateMonitorInput{ - // MonitorName: new.MonitorName.ValueStringPointer(), - // } - - // // Calculate local resources diff - // oldLocalResources := make(map[string]awstypes.MonitorLocalResource) - // newLocalResources := make(map[string]awstypes.MonitorLocalResource) - - // // Build map of old local resources - // if !old.LocalResources.IsNull() && !old.LocalResources.IsUnknown() { - // oldLocalSlice, diags := old.LocalResources.ToSlice(ctx) - // response.Diagnostics.Append(diags...) - // if response.Diagnostics.HasError() { - // return - // } - // for _, resource := range oldLocalSlice { - // key := resource.Type.ValueString() + "|" + resource.Identifier.ValueString() - // oldLocalResources[key] = awstypes.MonitorLocalResource{ - // Type: awstypes.MonitorLocalResourceType(resource.Type.ValueString()), - // Identifier: resource.Identifier.ValueStringPointer(), - // } - // } - // } - - // // Build map of new local resources - // if !new.LocalResources.IsNull() && !new.LocalResources.IsUnknown() { - // newLocalSlice, diags := new.LocalResources.ToSlice(ctx) - // response.Diagnostics.Append(diags...) - // if response.Diagnostics.HasError() { - // return - // } - // for _, resource := range newLocalSlice { - // key := resource.Type.ValueString() + "|" + resource.Identifier.ValueString() - // newLocalResources[key] = awstypes.MonitorLocalResource{ - // Type: awstypes.MonitorLocalResourceType(resource.Type.ValueString()), - // Identifier: resource.Identifier.ValueStringPointer(), - // } - // } - // } - - // // Find resources to add (in new but not in old) - // var localResourcesToAdd []awstypes.MonitorLocalResource - // for key, resource := range newLocalResources { - // if _, exists := oldLocalResources[key]; !exists { - // localResourcesToAdd = append(localResourcesToAdd, resource) - // } - // } - - // // Find resources to remove (in old but not in new) - // var localResourcesToRemove []awstypes.MonitorLocalResource - // for key, resource := range oldLocalResources { - // if _, exists := newLocalResources[key]; !exists { - // localResourcesToRemove = append(localResourcesToRemove, resource) - // } - // } - - // // Calculate remote resources diff - // oldRemoteResources := make(map[string]awstypes.MonitorRemoteResource) - // newRemoteResources := make(map[string]awstypes.MonitorRemoteResource) - - // // Build map of old remote resources - // if !old.RemoteResources.IsNull() && !old.RemoteResources.IsUnknown() { - // oldRemoteSlice, diags := old.RemoteResources.ToSlice(ctx) - // response.Diagnostics.Append(diags...) - // if response.Diagnostics.HasError() { - // return - // } - // for _, resource := range oldRemoteSlice { - // key := resource.Type.ValueString() + "|" + resource.Identifier.ValueString() - // oldRemoteResources[key] = awstypes.MonitorRemoteResource{ - // Type: awstypes.MonitorRemoteResourceType(resource.Type.ValueString()), - // Identifier: resource.Identifier.ValueStringPointer(), - // } - // } - // } - - // // Build map of new remote resources - // if !new.RemoteResources.IsNull() && !new.RemoteResources.IsUnknown() { - // newRemoteSlice, diags := new.RemoteResources.ToSlice(ctx) - // response.Diagnostics.Append(diags...) - // if response.Diagnostics.HasError() { - // return - // } - // for _, resource := range newRemoteSlice { - // key := resource.Type.ValueString() + "|" + resource.Identifier.ValueString() - // newRemoteResources[key] = awstypes.MonitorRemoteResource{ - // Type: awstypes.MonitorRemoteResourceType(resource.Type.ValueString()), - // Identifier: resource.Identifier.ValueStringPointer(), - // } - // } - // } - - // // Find resources to add (in new but not in old) - // var remoteResourcesToAdd []awstypes.MonitorRemoteResource - // for key, resource := range newRemoteResources { - // if _, exists := oldRemoteResources[key]; !exists { - // remoteResourcesToAdd = append(remoteResourcesToAdd, resource) - // } - // } - - // // Find resources to remove (in old but not in new) - // var remoteResourcesToRemove []awstypes.MonitorRemoteResource - // for key, resource := range oldRemoteResources { - // if _, exists := newRemoteResources[key]; !exists { - // remoteResourcesToRemove = append(remoteResourcesToRemove, resource) - // } - // } - - // // Set the calculated diffs in the input - // if len(localResourcesToAdd) > 0 { - // input.LocalResourcesToAdd = localResourcesToAdd - // } - // if len(localResourcesToRemove) > 0 { - // input.LocalResourcesToRemove = localResourcesToRemove - // } - // if len(remoteResourcesToAdd) > 0 { - // input.RemoteResourcesToAdd = remoteResourcesToAdd - // } - // if len(remoteResourcesToRemove) > 0 { - // input.RemoteResourcesToRemove = remoteResourcesToRemove - // } - - // _, err := conn.UpdateMonitor(ctx, &input) - // if err != nil { - // response.Diagnostics.AddError(fmt.Sprintf("updating Network Flow Monitor Monitor (%s)", new.ID.ValueString()), err.Error()) - // return - // } - - // // Wait for the update to complete - // monitor, err := waitMonitorUpdated(ctx, conn, new.MonitorName.ValueString(), r.UpdateTimeout(ctx, new.Timeouts)) - // if err != nil { - // response.Diagnostics.AddError(fmt.Sprintf("waiting for Network Flow Monitor Monitor (%s) update", new.ID.ValueString()), err.Error()) - // return - // } - - // // Update only the computed attributes, preserve the order of resources from configuration - // new.MonitorStatus = types.StringValue(string(monitor.MonitorStatus)) - - // // Ensure ID and ARN are set properly - // if new.ID.IsNull() || new.ID.IsUnknown() { - // new.ID = types.StringValue(aws.ToString(monitor.MonitorArn)) - // } - // if new.ARN.IsNull() || new.ARN.IsUnknown() { - // new.ARN = types.StringValue(aws.ToString(monitor.MonitorArn)) - // } - // } - response.Diagnostics.Append(response.State.Set(ctx, &new)...) } diff --git a/internal/service/networkflowmonitor/monitor_test.go b/internal/service/networkflowmonitor/monitor_test.go index 58baa5c97a41..cddc4e7454d2 100644 --- a/internal/service/networkflowmonitor/monitor_test.go +++ b/internal/service/networkflowmonitor/monitor_test.go @@ -51,7 +51,7 @@ func testAccMonitor_basic(t *testing.T) { }, }, ConfigStateChecks: []statecheck.StateCheck{ - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("scope_arn"), tfknownvalue.RegionalARNExact("networkflowmonitor", `monitor/`+rName)), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("monitor_arn"), tfknownvalue.RegionalARNExact("networkflowmonitor", `monitor/`+rName)), statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), }, }, @@ -61,6 +61,7 @@ func testAccMonitor_basic(t *testing.T) { ImportStateIdFunc: acctest.AttrImportStateIdFunc(resourceName, "monitor_name"), ImportStateVerify: true, ImportStateVerifyIdentifierAttribute: "monitor_name", + ImportStateVerifyIgnore: []string{"scope_arn"}, }, }, }) @@ -137,6 +138,7 @@ func testAccMonitor_tags(t *testing.T) { ImportStateIdFunc: acctest.AttrImportStateIdFunc(resourceName, "monitor_name"), ImportStateVerify: true, ImportStateVerifyIdentifierAttribute: "monitor_name", + ImportStateVerifyIgnore: []string{"scope_arn"}, }, { Config: testAccMonitorConfig_tags2(rName, acctest.CtKey1, acctest.CtValue1Updated, acctest.CtKey2, acctest.CtValue2), @@ -193,51 +195,61 @@ func testAccMonitor_update(t *testing.T) { Config: testAccMonitorConfig_basic(rName), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckMonitorExists(ctx, resourceName), - resource.TestCheckResourceAttr(resourceName, "monitor_name", rName), - resource.TestCheckResourceAttr(resourceName, "local_resource.0.type", "AWS::EC2::VPC"), ), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate), + }, + }, + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("local_resource"), knownvalue.SetSizeExact(1)), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("remote_resource"), knownvalue.SetSizeExact(0)), + }, }, - //adding one more local resource to monitor { Config: testAccMonitorConfig_updated1(rName), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckMonitorExists(ctx, resourceName), - resource.TestCheckResourceAttr(resourceName, "monitor_name", rName), - resource.TestCheckResourceAttr(resourceName, "local_resource.#", "2"), - resource.TestCheckResourceAttr(resourceName, "remote_resource.#", "1"), ), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + }, + }, + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("local_resource"), knownvalue.SetSizeExact(2)), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("remote_resource"), knownvalue.SetSizeExact(1)), + }, }, - //reverting local resources to single resource. { Config: testAccMonitorConfig_basic(rName), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckMonitorExists(ctx, resourceName), - resource.TestCheckResourceAttr(resourceName, "monitor_name", rName), - resource.TestCheckResourceAttr(resourceName, "local_resource.#", "1"), - resource.TestCheckResourceAttr(resourceName, "remote_resource.#", "1"), - resource.TestCheckResourceAttr(resourceName, "local_resource.0.type", "AWS::EC2::VPC"), ), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + }, + }, + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("local_resource"), knownvalue.SetSizeExact(1)), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("remote_resource"), knownvalue.SetSizeExact(0)), + }, }, - //adding 2 local resources and 2 remote resources { Config: testAccMonitorConfig_updated2(rName), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckMonitorExists(ctx, resourceName), - resource.TestCheckResourceAttr(resourceName, "monitor_name", rName), - resource.TestCheckResourceAttr(resourceName, "local_resource.#", "2"), - resource.TestCheckResourceAttr(resourceName, "remote_resource.#", "2"), - ), - }, - //reverting local resources to single resource. - { - Config: testAccMonitorConfig_basic(rName), - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckMonitorExists(ctx, resourceName), - resource.TestCheckResourceAttr(resourceName, "monitor_name", rName), - resource.TestCheckResourceAttr(resourceName, "local_resource.#", "1"), - resource.TestCheckResourceAttr(resourceName, "remote_resource.#", "1"), - resource.TestCheckResourceAttr(resourceName, "local_resource.0.type", "AWS::EC2::VPC"), ), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate), + }, + }, + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("local_resource"), knownvalue.SetSizeExact(2)), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("remote_resource"), knownvalue.SetSizeExact(2)), + }, }, }, }) diff --git a/internal/service/networkflowmonitor/scope.go b/internal/service/networkflowmonitor/scope.go index 3d6b23af3692..80b8da582260 100644 --- a/internal/service/networkflowmonitor/scope.go +++ b/internal/service/networkflowmonitor/scope.go @@ -234,13 +234,12 @@ func (r *scopeResource) Update(ctx context.Context, request resource.UpdateReque return strings.Join([]string{aws.ToString(v.Region), string(v.TargetIdentifier.TargetType), accountID}, ":") } os, ns := set.HashSetFromFunc(oldTargets, hash), set.HashSetFromFunc(newTargets, hash) - add, del := ns.Difference(os), os.Difference(ns) scopeID := fwflex.StringValueFromFramework(ctx, new.ScopeID) input := networkflowmonitor.UpdateScopeInput{ + ResourcesToAdd: ns.Difference(os).Slice(), + ResourcesToDelete: os.Difference(ns).Slice(), ScopeId: aws.String(scopeID), - ResourcesToAdd: add.Slice(), - ResourcesToDelete: del.Slice(), } _, err := conn.UpdateScope(ctx, &input) From cd25e730617c7d522a89ba6da5c3be5c71609a53 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 12 Nov 2025 14:15:42 -0500 Subject: [PATCH 18/21] Run 'make fix-constants PKG=networkflowmonitor'. --- internal/service/networkflowmonitor/scope.go | 4 ++-- internal/service/networkflowmonitor/scope_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/service/networkflowmonitor/scope.go b/internal/service/networkflowmonitor/scope.go index 80b8da582260..35a98f101187 100644 --- a/internal/service/networkflowmonitor/scope.go +++ b/internal/service/networkflowmonitor/scope.go @@ -62,7 +62,7 @@ func (r *scopeResource) Schema(ctx context.Context, request resource.SchemaReque names.AttrTagsAll: tftags.TagsAttributeComputedOnly(), }, Blocks: map[string]schema.Block{ - "target": schema.SetNestedBlock{ + names.AttrTarget: schema.SetNestedBlock{ CustomType: fwtypes.NewSetNestedObjectTypeOf[targetResourceModel](ctx), Validators: []validator.Set{ setvalidator.SizeAtLeast(1), @@ -102,7 +102,7 @@ func (r *scopeResource) Schema(ctx context.Context, request resource.SchemaReque }, NestedObject: schema.NestedBlockObject{ Attributes: map[string]schema.Attribute{ - "account_id": schema.StringAttribute{ + names.AttrAccountID: schema.StringAttribute{ Required: true, Validators: []validator.String{ fwvalidators.AWSAccountID(), diff --git a/internal/service/networkflowmonitor/scope_test.go b/internal/service/networkflowmonitor/scope_test.go index 2e7fb17883f5..6c8d5f604f03 100644 --- a/internal/service/networkflowmonitor/scope_test.go +++ b/internal/service/networkflowmonitor/scope_test.go @@ -52,7 +52,7 @@ func testAccScope_basic(t *testing.T) { statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("scope_arn"), tfknownvalue.RegionalARNRegexp("networkflowmonitor", regexache.MustCompile(`scope/.+`))), statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("scope_id"), knownvalue.NotNull()), statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTags), knownvalue.Null()), - statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("target"), knownvalue.SetSizeExact(1)), + statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTarget), knownvalue.SetSizeExact(1)), }, }, { From f129d0cf17e86118069a3af0fa69e97ef7093a23 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 12 Nov 2025 14:18:17 -0500 Subject: [PATCH 19/21] Fix semgrep 'ci.semgrep.framework.import-state-passthrough-id'. --- internal/service/networkflowmonitor/monitor.go | 2 +- internal/service/networkflowmonitor/scope.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/service/networkflowmonitor/monitor.go b/internal/service/networkflowmonitor/monitor.go index d3959ea9393e..fe42a79aaea2 100644 --- a/internal/service/networkflowmonitor/monitor.go +++ b/internal/service/networkflowmonitor/monitor.go @@ -297,7 +297,7 @@ func (r *monitorResource) Delete(ctx context.Context, request resource.DeleteReq } func (r *monitorResource) ImportState(ctx context.Context, request resource.ImportStateRequest, response *resource.ImportStateResponse) { - response.Diagnostics.Append(response.State.SetAttribute(ctx, path.Root("monitor_name"), request.ID)...) + resource.ImportStatePassthroughID(ctx, path.Root("monitor_name"), request, response) } func findMonitorByName(ctx context.Context, conn *networkflowmonitor.Client, name string) (*networkflowmonitor.GetMonitorOutput, error) { diff --git a/internal/service/networkflowmonitor/scope.go b/internal/service/networkflowmonitor/scope.go index 35a98f101187..7437b3ec1da6 100644 --- a/internal/service/networkflowmonitor/scope.go +++ b/internal/service/networkflowmonitor/scope.go @@ -288,7 +288,7 @@ func (r *scopeResource) Delete(ctx context.Context, request resource.DeleteReque } func (r *scopeResource) ImportState(ctx context.Context, request resource.ImportStateRequest, response *resource.ImportStateResponse) { - response.Diagnostics.Append(response.State.SetAttribute(ctx, path.Root("scope_id"), request.ID)...) + resource.ImportStatePassthroughID(ctx, path.Root("scope_id"), request, response) } func findScopeByID(ctx context.Context, conn *networkflowmonitor.Client, id string) (*networkflowmonitor.GetScopeOutput, error) { From de4c2168100f180487abec0f28f6c4a1b704935f Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 12 Nov 2025 14:20:17 -0500 Subject: [PATCH 20/21] Fix semgrep 'ci.typed-enum-conversion'. --- internal/service/networkflowmonitor/monitor.go | 5 ++--- internal/service/networkflowmonitor/scope.go | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/internal/service/networkflowmonitor/monitor.go b/internal/service/networkflowmonitor/monitor.go index fe42a79aaea2..2190ea80191f 100644 --- a/internal/service/networkflowmonitor/monitor.go +++ b/internal/service/networkflowmonitor/monitor.go @@ -6,7 +6,6 @@ package networkflowmonitor import ( "context" "fmt" - "strings" "time" "github.com/YakDriver/regexache" @@ -223,7 +222,7 @@ func (r *monitorResource) Update(ctx context.Context, request resource.UpdateReq } hashLocalResource := func(v awstypes.MonitorLocalResource) string { - return strings.Join([]string{string(v.Type), aws.ToString(v.Identifier)}, ":") + return string(v.Type) + ":" + aws.ToString(v.Identifier) } osLocalResource, nsLocalResource := set.HashSetFromFunc(oldLocalResources, hashLocalResource), set.HashSetFromFunc(newLocalResources, hashLocalResource) @@ -238,7 +237,7 @@ func (r *monitorResource) Update(ctx context.Context, request resource.UpdateReq } hashRemoteResource := func(v awstypes.MonitorRemoteResource) string { - return strings.Join([]string{string(v.Type), aws.ToString(v.Identifier)}, ":") + return string(v.Type) + ":" + aws.ToString(v.Identifier) } osRemoteResource, nsRemoteResource := set.HashSetFromFunc(oldRemoteResources, hashRemoteResource), set.HashSetFromFunc(newRemoteResources, hashRemoteResource) diff --git a/internal/service/networkflowmonitor/scope.go b/internal/service/networkflowmonitor/scope.go index 7437b3ec1da6..cf6f05113e4d 100644 --- a/internal/service/networkflowmonitor/scope.go +++ b/internal/service/networkflowmonitor/scope.go @@ -6,7 +6,6 @@ package networkflowmonitor import ( "context" "fmt" - "strings" "time" "github.com/aws/aws-sdk-go-v2/aws" @@ -231,7 +230,7 @@ func (r *scopeResource) Update(ctx context.Context, request resource.UpdateReque hash := func(v awstypes.TargetResource) string { accountID := any(v.TargetIdentifier.TargetId).(*awstypes.TargetIdMemberAccountId).Value - return strings.Join([]string{aws.ToString(v.Region), string(v.TargetIdentifier.TargetType), accountID}, ":") + return aws.ToString(v.Region) + ":" + string(v.TargetIdentifier.TargetType) + ":" + accountID } os, ns := set.HashSetFromFunc(oldTargets, hash), set.HashSetFromFunc(newTargets, hash) From 6573b982097c47eba5c9f08364e9237360610ccb Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 12 Nov 2025 14:21:39 -0500 Subject: [PATCH 21/21] Remove unused files. --- .../testdata/Monitor/tags/main_gen.tf | 52 -------------- .../Monitor/tagsComputed1/main_gen.tf | 56 --------------- .../Monitor/tagsComputed2/main_gen.tf | 67 ----------------- .../Monitor/tags_defaults/main_gen.tf | 63 ---------------- .../testdata/Monitor/tags_ignore/main_gen.tf | 72 ------------------- .../testdata/Scope/tags/main_gen.tf | 30 -------- .../testdata/Scope/tagsComputed1/main_gen.tf | 34 --------- .../testdata/Scope/tagsComputed2/main_gen.tf | 45 ------------ .../testdata/Scope/tags_defaults/main_gen.tf | 41 ----------- .../testdata/Scope/tags_ignore/main_gen.tf | 50 ------------- .../testdata/tmpl/monitor_tags.gtpl | 36 ---------- .../testdata/tmpl/scope_tags.gtpl | 14 ---- 12 files changed, 560 deletions(-) delete mode 100644 internal/service/networkflowmonitor/testdata/Monitor/tags/main_gen.tf delete mode 100644 internal/service/networkflowmonitor/testdata/Monitor/tagsComputed1/main_gen.tf delete mode 100644 internal/service/networkflowmonitor/testdata/Monitor/tagsComputed2/main_gen.tf delete mode 100644 internal/service/networkflowmonitor/testdata/Monitor/tags_defaults/main_gen.tf delete mode 100644 internal/service/networkflowmonitor/testdata/Monitor/tags_ignore/main_gen.tf delete mode 100644 internal/service/networkflowmonitor/testdata/Scope/tags/main_gen.tf delete mode 100644 internal/service/networkflowmonitor/testdata/Scope/tagsComputed1/main_gen.tf delete mode 100644 internal/service/networkflowmonitor/testdata/Scope/tagsComputed2/main_gen.tf delete mode 100644 internal/service/networkflowmonitor/testdata/Scope/tags_defaults/main_gen.tf delete mode 100644 internal/service/networkflowmonitor/testdata/Scope/tags_ignore/main_gen.tf delete mode 100644 internal/service/networkflowmonitor/testdata/tmpl/monitor_tags.gtpl delete mode 100644 internal/service/networkflowmonitor/testdata/tmpl/scope_tags.gtpl diff --git a/internal/service/networkflowmonitor/testdata/Monitor/tags/main_gen.tf b/internal/service/networkflowmonitor/testdata/Monitor/tags/main_gen.tf deleted file mode 100644 index 19d756c0992c..000000000000 --- a/internal/service/networkflowmonitor/testdata/Monitor/tags/main_gen.tf +++ /dev/null @@ -1,52 +0,0 @@ -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - -data "aws_caller_identity" "current" {} -data "aws_region" "current" {} - -resource "aws_vpc" "test" { - cidr_block = "10.0.0.0/16" - - tags = { - Name = var.rName - } -} - -resource "aws_networkflowmonitor_scope" "test" { - targets { - region = data.aws_region.current.name - target_identifier { - target_id = data.aws_caller_identity.current.account_id - target_type = "ACCOUNT" - } - } -} - -resource "aws_networkflowmonitor_monitor" "test" { - monitor_name = var.rName - scope_arn = aws_networkflowmonitor_scope.test.arn - - local_resources { - type = "AWS::EC2::VPC" - identifier = aws_vpc.test.arn - } - - remote_resources { - type = "AWS::EC2::VPC" - identifier = aws_vpc.test.arn - } - - tags = var.resource_tags -} -variable "rName" { - description = "Name for resource" - type = string - nullable = false -} - -variable "resource_tags" { - description = "Tags to set on resource. To specify no tags, set to `null`" - # Not setting a default, so that this must explicitly be set to `null` to specify no tags - type = map(string) - nullable = true -} diff --git a/internal/service/networkflowmonitor/testdata/Monitor/tagsComputed1/main_gen.tf b/internal/service/networkflowmonitor/testdata/Monitor/tagsComputed1/main_gen.tf deleted file mode 100644 index 79c50bcf2090..000000000000 --- a/internal/service/networkflowmonitor/testdata/Monitor/tagsComputed1/main_gen.tf +++ /dev/null @@ -1,56 +0,0 @@ -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - -provider "null" {} - -data "aws_caller_identity" "current" {} -data "aws_region" "current" {} - -resource "aws_vpc" "test" { - cidr_block = "10.0.0.0/16" - - tags = { - Name = var.rName - } -} - -resource "aws_networkflowmonitor_scope" "test" { - targets { - region = data.aws_region.current.name - target_identifier { - target_id = data.aws_caller_identity.current.account_id - target_type = "ACCOUNT" - } - } -} - -resource "aws_networkflowmonitor_monitor" "test" { - monitor_name = var.rName - scope_arn = aws_networkflowmonitor_scope.test.arn - - local_resources { - type = "AWS::EC2::VPC" - identifier = aws_vpc.test.arn - } - - remote_resources { - type = "AWS::EC2::VPC" - identifier = aws_vpc.test.arn - } - - tags = { - (var.unknownTagKey) = null_resource.test.id - } -} -resource "null_resource" "test" {} - -variable "rName" { - description = "Name for resource" - type = string - nullable = false -} - -variable "unknownTagKey" { - type = string - nullable = false -} diff --git a/internal/service/networkflowmonitor/testdata/Monitor/tagsComputed2/main_gen.tf b/internal/service/networkflowmonitor/testdata/Monitor/tagsComputed2/main_gen.tf deleted file mode 100644 index 0a5c21a20fd6..000000000000 --- a/internal/service/networkflowmonitor/testdata/Monitor/tagsComputed2/main_gen.tf +++ /dev/null @@ -1,67 +0,0 @@ -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - -provider "null" {} - -data "aws_caller_identity" "current" {} -data "aws_region" "current" {} - -resource "aws_vpc" "test" { - cidr_block = "10.0.0.0/16" - - tags = { - Name = var.rName - } -} - -resource "aws_networkflowmonitor_scope" "test" { - targets { - region = data.aws_region.current.name - target_identifier { - target_id = data.aws_caller_identity.current.account_id - target_type = "ACCOUNT" - } - } -} - -resource "aws_networkflowmonitor_monitor" "test" { - monitor_name = var.rName - scope_arn = aws_networkflowmonitor_scope.test.arn - - local_resources { - type = "AWS::EC2::VPC" - identifier = aws_vpc.test.arn - } - - remote_resources { - type = "AWS::EC2::VPC" - identifier = aws_vpc.test.arn - } - - tags = { - (var.unknownTagKey) = null_resource.test.id - (var.knownTagKey) = var.knownTagValue - } -} -resource "null_resource" "test" {} - -variable "rName" { - description = "Name for resource" - type = string - nullable = false -} - -variable "unknownTagKey" { - type = string - nullable = false -} - -variable "knownTagKey" { - type = string - nullable = false -} - -variable "knownTagValue" { - type = string - nullable = false -} diff --git a/internal/service/networkflowmonitor/testdata/Monitor/tags_defaults/main_gen.tf b/internal/service/networkflowmonitor/testdata/Monitor/tags_defaults/main_gen.tf deleted file mode 100644 index c9d7a76daac5..000000000000 --- a/internal/service/networkflowmonitor/testdata/Monitor/tags_defaults/main_gen.tf +++ /dev/null @@ -1,63 +0,0 @@ -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - -provider "aws" { - default_tags { - tags = var.provider_tags - } -} - -data "aws_caller_identity" "current" {} -data "aws_region" "current" {} - -resource "aws_vpc" "test" { - cidr_block = "10.0.0.0/16" - - tags = { - Name = var.rName - } -} - -resource "aws_networkflowmonitor_scope" "test" { - targets { - region = data.aws_region.current.name - target_identifier { - target_id = data.aws_caller_identity.current.account_id - target_type = "ACCOUNT" - } - } -} - -resource "aws_networkflowmonitor_monitor" "test" { - monitor_name = var.rName - scope_arn = aws_networkflowmonitor_scope.test.arn - - local_resources { - type = "AWS::EC2::VPC" - identifier = aws_vpc.test.arn - } - - remote_resources { - type = "AWS::EC2::VPC" - identifier = aws_vpc.test.arn - } - - tags = var.resource_tags -} -variable "rName" { - description = "Name for resource" - type = string - nullable = false -} - -variable "resource_tags" { - description = "Tags to set on resource. To specify no tags, set to `null`" - # Not setting a default, so that this must explicitly be set to `null` to specify no tags - type = map(string) - nullable = true -} - -variable "provider_tags" { - type = map(string) - nullable = false -} diff --git a/internal/service/networkflowmonitor/testdata/Monitor/tags_ignore/main_gen.tf b/internal/service/networkflowmonitor/testdata/Monitor/tags_ignore/main_gen.tf deleted file mode 100644 index 12129342a6f6..000000000000 --- a/internal/service/networkflowmonitor/testdata/Monitor/tags_ignore/main_gen.tf +++ /dev/null @@ -1,72 +0,0 @@ -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - -provider "aws" { - default_tags { - tags = var.provider_tags - } - ignore_tags { - keys = var.ignore_tag_keys - } -} - -data "aws_caller_identity" "current" {} -data "aws_region" "current" {} - -resource "aws_vpc" "test" { - cidr_block = "10.0.0.0/16" - - tags = { - Name = var.rName - } -} - -resource "aws_networkflowmonitor_scope" "test" { - targets { - region = data.aws_region.current.name - target_identifier { - target_id = data.aws_caller_identity.current.account_id - target_type = "ACCOUNT" - } - } -} - -resource "aws_networkflowmonitor_monitor" "test" { - monitor_name = var.rName - scope_arn = aws_networkflowmonitor_scope.test.arn - - local_resources { - type = "AWS::EC2::VPC" - identifier = aws_vpc.test.arn - } - - remote_resources { - type = "AWS::EC2::VPC" - identifier = aws_vpc.test.arn - } - - tags = var.resource_tags -} -variable "rName" { - description = "Name for resource" - type = string - nullable = false -} - -variable "resource_tags" { - description = "Tags to set on resource. To specify no tags, set to `null`" - # Not setting a default, so that this must explicitly be set to `null` to specify no tags - type = map(string) - nullable = true -} - -variable "provider_tags" { - type = map(string) - nullable = true - default = null -} - -variable "ignore_tag_keys" { - type = set(string) - nullable = false -} diff --git a/internal/service/networkflowmonitor/testdata/Scope/tags/main_gen.tf b/internal/service/networkflowmonitor/testdata/Scope/tags/main_gen.tf deleted file mode 100644 index 5e82d15050e5..000000000000 --- a/internal/service/networkflowmonitor/testdata/Scope/tags/main_gen.tf +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - -data "aws_caller_identity" "current" {} -data "aws_region" "current" {} - -# Test scope for ${var.rName} -resource "aws_networkflowmonitor_scope" "test" { - targets { - region = data.aws_region.current.name - target_identifier { - target_id = data.aws_caller_identity.current.account_id - target_type = "ACCOUNT" - } - } - - tags = var.resource_tags -} -variable "rName" { - description = "Name for resource" - type = string - nullable = false -} - -variable "resource_tags" { - description = "Tags to set on resource. To specify no tags, set to `null`" - # Not setting a default, so that this must explicitly be set to `null` to specify no tags - type = map(string) - nullable = true -} diff --git a/internal/service/networkflowmonitor/testdata/Scope/tagsComputed1/main_gen.tf b/internal/service/networkflowmonitor/testdata/Scope/tagsComputed1/main_gen.tf deleted file mode 100644 index 4ccd4147a360..000000000000 --- a/internal/service/networkflowmonitor/testdata/Scope/tagsComputed1/main_gen.tf +++ /dev/null @@ -1,34 +0,0 @@ -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - -provider "null" {} - -data "aws_caller_identity" "current" {} -data "aws_region" "current" {} - -# Test scope for ${var.rName} -resource "aws_networkflowmonitor_scope" "test" { - targets { - region = data.aws_region.current.name - target_identifier { - target_id = data.aws_caller_identity.current.account_id - target_type = "ACCOUNT" - } - } - - tags = { - (var.unknownTagKey) = null_resource.test.id - } -} -resource "null_resource" "test" {} - -variable "rName" { - description = "Name for resource" - type = string - nullable = false -} - -variable "unknownTagKey" { - type = string - nullable = false -} diff --git a/internal/service/networkflowmonitor/testdata/Scope/tagsComputed2/main_gen.tf b/internal/service/networkflowmonitor/testdata/Scope/tagsComputed2/main_gen.tf deleted file mode 100644 index 9d91d8b50898..000000000000 --- a/internal/service/networkflowmonitor/testdata/Scope/tagsComputed2/main_gen.tf +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - -provider "null" {} - -data "aws_caller_identity" "current" {} -data "aws_region" "current" {} - -# Test scope for ${var.rName} -resource "aws_networkflowmonitor_scope" "test" { - targets { - region = data.aws_region.current.name - target_identifier { - target_id = data.aws_caller_identity.current.account_id - target_type = "ACCOUNT" - } - } - - tags = { - (var.unknownTagKey) = null_resource.test.id - (var.knownTagKey) = var.knownTagValue - } -} -resource "null_resource" "test" {} - -variable "rName" { - description = "Name for resource" - type = string - nullable = false -} - -variable "unknownTagKey" { - type = string - nullable = false -} - -variable "knownTagKey" { - type = string - nullable = false -} - -variable "knownTagValue" { - type = string - nullable = false -} diff --git a/internal/service/networkflowmonitor/testdata/Scope/tags_defaults/main_gen.tf b/internal/service/networkflowmonitor/testdata/Scope/tags_defaults/main_gen.tf deleted file mode 100644 index fedbe5a7305a..000000000000 --- a/internal/service/networkflowmonitor/testdata/Scope/tags_defaults/main_gen.tf +++ /dev/null @@ -1,41 +0,0 @@ -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - -provider "aws" { - default_tags { - tags = var.provider_tags - } -} - -data "aws_caller_identity" "current" {} -data "aws_region" "current" {} - -# Test scope for ${var.rName} -resource "aws_networkflowmonitor_scope" "test" { - targets { - region = data.aws_region.current.name - target_identifier { - target_id = data.aws_caller_identity.current.account_id - target_type = "ACCOUNT" - } - } - - tags = var.resource_tags -} -variable "rName" { - description = "Name for resource" - type = string - nullable = false -} - -variable "resource_tags" { - description = "Tags to set on resource. To specify no tags, set to `null`" - # Not setting a default, so that this must explicitly be set to `null` to specify no tags - type = map(string) - nullable = true -} - -variable "provider_tags" { - type = map(string) - nullable = false -} diff --git a/internal/service/networkflowmonitor/testdata/Scope/tags_ignore/main_gen.tf b/internal/service/networkflowmonitor/testdata/Scope/tags_ignore/main_gen.tf deleted file mode 100644 index 810efd5f5cfe..000000000000 --- a/internal/service/networkflowmonitor/testdata/Scope/tags_ignore/main_gen.tf +++ /dev/null @@ -1,50 +0,0 @@ -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - -provider "aws" { - default_tags { - tags = var.provider_tags - } - ignore_tags { - keys = var.ignore_tag_keys - } -} - -data "aws_caller_identity" "current" {} -data "aws_region" "current" {} - -# Test scope for ${var.rName} -resource "aws_networkflowmonitor_scope" "test" { - targets { - region = data.aws_region.current.name - target_identifier { - target_id = data.aws_caller_identity.current.account_id - target_type = "ACCOUNT" - } - } - - tags = var.resource_tags -} -variable "rName" { - description = "Name for resource" - type = string - nullable = false -} - -variable "resource_tags" { - description = "Tags to set on resource. To specify no tags, set to `null`" - # Not setting a default, so that this must explicitly be set to `null` to specify no tags - type = map(string) - nullable = true -} - -variable "provider_tags" { - type = map(string) - nullable = true - default = null -} - -variable "ignore_tag_keys" { - type = set(string) - nullable = false -} diff --git a/internal/service/networkflowmonitor/testdata/tmpl/monitor_tags.gtpl b/internal/service/networkflowmonitor/testdata/tmpl/monitor_tags.gtpl deleted file mode 100644 index 2826c1295e42..000000000000 --- a/internal/service/networkflowmonitor/testdata/tmpl/monitor_tags.gtpl +++ /dev/null @@ -1,36 +0,0 @@ -data "aws_caller_identity" "current" {} -data "aws_region" "current" {} - -resource "aws_vpc" "test" { - cidr_block = "10.0.0.0/16" - - tags = { - Name = var.rName - } -} - -resource "aws_networkflowmonitor_scope" "test" { - targets { - region = data.aws_region.current.name - target_identifier { - target_id = data.aws_caller_identity.current.account_id - target_type = "ACCOUNT" - } - } -} - -resource "aws_networkflowmonitor_monitor" "test" { - monitor_name = var.rName - scope_arn = aws_networkflowmonitor_scope.test.arn - - local_resources { - type = "AWS::EC2::VPC" - identifier = aws_vpc.test.arn - } - - remote_resources { - type = "AWS::EC2::VPC" - identifier = aws_vpc.test.arn - } -{{- template "tags" . }} -} \ No newline at end of file diff --git a/internal/service/networkflowmonitor/testdata/tmpl/scope_tags.gtpl b/internal/service/networkflowmonitor/testdata/tmpl/scope_tags.gtpl deleted file mode 100644 index 028909ea5ddf..000000000000 --- a/internal/service/networkflowmonitor/testdata/tmpl/scope_tags.gtpl +++ /dev/null @@ -1,14 +0,0 @@ -data "aws_caller_identity" "current" {} -data "aws_region" "current" {} - -# Test scope for ${var.rName} -resource "aws_networkflowmonitor_scope" "test" { - targets { - region = data.aws_region.current.name - target_identifier { - target_id = data.aws_caller_identity.current.account_id - target_type = "ACCOUNT" - } - } -{{- template "tags" . }} -} \ No newline at end of file