Skip to content

Commit a3b3f5f

Browse files
shrsrlhercot
authored andcommitted
[ignore] Addition of child data source model to data_source_aci_rest_managed without content_on_destroy
1 parent fe05171 commit a3b3f5f

File tree

3 files changed

+32
-63
lines changed

3 files changed

+32
-63
lines changed

internal/provider/data_source_aci_rest_managed.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ type AciRestManagedDataSourceModel struct {
3737
Annotation types.String `tfsdk:"annotation"`
3838
}
3939

40+
type ChildAciRestManagedDataSourceModel struct {
41+
Rn types.String `tfsdk:"rn"`
42+
ClassName types.String `tfsdk:"class_name"`
43+
Content types.Map `tfsdk:"content"`
44+
}
45+
4046
func (d *AciRestManagedDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
4147
tflog.Debug(ctx, "Start schema of datasource: aci_rest_managed")
4248
resp.TypeName = req.ProviderTypeName + "_rest_managed"
@@ -164,13 +170,13 @@ func (d *AciRestManagedDataSource) Read(ctx context.Context, req datasource.Read
164170
}
165171
data.Content, _ = types.MapValue(types.StringType, content)
166172

167-
childList := make([]ChildAciRestManagedResourceModel, 0)
173+
childList := make([]ChildAciRestManagedDataSourceModel, 0)
168174
if _, ok := classReadInfo[0].(map[string]interface{})["children"]; ok {
169175
for _, child := range classReadInfo[0].(map[string]interface{})["children"].([]interface{}) {
170176
for childClassName, childClassDetails := range child.(map[string]interface{}) {
171177
childAttributes := childClassDetails.(map[string]interface{})["attributes"].(map[string]interface{})
172178
childContents := map[string]attr.Value{}
173-
ChildAciRestManaged := ChildAciRestManagedResourceModel{}
179+
ChildAciRestManaged := ChildAciRestManagedDataSourceModel{}
174180
ChildAciRestManaged.ClassName = basetypes.NewStringValue(childClassName)
175181

176182
if val, ok := childAttributes["rn"]; ok {

internal/provider/resource_aci_rest_managed.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -400,10 +400,6 @@ func (r *AciRestManagedResource) Delete(ctx context.Context, req resource.Delete
400400
if hasContentOnDestroy {
401401
tflog.Debug(ctx, "content_on_destroy is specified, applying destroy configuration")
402402

403-
// Store original values
404-
originalContent := data.Content
405-
originalChild := data.Child
406-
407403
// Apply content_on_destroy to parent
408404
data.Content = data.ContentOnDestroy
409405

@@ -442,19 +438,12 @@ func (r *AciRestManagedResource) Delete(ctx context.Context, req resource.Delete
442438
// getAciRestManagedChildPayloads will compare and mark children not in childrenWithDestroyConfig for deletion
443439
jsonPayload = getAciRestManagedCreateJsonPayload(ctx, &resp.Diagnostics, false, data, childrenWithDestroyConfig, currentChildren)
444440

445-
// Restore original values
446-
data.Content = originalContent
447-
data.Child = originalChild
448-
449441
if resp.Diagnostics.HasError() {
450442
return
451443
}
452444

453-
tflog.Debug(ctx, "Successfully built destroy configuration payload")
454445
} else {
455446
// No content_on_destroy - perform regular delete
456-
tflog.Debug(ctx, "No content_on_destroy specified, performing regular delete")
457-
458447
jsonPayload = GetDeleteJsonPayload(ctx, &resp.Diagnostics, data.ClassName.ValueString(), data.Id.ValueString())
459448
if resp.Diagnostics.HasError() {
460449
return

internal/provider/resource_aci_rest_managed_test.go

Lines changed: 24 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77

88
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
99
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
10-
"github.com/hashicorp/terraform-plugin-testing/terraform"
1110
)
1211

1312
func TestAccAciRestManaged_tenant(t *testing.T) {
@@ -981,67 +980,34 @@ func TestAccAciRestManaged_onDestroyCreate(t *testing.T) {
981980
}
982981

983982
func TestAccAciRestManaged_onDestroyImport(t *testing.T) {
984-
985983
resource.Test(t, resource.TestCase{
986984
PreCheck: func() { testAccPreCheck(t, "both", "5.2(1g)-") },
987985
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
988986
Steps: []resource.TestStep{
989987
{
990-
Config: testAccAciRestManagedConfig_onDestroyMinimal(),
991-
ImportState: true,
992-
ImportStateId: fmt.Sprintf("uni/tn-%s:ap-web,ctx-vrf1", onDestroyTestName),
993-
ResourceName: "aci_rest_managed.tenant_with_destroy",
994-
ImportStateCheck: func(states []*terraform.InstanceState) error {
995-
if len(states) != 1 {
996-
return fmt.Errorf("expected 1 resource state, got %d", len(states))
997-
}
998-
999-
state := states[0]
1000-
1001-
// Validate parent
1002-
if state.Attributes["dn"] != "uni/tn-"+onDestroyTestName {
1003-
return fmt.Errorf("dn mismatch")
1004-
}
1005-
1006-
if state.Attributes["class_name"] != "fvTenant" {
1007-
return fmt.Errorf("class_name mismatch")
1008-
}
1009-
1010-
if state.Attributes["content.descr"] != "Decommissioned Tenant" {
1011-
return fmt.Errorf("content.descr mismatch: expected 'Decommissioned Tenant', got '%s'", state.Attributes["content.descr"])
1012-
}
1013-
1014-
// Check children count
1015-
childCount := 2
1016-
if state.Attributes["child.#"] != "2" {
1017-
return fmt.Errorf("expected 2 children, got %s", state.Attributes["child.#"])
1018-
}
1019-
1020-
// Validate each child using helper
1021-
if err := findAndValidateChildForRestManaged(state, childCount, "ap-web", "fvAp", map[string]string{
1022-
"name": "web",
1023-
"descr": "Archived Web App",
1024-
}); err != nil {
1025-
return err
1026-
}
1027-
1028-
if err := findAndValidateChildForRestManaged(state, childCount, "ctx-vrf1", "fvCtx", map[string]string{
1029-
"name": "vrf1",
1030-
"descr": "Archived VRF",
1031-
}); err != nil {
1032-
return err
1033-
}
1034-
1035-
return nil
1036-
},
988+
Config: testAccDataSourceAciRestManagedConfig_onDestroy(),
989+
Check: resource.ComposeTestCheckFunc(
990+
resource.TestCheckResourceAttr("data.aci_rest_managed.tenant_with_destroy", "class_name", "fvTenant"),
991+
resource.TestCheckResourceAttr("data.aci_rest_managed.tenant_with_destroy", "id", "uni/tn-"+onDestroyTestName),
992+
resource.TestCheckResourceAttr("data.aci_rest_managed.tenant_with_destroy", "dn", "uni/tn-"+onDestroyTestName),
993+
resource.TestCheckResourceAttr("data.aci_rest_managed.tenant_with_destroy", "content.name", onDestroyTestName),
994+
resource.TestCheckResourceAttr("data.aci_rest_managed.tenant_with_destroy", "content.descr", "Decommissioned Tenant"),
995+
resource.TestCheckResourceAttr("data.aci_rest_managed.tenant_with_destroy", "child.0.class_name", "fvAp"),
996+
resource.TestCheckResourceAttr("data.aci_rest_managed.tenant_with_destroy", "child.0.rn", "ap-web"),
997+
resource.TestCheckResourceAttr("data.aci_rest_managed.tenant_with_destroy", "child.0.content.name", "web"),
998+
resource.TestCheckResourceAttr("data.aci_rest_managed.tenant_with_destroy", "child.0.content.descr", "Archived Web App"),
999+
resource.TestCheckResourceAttr("data.aci_rest_managed.tenant_with_destroy", "child.1.class_name", "fvCtx"),
1000+
resource.TestCheckResourceAttr("data.aci_rest_managed.tenant_with_destroy", "child.1.rn", "ctx-vrf1"),
1001+
resource.TestCheckResourceAttr("data.aci_rest_managed.tenant_with_destroy", "child.1.content.name", "vrf1"),
1002+
resource.TestCheckResourceAttr("data.aci_rest_managed.tenant_with_destroy", "child.1.content.descr", "Archived VRF"),
1003+
),
10371004
},
10381005
{
10391006
Config: testAccAciRestManagedConfig_onDestroyMinimal(),
10401007
ImportState: true,
10411008
ImportStateId: fmt.Sprintf("uni/tn-%s:ap-database", onDestroyTestName),
10421009
ResourceName: "aci_rest_managed.tenant_with_destroy",
10431010
ExpectError: regexp.MustCompile("Unable to find specified child 'ap-database'"),
1044-
Destroy: true,
10451011
},
10461012
},
10471013
})
@@ -1670,6 +1636,14 @@ func testAccAciRestManagedConfig_onDestroy() string {
16701636
`, onDestroyTestName)
16711637
}
16721638

1639+
func testAccDataSourceAciRestManagedConfig_onDestroy() string {
1640+
return fmt.Sprintf(`
1641+
data "aci_rest_managed" "tenant_with_destroy" {
1642+
dn = "uni/tn-%[1]s"
1643+
}
1644+
`, onDestroyTestName)
1645+
}
1646+
16731647
func testAccAciRestManagedConfig_onDestroyMinimal() string {
16741648
return fmt.Sprintf(`
16751649
resource "aci_rest_managed" "tenant_with_destroy" {

0 commit comments

Comments
 (0)