diff --git a/.changelog/44754.txt b/.changelog/44754.txt new file mode 100644 index 000000000000..b2a3c3e3a770 --- /dev/null +++ b/.changelog/44754.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_odb_network: Add `delete_associated_resources` attribute to enable practitioner to delete associated oci resource. +``` \ No newline at end of file diff --git a/internal/service/odb/network.go b/internal/service/odb/network.go index 4fdda38c7dd7..15777cfd0d8a 100644 --- a/internal/service/odb/network.go +++ b/internal/service/odb/network.go @@ -17,6 +17,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier" "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" @@ -188,6 +190,15 @@ func (r *resourceNetwork) Schema(ctx context.Context, req resource.SchemaRequest Computed: true, Description: "The URL of the OCI VCN for the ODB network.", }, + "delete_associated_resources": schema.BoolAttribute{ + Optional: true, + Computed: true, + Default: booldefault.StaticBool(false), + PlanModifiers: []planmodifier.Bool{ + boolplanmodifier.UseStateForUnknown(), + }, + Description: "If set to true deletes associated OCI resources. Default false.", + }, "percent_progress": schema.Float32Attribute{ Computed: true, Description: "The amount of progress made on the current operation on the ODB network, expressed as a percentage.", @@ -474,12 +485,14 @@ func (r *resourceNetwork) Delete(ctx context.Context, req resource.DeleteRequest return } - deleteAssociatedResources := false input := odb.DeleteOdbNetworkInput{ - OdbNetworkId: state.OdbNetworkId.ValueStringPointer(), - DeleteAssociatedResources: &deleteAssociatedResources, + OdbNetworkId: state.OdbNetworkId.ValueStringPointer(), } + input.DeleteAssociatedResources = aws.Bool(false) + if !state.DeleteAssociatedResources.IsNull() || !state.DeleteAssociatedResources.IsUnknown() { + input.DeleteAssociatedResources = state.DeleteAssociatedResources.ValueBoolPointer() + } _, err := conn.DeleteOdbNetwork(ctx, &input) if err != nil { @@ -651,33 +664,34 @@ func FindOracleDBNetworkResourceByID(ctx context.Context, conn *odb.Client, id s type odbNetworkResourceModel struct { framework.WithRegionModel - DisplayName types.String `tfsdk:"display_name"` - AvailabilityZone types.String `tfsdk:"availability_zone"` - AvailabilityZoneId types.String `tfsdk:"availability_zone_id"` - ClientSubnetCidr types.String `tfsdk:"client_subnet_cidr"` - BackupSubnetCidr types.String `tfsdk:"backup_subnet_cidr"` - CustomDomainName types.String `tfsdk:"custom_domain_name"` - DefaultDnsPrefix types.String `tfsdk:"default_dns_prefix"` - S3Access fwtypes.StringEnum[odbtypes.Access] `tfsdk:"s3_access" autoflex:",noflatten"` - ZeroEtlAccess fwtypes.StringEnum[odbtypes.Access] `tfsdk:"zero_etl_access" autoflex:",noflatten"` - S3PolicyDocument types.String `tfsdk:"s3_policy_document" autoflex:",noflatten"` - OdbNetworkId types.String `tfsdk:"id"` - PeeredCidrs fwtypes.SetValueOf[types.String] `tfsdk:"peered_cidrs"` - OciDnsForwardingConfigs fwtypes.ListNestedObjectValueOf[odbNwkOciDnsForwardingConfigResourceModel] `tfsdk:"oci_dns_forwarding_configs"` - OciNetworkAnchorId types.String `tfsdk:"oci_network_anchor_id"` - OciNetworkAnchorUrl types.String `tfsdk:"oci_network_anchor_url"` - OciResourceAnchorName types.String `tfsdk:"oci_resource_anchor_name"` - OciVcnId types.String `tfsdk:"oci_vcn_id"` - OciVcnUrl types.String `tfsdk:"oci_vcn_url"` - OdbNetworkArn types.String `tfsdk:"arn"` - PercentProgress types.Float32 `tfsdk:"percent_progress"` - Status fwtypes.StringEnum[odbtypes.ResourceStatus] `tfsdk:"status"` - StatusReason types.String `tfsdk:"status_reason"` - Timeouts timeouts.Value `tfsdk:"timeouts"` - ManagedServices fwtypes.ListNestedObjectValueOf[odbNetworkManagedServicesResourceModel] `tfsdk:"managed_services"` - CreatedAt timetypes.RFC3339 `tfsdk:"created_at"` - Tags tftags.Map `tfsdk:"tags"` - TagsAll tftags.Map `tfsdk:"tags_all"` + DisplayName types.String `tfsdk:"display_name"` + AvailabilityZone types.String `tfsdk:"availability_zone"` + AvailabilityZoneId types.String `tfsdk:"availability_zone_id"` + ClientSubnetCidr types.String `tfsdk:"client_subnet_cidr"` + BackupSubnetCidr types.String `tfsdk:"backup_subnet_cidr"` + CustomDomainName types.String `tfsdk:"custom_domain_name"` + DefaultDnsPrefix types.String `tfsdk:"default_dns_prefix"` + S3Access fwtypes.StringEnum[odbtypes.Access] `tfsdk:"s3_access" autoflex:",noflatten"` + ZeroEtlAccess fwtypes.StringEnum[odbtypes.Access] `tfsdk:"zero_etl_access" autoflex:",noflatten"` + S3PolicyDocument types.String `tfsdk:"s3_policy_document" autoflex:",noflatten"` + OdbNetworkId types.String `tfsdk:"id"` + PeeredCidrs fwtypes.SetValueOf[types.String] `tfsdk:"peered_cidrs"` + OciDnsForwardingConfigs fwtypes.ListNestedObjectValueOf[odbNwkOciDnsForwardingConfigResourceModel] `tfsdk:"oci_dns_forwarding_configs"` + OciNetworkAnchorId types.String `tfsdk:"oci_network_anchor_id"` + OciNetworkAnchorUrl types.String `tfsdk:"oci_network_anchor_url"` + OciResourceAnchorName types.String `tfsdk:"oci_resource_anchor_name"` + OciVcnId types.String `tfsdk:"oci_vcn_id"` + OciVcnUrl types.String `tfsdk:"oci_vcn_url"` + OdbNetworkArn types.String `tfsdk:"arn"` + PercentProgress types.Float32 `tfsdk:"percent_progress"` + Status fwtypes.StringEnum[odbtypes.ResourceStatus] `tfsdk:"status"` + StatusReason types.String `tfsdk:"status_reason"` + Timeouts timeouts.Value `tfsdk:"timeouts"` + ManagedServices fwtypes.ListNestedObjectValueOf[odbNetworkManagedServicesResourceModel] `tfsdk:"managed_services"` + CreatedAt timetypes.RFC3339 `tfsdk:"created_at"` + DeleteAssociatedResources types.Bool `tfsdk:"delete_associated_resources"` + Tags tftags.Map `tfsdk:"tags"` + TagsAll tftags.Map `tfsdk:"tags_all"` } type odbNwkOciDnsForwardingConfigResourceModel struct { diff --git a/internal/service/odb/network_test.go b/internal/service/odb/network_test.go index 3b3bad8dda7b..4a3007a7cfdc 100644 --- a/internal/service/odb/network_test.go +++ b/internal/service/odb/network_test.go @@ -37,7 +37,9 @@ func TestAccODBNetworkResource_basic(t *testing.T) { if testing.Short() { t.Skip("skipping long-running test in short mode") } - + importStateVerifyIgnore := []string{ + "delete_associated_resources", + } var network odbtypes.OdbNetwork rName := sdkacctest.RandomWithPrefix(oracleDBNetworkResourceTestEntity.displayNamePrefix) resourceName := "aws_odb_network.test" @@ -57,9 +59,10 @@ func TestAccODBNetworkResource_basic(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: importStateVerifyIgnore, }, }, }) @@ -70,7 +73,9 @@ func TestAccODBNetworkResource_withAllParams(t *testing.T) { if testing.Short() { t.Skip("skipping long-running test in short mode") } - + importStateVerifyIgnore := []string{ + "delete_associated_resources", + } var network1 odbtypes.OdbNetwork rName := sdkacctest.RandomWithPrefix(oracleDBNetworkResourceTestEntity.displayNamePrefix) resourceName := "aws_odb_network.test" @@ -91,9 +96,10 @@ func TestAccODBNetworkResource_withAllParams(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: importStateVerifyIgnore, }, }, }) @@ -104,7 +110,9 @@ func TestAccODBNetworkResource_updateManagedService(t *testing.T) { if testing.Short() { t.Skip("skipping long-running test in short mode") } - + importStateVerifyIgnore := []string{ + "delete_associated_resources", + } var network1, network2 odbtypes.OdbNetwork rName := sdkacctest.RandomWithPrefix(oracleDBNetworkResourceTestEntity.displayNamePrefix) resourceName := "aws_odb_network.test" @@ -125,9 +133,10 @@ func TestAccODBNetworkResource_updateManagedService(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: importStateVerifyIgnore, }, { Config: oracleDBNetworkResourceTestEntity.basicNetworkWithActiveManagedService(rName), @@ -142,9 +151,10 @@ func TestAccODBNetworkResource_updateManagedService(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: importStateVerifyIgnore, }, }, }) @@ -155,7 +165,9 @@ func TestAccODBNetworkResource_disableManagedService(t *testing.T) { if testing.Short() { t.Skip("skipping long-running test in short mode") } - + importStateVerifyIgnore := []string{ + "delete_associated_resources", + } var network1, network2 odbtypes.OdbNetwork rName := sdkacctest.RandomWithPrefix(oracleDBNetworkResourceTestEntity.displayNamePrefix) resourceName := "aws_odb_network.test" @@ -176,9 +188,10 @@ func TestAccODBNetworkResource_disableManagedService(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: importStateVerifyIgnore, }, { Config: oracleDBNetworkResourceTestEntity.basicNetwork(rName), @@ -193,9 +206,10 @@ func TestAccODBNetworkResource_disableManagedService(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: importStateVerifyIgnore, }, }, }) @@ -206,7 +220,9 @@ func TestAccODBNetworkResource_updateTags(t *testing.T) { if testing.Short() { t.Skip("skipping long-running test in short mode") } - + importStateVerifyIgnore := []string{ + "delete_associated_resources", + } var network1, network2 odbtypes.OdbNetwork rName := sdkacctest.RandomWithPrefix(oracleDBNetworkResourceTestEntity.displayNamePrefix) resourceName := "aws_odb_network.test" @@ -242,9 +258,10 @@ func TestAccODBNetworkResource_updateTags(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: importStateVerifyIgnore, }, }, }) @@ -281,6 +298,61 @@ func TestAccODBNetworkResource_disappears(t *testing.T) { }) } +func TestAccODBNetworkResource_updateDeleteAssociatedResource(t *testing.T) { + ctx := acctest.Context(t) + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + importStateVerifyIgnore := []string{ + "delete_associated_resources", + } + var network1, network2 odbtypes.OdbNetwork + rName := sdkacctest.RandomWithPrefix(oracleDBNetworkResourceTestEntity.displayNamePrefix) + resourceName := "aws_odb_network.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + oracleDBNetworkResourceTestEntity.testAccPreCheck(ctx, t) + }, + ErrorCheck: acctest.ErrorCheck(t, names.ODBServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: oracleDBNetworkResourceTestEntity.testAccCheckNetworkDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: oracleDBNetworkResourceTestEntity.basicNetworkWithWithDeleteAssociatedResourceFalse(rName), + Check: resource.ComposeAggregateTestCheckFunc( + oracleDBNetworkResourceTestEntity.testAccCheckNetworkExists(ctx, resourceName, &network1), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: importStateVerifyIgnore, + }, + { + Config: oracleDBNetworkResourceTestEntity.basicNetwork(rName), + Check: resource.ComposeAggregateTestCheckFunc( + oracleDBNetworkResourceTestEntity.testAccCheckNetworkExists(ctx, resourceName, &network2), + resource.ComposeTestCheckFunc(func(state *terraform.State) error { + if strings.Compare(*(network1.OdbNetworkId), *(network2.OdbNetworkId)) != 0 { + return errors.New("should not create a new cloud odb network") + } + return nil + }), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: importStateVerifyIgnore, + }, + }, + }) +} + func (oracleDBNetworkResourceTest) testAccCheckNetworkDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { conn := acctest.Provider.Meta().(*conns.AWSClient).ODBClient(ctx) @@ -346,6 +418,45 @@ func (oracleDBNetworkResourceTest) basicNetwork(rName string) string { + + + + +resource "aws_odb_network" "test" { + display_name = %[1]q + availability_zone_id = "use1-az6" + client_subnet_cidr = "10.2.0.0/24" + backup_subnet_cidr = "10.2.1.0/24" + s3_access = "DISABLED" + zero_etl_access = "DISABLED" + delete_associated_resources = true +} + + + + +`, rName) + return networkRes +} + +func (oracleDBNetworkResourceTest) basicNetworkWithWithDeleteAssociatedResourceFalse(rName string) string { + networkRes := fmt.Sprintf(` + + + + + + + + + + + + + + + + resource "aws_odb_network" "test" { display_name = %[1]q availability_zone_id = "use1-az6" @@ -356,6 +467,12 @@ resource "aws_odb_network" "test" { } + + + + + + `, rName) return networkRes } @@ -366,16 +483,23 @@ func (oracleDBNetworkResourceTest) basicNetworkWithActiveManagedService(rName st + + + + resource "aws_odb_network" "test" { - display_name = %[1]q - availability_zone_id = "use1-az6" - client_subnet_cidr = "10.2.0.0/24" - backup_subnet_cidr = "10.2.1.0/24" - s3_access = "ENABLED" - zero_etl_access = "ENABLED" + display_name = %[1]q + availability_zone_id = "use1-az6" + client_subnet_cidr = "10.2.0.0/24" + backup_subnet_cidr = "10.2.1.0/24" + s3_access = "ENABLED" + zero_etl_access = "ENABLED" + delete_associated_resources = true } + + `, rName) return networkRes } @@ -386,17 +510,24 @@ func (oracleDBNetworkResourceTest) networkWithAllParams(rName, customDomainName + + + + resource "aws_odb_network" "test" { - display_name = %[1]q - availability_zone_id = "use1-az6" - client_subnet_cidr = "10.2.0.0/24" - backup_subnet_cidr = "10.2.1.0/24" - s3_access = "DISABLED" - zero_etl_access = "DISABLED" - custom_domain_name = %[2]q + display_name = %[1]q + availability_zone_id = "use1-az6" + client_subnet_cidr = "10.2.0.0/24" + backup_subnet_cidr = "10.2.1.0/24" + s3_access = "DISABLED" + zero_etl_access = "DISABLED" + custom_domain_name = %[2]q + delete_associated_resources = true } + + `, rName, customDomainName) return networkRes } @@ -407,13 +538,18 @@ func (oracleDBNetworkResourceTest) updateNetworkTags(rName string) string { + + + + resource "aws_odb_network" "test" { - display_name = %[1]q - availability_zone_id = "use1-az6" - client_subnet_cidr = "10.2.0.0/24" - backup_subnet_cidr = "10.2.1.0/24" - s3_access = "DISABLED" - zero_etl_access = "DISABLED" + display_name = %[1]q + availability_zone_id = "use1-az6" + client_subnet_cidr = "10.2.0.0/24" + backup_subnet_cidr = "10.2.1.0/24" + s3_access = "DISABLED" + zero_etl_access = "DISABLED" + delete_associated_resources = true tags = { "env" = "dev" } diff --git a/website/docs/r/odb_network.html.markdown b/website/docs/r/odb_network.html.markdown index a6d73abcd750..efa7eb21fba1 100644 --- a/website/docs/r/odb_network.html.markdown +++ b/website/docs/r/odb_network.html.markdown @@ -60,6 +60,7 @@ The following arguments are optional: * `default_dns_prefix` - (Optional) The default DNS prefix for the network resource. Changing this will force terraform to create new resource. Changing this will force terraform to create new resource. * `tags` - (Optional) A map of tags to assign to the exadata infrastructure. 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. * `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). +* `delete_associated_resources` - (Optional) If set to true deletes associated OCI resources. Default false. ## Attribute Reference