diff --git a/gen/templates/provider.go.tmpl b/gen/templates/provider.go.tmpl index b612c0371..ce90219a5 100644 --- a/gen/templates/provider.go.tmpl +++ b/gen/templates/provider.go.tmpl @@ -34,6 +34,22 @@ var globalAllowExistingOnCreate bool var _ provider.Provider = &AciProvider{} var _ provider.ProviderWithFunctions = &AciProvider{} +// Struct model for identity data handling +type IdentityModel struct { + Id types.String `tfsdk:"id"` +} + +// Generic identity schema for each resource +func getIdentitySchema() identityschema.Schema { + return identityschema.Schema{ + Attributes: map[string]identityschema.Attribute{ + "id": identityschema.StringAttribute{ + RequiredForImport: true, + }, + }, + } +} + // AciProvider defines the provider implementation. type AciProvider struct { version string diff --git a/gen/templates/resource.go.tmpl b/gen/templates/resource.go.tmpl index 211668f19..c368c6bb8 100644 --- a/gen/templates/resource.go.tmpl +++ b/gen/templates/resource.go.tmpl @@ -34,12 +34,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &{{.ResourceClassName}}Resource{} +var _ resource.ResourceWithIdentity = &{{.ResourceClassName}}Resource{} var _ resource.ResourceWithImportState = &{{.ResourceClassName}}Resource{} func New{{.ResourceClassName}}Resource() resource.Resource { return &{{.ResourceClassName}}Resource{} } +func (r {{.ResourceClassName}}Resource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // {{.ResourceClassName}}Resource defines the resource implementation. type {{.ResourceClassName}}Resource struct { client *client.Client @@ -1846,6 +1851,7 @@ func (r *{{.ResourceClassName}}Resource) Create(ctx context.Context, req resourc // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_{{.ResourceName}} with id '%s'", data.Id.ValueString())) } @@ -1870,6 +1876,7 @@ func (r *{{.ResourceClassName}}Resource) Read(ctx context.Context, req resource. resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_{{.ResourceName}} with id '%s'", data.Id.ValueString())) @@ -1992,6 +1999,7 @@ tflog.Debug(ctx, fmt.Sprintf("Update of resource aci_{{ .ResourceName }} with id // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_{{.ResourceName}} with id '%s'", data.Id.ValueString())) } @@ -2034,10 +2042,11 @@ func (r *{{.ResourceClassName}}Resource) Delete(ctx context.Context, req resourc func (r *{{.ResourceClassName}}Resource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_{{.ResourceName}}") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *{{.ResourceClassName}}ResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_{{.ResourceName}} with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_{{.ResourceName}}") @@ -2050,11 +2059,17 @@ func getAndSet{{.ResourceClassName}}Attributes(ctx context.Context, diags *diag. requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "GET", nil) {{- end}} - readData := getEmpty{{.ResourceClassName}}ResourceModel() - if diags.HasError() { return } + + set{{.ResourceClassName}}Attributes(ctx, diags, data, requestData) +} + +func set{{.ResourceClassName}}Attributes(ctx context.Context, diags *diag.Diagnostics, data *{{.ResourceClassName}}ResourceModel, requestData *container.Container) { + + readData := getEmpty{{.ResourceClassName}}ResourceModel() + if requestData.Search("imdata").Search("{{.PkgName}}").Data() != nil { classReadInfo := requestData.Search("imdata").Search("{{.PkgName}}").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/provider.go b/internal/provider/provider.go index d2e038613..b68e56c2b 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -20,6 +20,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/provider/schema" "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/identityschema" // temporary unused until muxing is removed // "github.com/hashicorp/terraform-plugin-framework/schema/validator" @@ -35,6 +36,22 @@ var globalAllowExistingOnCreate bool var _ provider.Provider = &AciProvider{} var _ provider.ProviderWithFunctions = &AciProvider{} +// Struct model for identity data handling +type IdentityModel struct { + Id types.String `tfsdk:"id"` +} + +// Generic identity schema for each resource +func getIdentitySchema() identityschema.Schema { + return identityschema.Schema{ + Attributes: map[string]identityschema.Attribute{ + "id": identityschema.StringAttribute{ + RequiredForImport: true, + }, + }, + } +} + // AciProvider defines the provider implementation. type AciProvider struct { version string diff --git a/internal/provider/resource_aci_access_interface_override.go b/internal/provider/resource_aci_access_interface_override.go index 4efb66662..d6d8f37a5 100644 --- a/internal/provider/resource_aci_access_interface_override.go +++ b/internal/provider/resource_aci_access_interface_override.go @@ -29,12 +29,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &InfraHPathSResource{} +var _ resource.ResourceWithIdentity = &InfraHPathSResource{} var _ resource.ResourceWithImportState = &InfraHPathSResource{} func NewInfraHPathSResource() resource.Resource { return &InfraHPathSResource{} } +func (r InfraHPathSResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // InfraHPathSResource defines the resource implementation. type InfraHPathSResource struct { client *client.Client @@ -708,6 +713,7 @@ func (r *InfraHPathSResource) Create(ctx context.Context, req resource.CreateReq // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_access_interface_override with id '%s'", data.Id.ValueString())) } @@ -732,6 +738,7 @@ func (r *InfraHPathSResource) Read(ctx context.Context, req resource.ReadRequest resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_access_interface_override with id '%s'", data.Id.ValueString())) @@ -780,6 +787,7 @@ func (r *InfraHPathSResource) Update(ctx context.Context, req resource.UpdateReq // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_access_interface_override with id '%s'", data.Id.ValueString())) } @@ -808,10 +816,11 @@ func (r *InfraHPathSResource) Delete(ctx context.Context, req resource.DeleteReq func (r *InfraHPathSResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_access_interface_override") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *InfraHPathSResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_access_interface_override with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_access_interface_override") @@ -820,11 +829,17 @@ func (r *InfraHPathSResource) ImportState(ctx context.Context, req resource.Impo func getAndSetInfraHPathSAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *InfraHPathSResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "infraHPathS,infraRsHPathAtt,infraRsPathToAccBaseGrp,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyInfraHPathSResourceModel() - if diags.HasError() { return } + + setInfraHPathSAttributes(ctx, diags, data, requestData) +} + +func setInfraHPathSAttributes(ctx context.Context, diags *diag.Diagnostics, data *InfraHPathSResourceModel, requestData *container.Container) { + + readData := getEmptyInfraHPathSResourceModel() + if requestData.Search("imdata").Search("infraHPathS").Data() != nil { classReadInfo := requestData.Search("imdata").Search("infraHPathS").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_access_port_block.go b/internal/provider/resource_aci_access_port_block.go index f8ae8bc2e..fbbdbaab4 100644 --- a/internal/provider/resource_aci_access_port_block.go +++ b/internal/provider/resource_aci_access_port_block.go @@ -30,12 +30,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &InfraPortBlkResource{} +var _ resource.ResourceWithIdentity = &InfraPortBlkResource{} var _ resource.ResourceWithImportState = &InfraPortBlkResource{} func NewInfraPortBlkResource() resource.Resource { return &InfraPortBlkResource{} } +func (r InfraPortBlkResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // InfraPortBlkResource defines the resource implementation. type InfraPortBlkResource struct { client *client.Client @@ -807,6 +812,7 @@ func (r *InfraPortBlkResource) Create(ctx context.Context, req resource.CreateRe // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_access_port_block with id '%s'", data.Id.ValueString())) } @@ -831,6 +837,7 @@ func (r *InfraPortBlkResource) Read(ctx context.Context, req resource.ReadReques resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_access_port_block with id '%s'", data.Id.ValueString())) @@ -876,6 +883,7 @@ func (r *InfraPortBlkResource) Update(ctx context.Context, req resource.UpdateRe // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_access_port_block with id '%s'", data.Id.ValueString())) } @@ -904,10 +912,11 @@ func (r *InfraPortBlkResource) Delete(ctx context.Context, req resource.DeleteRe func (r *InfraPortBlkResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_access_port_block") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *InfraPortBlkResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_access_port_block with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_access_port_block") @@ -916,11 +925,17 @@ func (r *InfraPortBlkResource) ImportState(ctx context.Context, req resource.Imp func getAndSetInfraPortBlkAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *InfraPortBlkResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "infraPortBlk,infraRsAccBndlSubgrp,tagAnnotation,tagTag,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyInfraPortBlkResourceModel() - if diags.HasError() { return } + + setInfraPortBlkAttributes(ctx, diags, data, requestData) +} + +func setInfraPortBlkAttributes(ctx context.Context, diags *diag.Diagnostics, data *InfraPortBlkResourceModel, requestData *container.Container) { + + readData := getEmptyInfraPortBlkResourceModel() + if requestData.Search("imdata").Search("infraPortBlk").Data() != nil { classReadInfo := requestData.Search("imdata").Search("infraPortBlk").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_access_port_selector.go b/internal/provider/resource_aci_access_port_selector.go index bf0b68f53..085d6364b 100644 --- a/internal/provider/resource_aci_access_port_selector.go +++ b/internal/provider/resource_aci_access_port_selector.go @@ -30,12 +30,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &InfraHPortSResource{} +var _ resource.ResourceWithIdentity = &InfraHPortSResource{} var _ resource.ResourceWithImportState = &InfraHPortSResource{} func NewInfraHPortSResource() resource.Resource { return &InfraHPortSResource{} } +func (r InfraHPortSResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // InfraHPortSResource defines the resource implementation. type InfraHPortSResource struct { client *client.Client @@ -831,6 +836,7 @@ func (r *InfraHPortSResource) Create(ctx context.Context, req resource.CreateReq // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_access_port_selector with id '%s'", data.Id.ValueString())) } @@ -855,6 +861,7 @@ func (r *InfraHPortSResource) Read(ctx context.Context, req resource.ReadRequest resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_access_port_selector with id '%s'", data.Id.ValueString())) @@ -900,6 +907,7 @@ func (r *InfraHPortSResource) Update(ctx context.Context, req resource.UpdateReq // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_access_port_selector with id '%s'", data.Id.ValueString())) } @@ -928,10 +936,11 @@ func (r *InfraHPortSResource) Delete(ctx context.Context, req resource.DeleteReq func (r *InfraHPortSResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_access_port_selector") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *InfraHPortSResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_access_port_selector with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_access_port_selector") @@ -940,11 +949,17 @@ func (r *InfraHPortSResource) ImportState(ctx context.Context, req resource.Impo func getAndSetInfraHPortSAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *InfraHPortSResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "infraHPortS,infraRsAccBaseGrp,tagAnnotation,tagTag,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyInfraHPortSResourceModel() - if diags.HasError() { return } + + setInfraHPortSAttributes(ctx, diags, data, requestData) +} + +func setInfraHPortSAttributes(ctx context.Context, diags *diag.Diagnostics, data *InfraHPortSResourceModel, requestData *container.Container) { + + readData := getEmptyInfraHPortSResourceModel() + if requestData.Search("imdata").Search("infraHPortS").Data() != nil { classReadInfo := requestData.Search("imdata").Search("infraHPortS").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_annotation.go b/internal/provider/resource_aci_annotation.go index 851db5438..2adb24e5c 100644 --- a/internal/provider/resource_aci_annotation.go +++ b/internal/provider/resource_aci_annotation.go @@ -24,12 +24,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &TagAnnotationResource{} +var _ resource.ResourceWithIdentity = &TagAnnotationResource{} var _ resource.ResourceWithImportState = &TagAnnotationResource{} func NewTagAnnotationResource() resource.Resource { return &TagAnnotationResource{} } +func (r TagAnnotationResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // TagAnnotationResource defines the resource implementation. type TagAnnotationResource struct { client *client.Client @@ -187,6 +192,7 @@ func (r *TagAnnotationResource) Create(ctx context.Context, req resource.CreateR // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_annotation with id '%s'", data.Id.ValueString())) } @@ -211,6 +217,7 @@ func (r *TagAnnotationResource) Read(ctx context.Context, req resource.ReadReque resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_annotation with id '%s'", data.Id.ValueString())) @@ -245,6 +252,7 @@ func (r *TagAnnotationResource) Update(ctx context.Context, req resource.UpdateR // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_annotation with id '%s'", data.Id.ValueString())) } @@ -273,10 +281,11 @@ func (r *TagAnnotationResource) Delete(ctx context.Context, req resource.DeleteR func (r *TagAnnotationResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_annotation") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *TagAnnotationResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_annotation with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_annotation") @@ -285,11 +294,17 @@ func (r *TagAnnotationResource) ImportState(ctx context.Context, req resource.Im func getAndSetTagAnnotationAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *TagAnnotationResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "GET", nil) - readData := getEmptyTagAnnotationResourceModel() - if diags.HasError() { return } + + setTagAnnotationAttributes(ctx, diags, data, requestData) +} + +func setTagAnnotationAttributes(ctx context.Context, diags *diag.Diagnostics, data *TagAnnotationResourceModel, requestData *container.Container) { + + readData := getEmptyTagAnnotationResourceModel() + if requestData.Search("imdata").Search("tagAnnotation").Data() != nil { classReadInfo := requestData.Search("imdata").Search("tagAnnotation").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_any.go b/internal/provider/resource_aci_any.go index e34b746dc..321cc5d84 100644 --- a/internal/provider/resource_aci_any.go +++ b/internal/provider/resource_aci_any.go @@ -32,12 +32,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &VzAnyResource{} +var _ resource.ResourceWithIdentity = &VzAnyResource{} var _ resource.ResourceWithImportState = &VzAnyResource{} func NewVzAnyResource() resource.Resource { return &VzAnyResource{} } +func (r VzAnyResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // VzAnyResource defines the resource implementation. type VzAnyResource struct { client *client.Client @@ -1593,6 +1598,7 @@ func (r *VzAnyResource) Create(ctx context.Context, req resource.CreateRequest, // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_any with id '%s'", data.Id.ValueString())) } @@ -1617,6 +1623,7 @@ func (r *VzAnyResource) Read(ctx context.Context, req resource.ReadRequest, resp resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_any with id '%s'", data.Id.ValueString())) @@ -1668,6 +1675,7 @@ func (r *VzAnyResource) Update(ctx context.Context, req resource.UpdateRequest, // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_any with id '%s'", data.Id.ValueString())) } @@ -1698,10 +1706,11 @@ func (r *VzAnyResource) Delete(ctx context.Context, req resource.DeleteRequest, func (r *VzAnyResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_any") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *VzAnyResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_any with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_any") @@ -1710,11 +1719,17 @@ func (r *VzAnyResource) ImportState(ctx context.Context, req resource.ImportStat func getAndSetVzAnyAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *VzAnyResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "vzAny,tagAnnotation,tagTag,vzRsAnyToCons,vzRsAnyToConsIf,vzRsAnyToProv,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyVzAnyResourceModel() - if diags.HasError() { return } + + setVzAnyAttributes(ctx, diags, data, requestData) +} + +func setVzAnyAttributes(ctx context.Context, diags *diag.Diagnostics, data *VzAnyResourceModel, requestData *container.Container) { + + readData := getEmptyVzAnyResourceModel() + if requestData.Search("imdata").Search("vzAny").Data() != nil { classReadInfo := requestData.Search("imdata").Search("vzAny").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_application_epg.go b/internal/provider/resource_aci_application_epg.go index 4700269c0..529afea17 100644 --- a/internal/provider/resource_aci_application_epg.go +++ b/internal/provider/resource_aci_application_epg.go @@ -33,12 +33,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvAEPgResource{} +var _ resource.ResourceWithIdentity = &FvAEPgResource{} var _ resource.ResourceWithImportState = &FvAEPgResource{} func NewFvAEPgResource() resource.Resource { return &FvAEPgResource{} } +func (r FvAEPgResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvAEPgResource defines the resource implementation. type FvAEPgResource struct { client *client.Client @@ -7202,6 +7207,7 @@ func (r *FvAEPgResource) Create(ctx context.Context, req resource.CreateRequest, // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_application_epg with id '%s'", data.Id.ValueString())) } @@ -7226,6 +7232,7 @@ func (r *FvAEPgResource) Read(ctx context.Context, req resource.ReadRequest, res resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_application_epg with id '%s'", data.Id.ValueString())) @@ -7350,6 +7357,7 @@ func (r *FvAEPgResource) Update(ctx context.Context, req resource.UpdateRequest, // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_application_epg with id '%s'", data.Id.ValueString())) } @@ -7378,10 +7386,11 @@ func (r *FvAEPgResource) Delete(ctx context.Context, req resource.DeleteRequest, func (r *FvAEPgResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_application_epg") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvAEPgResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_application_epg with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_application_epg") @@ -7390,11 +7399,17 @@ func (r *FvAEPgResource) ImportState(ctx context.Context, req resource.ImportSta func getAndSetFvAEPgAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvAEPgResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvAEPg,fvCrtrn,fvRsAEPgMonPol,fvRsAepAtt,fvRsBd,fvRsCons,fvRsConsIf,fvRsCustQosPol,fvRsDomAtt,fvRsDppPol,fvRsFcPathAtt,fvRsIntraEpg,fvRsNodeAtt,fvRsPathAtt,fvRsProtBy,fvRsProv,fvRsSecInherited,fvRsTrustCtrl,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,fvUplinkOrderCont,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvAEPgResourceModel() - if diags.HasError() { return } + + setFvAEPgAttributes(ctx, diags, data, requestData) +} + +func setFvAEPgAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvAEPgResourceModel, requestData *container.Container) { + + readData := getEmptyFvAEPgResourceModel() + if requestData.Search("imdata").Search("fvAEPg").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvAEPg").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_application_profile.go b/internal/provider/resource_aci_application_profile.go index 820eecd8f..3ce0f7a48 100644 --- a/internal/provider/resource_aci_application_profile.go +++ b/internal/provider/resource_aci_application_profile.go @@ -32,12 +32,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvApResource{} +var _ resource.ResourceWithIdentity = &FvApResource{} var _ resource.ResourceWithImportState = &FvApResource{} func NewFvApResource() resource.Resource { return &FvApResource{} } +func (r FvApResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvApResource defines the resource implementation. type FvApResource struct { client *client.Client @@ -819,6 +824,7 @@ func (r *FvApResource) Create(ctx context.Context, req resource.CreateRequest, r // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_application_profile with id '%s'", data.Id.ValueString())) } @@ -843,6 +849,7 @@ func (r *FvApResource) Read(ctx context.Context, req resource.ReadRequest, resp resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_application_profile with id '%s'", data.Id.ValueString())) @@ -888,6 +895,7 @@ func (r *FvApResource) Update(ctx context.Context, req resource.UpdateRequest, r // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_application_profile with id '%s'", data.Id.ValueString())) } @@ -916,10 +924,11 @@ func (r *FvApResource) Delete(ctx context.Context, req resource.DeleteRequest, r func (r *FvApResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_application_profile") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvApResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_application_profile with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_application_profile") @@ -928,11 +937,17 @@ func (r *FvApResource) ImportState(ctx context.Context, req resource.ImportState func getAndSetFvApAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvApResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvAp,fvRsApMonPol,tagAnnotation,tagTag,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvApResourceModel() - if diags.HasError() { return } + + setFvApAttributes(ctx, diags, data, requestData) +} + +func setFvApAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvApResourceModel, requestData *container.Container) { + + readData := getEmptyFvApResourceModel() + if requestData.Search("imdata").Search("fvAp").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvAp").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_associated_site.go b/internal/provider/resource_aci_associated_site.go index 2da60c568..6a8b0aab0 100644 --- a/internal/provider/resource_aci_associated_site.go +++ b/internal/provider/resource_aci_associated_site.go @@ -27,12 +27,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvSiteAssociatedResource{} +var _ resource.ResourceWithIdentity = &FvSiteAssociatedResource{} var _ resource.ResourceWithImportState = &FvSiteAssociatedResource{} func NewFvSiteAssociatedResource() resource.Resource { return &FvSiteAssociatedResource{} } +func (r FvSiteAssociatedResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvSiteAssociatedResource defines the resource implementation. type FvSiteAssociatedResource struct { client *client.Client @@ -678,6 +683,7 @@ func (r *FvSiteAssociatedResource) Create(ctx context.Context, req resource.Crea // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_associated_site with id '%s'", data.Id.ValueString())) } @@ -702,6 +708,7 @@ func (r *FvSiteAssociatedResource) Read(ctx context.Context, req resource.ReadRe resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_associated_site with id '%s'", data.Id.ValueString())) @@ -747,6 +754,7 @@ func (r *FvSiteAssociatedResource) Update(ctx context.Context, req resource.Upda // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_associated_site with id '%s'", data.Id.ValueString())) } @@ -775,10 +783,11 @@ func (r *FvSiteAssociatedResource) Delete(ctx context.Context, req resource.Dele func (r *FvSiteAssociatedResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_associated_site") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvSiteAssociatedResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_associated_site with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_associated_site") @@ -787,11 +796,17 @@ func (r *FvSiteAssociatedResource) ImportState(ctx context.Context, req resource func getAndSetFvSiteAssociatedAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvSiteAssociatedResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvSiteAssociated,fvRemoteId,tagAnnotation,tagTag,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvSiteAssociatedResourceModel() - if diags.HasError() { return } + + setFvSiteAssociatedAttributes(ctx, diags, data, requestData) +} + +func setFvSiteAssociatedAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvSiteAssociatedResourceModel, requestData *container.Container) { + + readData := getEmptyFvSiteAssociatedResourceModel() + if requestData.Search("imdata").Search("fvSiteAssociated").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvSiteAssociated").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_attachable_access_entity_profile.go b/internal/provider/resource_aci_attachable_access_entity_profile.go index b7b914fc0..b3a61ec9c 100644 --- a/internal/provider/resource_aci_attachable_access_entity_profile.go +++ b/internal/provider/resource_aci_attachable_access_entity_profile.go @@ -30,12 +30,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &InfraAttEntityPResource{} +var _ resource.ResourceWithIdentity = &InfraAttEntityPResource{} var _ resource.ResourceWithImportState = &InfraAttEntityPResource{} func NewInfraAttEntityPResource() resource.Resource { return &InfraAttEntityPResource{} } +func (r InfraAttEntityPResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // InfraAttEntityPResource defines the resource implementation. type InfraAttEntityPResource struct { client *client.Client @@ -774,6 +779,7 @@ func (r *InfraAttEntityPResource) Create(ctx context.Context, req resource.Creat // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_attachable_access_entity_profile with id '%s'", data.Id.ValueString())) } @@ -798,6 +804,7 @@ func (r *InfraAttEntityPResource) Read(ctx context.Context, req resource.ReadReq resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_attachable_access_entity_profile with id '%s'", data.Id.ValueString())) @@ -843,6 +850,7 @@ func (r *InfraAttEntityPResource) Update(ctx context.Context, req resource.Updat // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_attachable_access_entity_profile with id '%s'", data.Id.ValueString())) } @@ -871,10 +879,11 @@ func (r *InfraAttEntityPResource) Delete(ctx context.Context, req resource.Delet func (r *InfraAttEntityPResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_attachable_access_entity_profile") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *InfraAttEntityPResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_attachable_access_entity_profile with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_attachable_access_entity_profile") @@ -883,11 +892,17 @@ func (r *InfraAttEntityPResource) ImportState(ctx context.Context, req resource. func getAndSetInfraAttEntityPAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *InfraAttEntityPResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "infraAttEntityP,infraRsDomP,tagAnnotation,tagTag,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyInfraAttEntityPResourceModel() - if diags.HasError() { return } + + setInfraAttEntityPAttributes(ctx, diags, data, requestData) +} + +func setInfraAttEntityPAttributes(ctx context.Context, diags *diag.Diagnostics, data *InfraAttEntityPResourceModel, requestData *container.Container) { + + readData := getEmptyInfraAttEntityPResourceModel() + if requestData.Search("imdata").Search("infraAttEntityP").Data() != nil { classReadInfo := requestData.Search("imdata").Search("infraAttEntityP").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_bridge_domain.go b/internal/provider/resource_aci_bridge_domain.go index fee252836..dbef6da58 100644 --- a/internal/provider/resource_aci_bridge_domain.go +++ b/internal/provider/resource_aci_bridge_domain.go @@ -31,12 +31,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvBDResource{} +var _ resource.ResourceWithIdentity = &FvBDResource{} var _ resource.ResourceWithImportState = &FvBDResource{} func NewFvBDResource() resource.Resource { return &FvBDResource{} } +func (r FvBDResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvBDResource defines the resource implementation. type FvBDResource struct { client *client.Client @@ -5048,6 +5053,7 @@ func (r *FvBDResource) Create(ctx context.Context, req resource.CreateRequest, r // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_bridge_domain with id '%s'", data.Id.ValueString())) } @@ -5072,6 +5078,7 @@ func (r *FvBDResource) Read(ctx context.Context, req resource.ReadRequest, resp resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_bridge_domain with id '%s'", data.Id.ValueString())) @@ -5183,6 +5190,7 @@ func (r *FvBDResource) Update(ctx context.Context, req resource.UpdateRequest, r // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_bridge_domain with id '%s'", data.Id.ValueString())) } @@ -5211,10 +5219,11 @@ func (r *FvBDResource) Delete(ctx context.Context, req resource.DeleteRequest, r func (r *FvBDResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_bridge_domain") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvBDResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_bridge_domain with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_bridge_domain") @@ -5223,11 +5232,17 @@ func (r *FvBDResource) ImportState(ctx context.Context, req resource.ImportState func getAndSetFvBDAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvBDResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvBD,fvAccP,fvRogueExceptionMac,fvRsABDPolMonPol,fvRsBDToFhs,fvRsBDToNdP,fvRsBDToNetflowMonitorPol,fvRsBDToOut,fvRsBDToProfile,fvRsBDToRelayP,fvRsBdToEpRet,fvRsCtx,fvRsIgmpsn,fvRsMldsn,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvBDResourceModel() - if diags.HasError() { return } + + setFvBDAttributes(ctx, diags, data, requestData) +} + +func setFvBDAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvBDResourceModel, requestData *container.Container) { + + readData := getEmptyFvBDResourceModel() + if requestData.Search("imdata").Search("fvBD").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvBD").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_certificate_authority.go b/internal/provider/resource_aci_certificate_authority.go index a20daaef8..24f5307e8 100644 --- a/internal/provider/resource_aci_certificate_authority.go +++ b/internal/provider/resource_aci_certificate_authority.go @@ -31,12 +31,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &PkiTPResource{} +var _ resource.ResourceWithIdentity = &PkiTPResource{} var _ resource.ResourceWithImportState = &PkiTPResource{} func NewPkiTPResource() resource.Resource { return &PkiTPResource{} } +func (r PkiTPResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // PkiTPResource defines the resource implementation. type PkiTPResource struct { client *client.Client @@ -405,6 +410,7 @@ func (r *PkiTPResource) Create(ctx context.Context, req resource.CreateRequest, // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_certificate_authority with id '%s'", data.Id.ValueString())) } @@ -429,6 +435,7 @@ func (r *PkiTPResource) Read(ctx context.Context, req resource.ReadRequest, resp resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_certificate_authority with id '%s'", data.Id.ValueString())) @@ -483,6 +490,7 @@ func (r *PkiTPResource) Update(ctx context.Context, req resource.UpdateRequest, // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_certificate_authority with id '%s'", data.Id.ValueString())) } @@ -511,10 +519,11 @@ func (r *PkiTPResource) Delete(ctx context.Context, req resource.DeleteRequest, func (r *PkiTPResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_certificate_authority") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *PkiTPResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_certificate_authority with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_certificate_authority") @@ -523,11 +532,17 @@ func (r *PkiTPResource) ImportState(ctx context.Context, req resource.ImportStat func getAndSetPkiTPAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *PkiTPResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "pkiTP,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyPkiTPResourceModel() - if diags.HasError() { return } + + setPkiTPAttributes(ctx, diags, data, requestData) +} + +func setPkiTPAttributes(ctx context.Context, diags *diag.Diagnostics, data *PkiTPResourceModel, requestData *container.Container) { + + readData := getEmptyPkiTPResourceModel() + if requestData.Search("imdata").Search("pkiTP").Data() != nil { classReadInfo := requestData.Search("imdata").Search("pkiTP").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_custom_qos_policy.go b/internal/provider/resource_aci_custom_qos_policy.go index 56ad2b507..d569baa55 100644 --- a/internal/provider/resource_aci_custom_qos_policy.go +++ b/internal/provider/resource_aci_custom_qos_policy.go @@ -31,12 +31,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &QosCustomPolResource{} +var _ resource.ResourceWithIdentity = &QosCustomPolResource{} var _ resource.ResourceWithImportState = &QosCustomPolResource{} func NewQosCustomPolResource() resource.Resource { return &QosCustomPolResource{} } +func (r QosCustomPolResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // QosCustomPolResource defines the resource implementation. type QosCustomPolResource struct { client *client.Client @@ -1052,6 +1057,7 @@ func (r *QosCustomPolResource) Create(ctx context.Context, req resource.CreateRe // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_custom_qos_policy with id '%s'", data.Id.ValueString())) } @@ -1076,6 +1082,7 @@ func (r *QosCustomPolResource) Read(ctx context.Context, req resource.ReadReques resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_custom_qos_policy with id '%s'", data.Id.ValueString())) @@ -1124,6 +1131,7 @@ func (r *QosCustomPolResource) Update(ctx context.Context, req resource.UpdateRe // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_custom_qos_policy with id '%s'", data.Id.ValueString())) } @@ -1152,10 +1160,11 @@ func (r *QosCustomPolResource) Delete(ctx context.Context, req resource.DeleteRe func (r *QosCustomPolResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_custom_qos_policy") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *QosCustomPolResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_custom_qos_policy with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_custom_qos_policy") @@ -1164,11 +1173,17 @@ func (r *QosCustomPolResource) ImportState(ctx context.Context, req resource.Imp func getAndSetQosCustomPolAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *QosCustomPolResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "qosCustomPol,qosDot1PClass,qosDscpClass,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyQosCustomPolResourceModel() - if diags.HasError() { return } + + setQosCustomPolAttributes(ctx, diags, data, requestData) +} + +func setQosCustomPolAttributes(ctx context.Context, diags *diag.Diagnostics, data *QosCustomPolResourceModel, requestData *container.Container) { + + readData := getEmptyQosCustomPolResourceModel() + if requestData.Search("imdata").Search("qosCustomPol").Data() != nil { classReadInfo := requestData.Search("imdata").Search("qosCustomPol").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_data_plane_policing_policy.go b/internal/provider/resource_aci_data_plane_policing_policy.go index 8832dc3cd..e0403e687 100644 --- a/internal/provider/resource_aci_data_plane_policing_policy.go +++ b/internal/provider/resource_aci_data_plane_policing_policy.go @@ -31,12 +31,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &QosDppPolResource{} +var _ resource.ResourceWithIdentity = &QosDppPolResource{} var _ resource.ResourceWithImportState = &QosDppPolResource{} func NewQosDppPolResource() resource.Resource { return &QosDppPolResource{} } +func (r QosDppPolResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // QosDppPolResource defines the resource implementation. type QosDppPolResource struct { client *client.Client @@ -688,6 +693,7 @@ func (r *QosDppPolResource) Create(ctx context.Context, req resource.CreateReque // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_data_plane_policing_policy with id '%s'", data.Id.ValueString())) } @@ -712,6 +718,7 @@ func (r *QosDppPolResource) Read(ctx context.Context, req resource.ReadRequest, resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_data_plane_policing_policy with id '%s'", data.Id.ValueString())) @@ -754,6 +761,7 @@ func (r *QosDppPolResource) Update(ctx context.Context, req resource.UpdateReque // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_data_plane_policing_policy with id '%s'", data.Id.ValueString())) } @@ -782,10 +790,11 @@ func (r *QosDppPolResource) Delete(ctx context.Context, req resource.DeleteReque func (r *QosDppPolResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_data_plane_policing_policy") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *QosDppPolResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_data_plane_policing_policy with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_data_plane_policing_policy") @@ -794,11 +803,17 @@ func (r *QosDppPolResource) ImportState(ctx context.Context, req resource.Import func getAndSetQosDppPolAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *QosDppPolResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "qosDppPol,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyQosDppPolResourceModel() - if diags.HasError() { return } + + setQosDppPolAttributes(ctx, diags, data, requestData) +} + +func setQosDppPolAttributes(ctx context.Context, diags *diag.Diagnostics, data *QosDppPolResourceModel, requestData *container.Container) { + + readData := getEmptyQosDppPolResourceModel() + if requestData.Search("imdata").Search("qosDppPol").Data() != nil { classReadInfo := requestData.Search("imdata").Search("qosDppPol").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_dot1p_classifier.go b/internal/provider/resource_aci_dot1p_classifier.go index 7066463ac..5ca0832d4 100644 --- a/internal/provider/resource_aci_dot1p_classifier.go +++ b/internal/provider/resource_aci_dot1p_classifier.go @@ -31,12 +31,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &QosDot1PClassResource{} +var _ resource.ResourceWithIdentity = &QosDot1PClassResource{} var _ resource.ResourceWithImportState = &QosDot1PClassResource{} func NewQosDot1PClassResource() resource.Resource { return &QosDot1PClassResource{} } +func (r QosDot1PClassResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // QosDot1PClassResource defines the resource implementation. type QosDot1PClassResource struct { client *client.Client @@ -435,6 +440,7 @@ func (r *QosDot1PClassResource) Create(ctx context.Context, req resource.CreateR // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_dot1p_classifier with id '%s'", data.Id.ValueString())) } @@ -459,6 +465,7 @@ func (r *QosDot1PClassResource) Read(ctx context.Context, req resource.ReadReque resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_dot1p_classifier with id '%s'", data.Id.ValueString())) @@ -501,6 +508,7 @@ func (r *QosDot1PClassResource) Update(ctx context.Context, req resource.UpdateR // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_dot1p_classifier with id '%s'", data.Id.ValueString())) } @@ -529,10 +537,11 @@ func (r *QosDot1PClassResource) Delete(ctx context.Context, req resource.DeleteR func (r *QosDot1PClassResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_dot1p_classifier") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *QosDot1PClassResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_dot1p_classifier with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_dot1p_classifier") @@ -541,11 +550,17 @@ func (r *QosDot1PClassResource) ImportState(ctx context.Context, req resource.Im func getAndSetQosDot1PClassAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *QosDot1PClassResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "qosDot1PClass,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyQosDot1PClassResourceModel() - if diags.HasError() { return } + + setQosDot1PClassAttributes(ctx, diags, data, requestData) +} + +func setQosDot1PClassAttributes(ctx context.Context, diags *diag.Diagnostics, data *QosDot1PClassResourceModel, requestData *container.Container) { + + readData := getEmptyQosDot1PClassResourceModel() + if requestData.Search("imdata").Search("qosDot1PClass").Data() != nil { classReadInfo := requestData.Search("imdata").Search("qosDot1PClass").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_dscp_to_priority_map.go b/internal/provider/resource_aci_dscp_to_priority_map.go index 4cce73d01..727cc8adf 100644 --- a/internal/provider/resource_aci_dscp_to_priority_map.go +++ b/internal/provider/resource_aci_dscp_to_priority_map.go @@ -31,12 +31,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &QosDscpClassResource{} +var _ resource.ResourceWithIdentity = &QosDscpClassResource{} var _ resource.ResourceWithImportState = &QosDscpClassResource{} func NewQosDscpClassResource() resource.Resource { return &QosDscpClassResource{} } +func (r QosDscpClassResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // QosDscpClassResource defines the resource implementation. type QosDscpClassResource struct { client *client.Client @@ -435,6 +440,7 @@ func (r *QosDscpClassResource) Create(ctx context.Context, req resource.CreateRe // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_dscp_to_priority_map with id '%s'", data.Id.ValueString())) } @@ -459,6 +465,7 @@ func (r *QosDscpClassResource) Read(ctx context.Context, req resource.ReadReques resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_dscp_to_priority_map with id '%s'", data.Id.ValueString())) @@ -501,6 +508,7 @@ func (r *QosDscpClassResource) Update(ctx context.Context, req resource.UpdateRe // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_dscp_to_priority_map with id '%s'", data.Id.ValueString())) } @@ -529,10 +537,11 @@ func (r *QosDscpClassResource) Delete(ctx context.Context, req resource.DeleteRe func (r *QosDscpClassResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_dscp_to_priority_map") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *QosDscpClassResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_dscp_to_priority_map with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_dscp_to_priority_map") @@ -541,11 +550,17 @@ func (r *QosDscpClassResource) ImportState(ctx context.Context, req resource.Imp func getAndSetQosDscpClassAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *QosDscpClassResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "qosDscpClass,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyQosDscpClassResourceModel() - if diags.HasError() { return } + + setQosDscpClassAttributes(ctx, diags, data, requestData) +} + +func setQosDscpClassAttributes(ctx context.Context, diags *diag.Diagnostics, data *QosDscpClassResourceModel, requestData *container.Container) { + + readData := getEmptyQosDscpClassResourceModel() + if requestData.Search("imdata").Search("qosDscpClass").Data() != nil { classReadInfo := requestData.Search("imdata").Search("qosDscpClass").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_dwdm_interface_policy.go b/internal/provider/resource_aci_dwdm_interface_policy.go index fa4a99009..0d30ea24a 100644 --- a/internal/provider/resource_aci_dwdm_interface_policy.go +++ b/internal/provider/resource_aci_dwdm_interface_policy.go @@ -32,12 +32,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &DwdmIfPolResource{} +var _ resource.ResourceWithIdentity = &DwdmIfPolResource{} var _ resource.ResourceWithImportState = &DwdmIfPolResource{} func NewDwdmIfPolResource() resource.Resource { return &DwdmIfPolResource{} } +func (r DwdmIfPolResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // DwdmIfPolResource defines the resource implementation. type DwdmIfPolResource struct { client *client.Client @@ -375,6 +380,7 @@ func (r *DwdmIfPolResource) Create(ctx context.Context, req resource.CreateReque // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_dwdm_interface_policy with id '%s'", data.Id.ValueString())) } @@ -399,6 +405,7 @@ func (r *DwdmIfPolResource) Read(ctx context.Context, req resource.ReadRequest, resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_dwdm_interface_policy with id '%s'", data.Id.ValueString())) @@ -441,6 +448,7 @@ func (r *DwdmIfPolResource) Update(ctx context.Context, req resource.UpdateReque // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_dwdm_interface_policy with id '%s'", data.Id.ValueString())) } @@ -469,10 +477,11 @@ func (r *DwdmIfPolResource) Delete(ctx context.Context, req resource.DeleteReque func (r *DwdmIfPolResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_dwdm_interface_policy") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *DwdmIfPolResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_dwdm_interface_policy with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_dwdm_interface_policy") @@ -481,11 +490,17 @@ func (r *DwdmIfPolResource) ImportState(ctx context.Context, req resource.Import func getAndSetDwdmIfPolAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *DwdmIfPolResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "dwdmIfPol,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyDwdmIfPolResourceModel() - if diags.HasError() { return } + + setDwdmIfPolAttributes(ctx, diags, data, requestData) +} + +func setDwdmIfPolAttributes(ctx context.Context, diags *diag.Diagnostics, data *DwdmIfPolResourceModel, requestData *container.Container) { + + readData := getEmptyDwdmIfPolResourceModel() + if requestData.Search("imdata").Search("dwdmIfPol").Data() != nil { classReadInfo := requestData.Search("imdata").Search("dwdmIfPol").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_eigrp_address_family_context.go b/internal/provider/resource_aci_eigrp_address_family_context.go index 970ede9b7..a2fc930a6 100644 --- a/internal/provider/resource_aci_eigrp_address_family_context.go +++ b/internal/provider/resource_aci_eigrp_address_family_context.go @@ -29,12 +29,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &EigrpCtxAfPolResource{} +var _ resource.ResourceWithIdentity = &EigrpCtxAfPolResource{} var _ resource.ResourceWithImportState = &EigrpCtxAfPolResource{} func NewEigrpCtxAfPolResource() resource.Resource { return &EigrpCtxAfPolResource{} } +func (r EigrpCtxAfPolResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // EigrpCtxAfPolResource defines the resource implementation. type EigrpCtxAfPolResource struct { client *client.Client @@ -422,6 +427,7 @@ func (r *EigrpCtxAfPolResource) Create(ctx context.Context, req resource.CreateR // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_eigrp_address_family_context with id '%s'", data.Id.ValueString())) } @@ -446,6 +452,7 @@ func (r *EigrpCtxAfPolResource) Read(ctx context.Context, req resource.ReadReque resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_eigrp_address_family_context with id '%s'", data.Id.ValueString())) @@ -488,6 +495,7 @@ func (r *EigrpCtxAfPolResource) Update(ctx context.Context, req resource.UpdateR // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_eigrp_address_family_context with id '%s'", data.Id.ValueString())) } @@ -516,10 +524,11 @@ func (r *EigrpCtxAfPolResource) Delete(ctx context.Context, req resource.DeleteR func (r *EigrpCtxAfPolResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_eigrp_address_family_context") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *EigrpCtxAfPolResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_eigrp_address_family_context with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_eigrp_address_family_context") @@ -528,11 +537,17 @@ func (r *EigrpCtxAfPolResource) ImportState(ctx context.Context, req resource.Im func getAndSetEigrpCtxAfPolAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *EigrpCtxAfPolResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "eigrpCtxAfPol,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyEigrpCtxAfPolResourceModel() - if diags.HasError() { return } + + setEigrpCtxAfPolAttributes(ctx, diags, data, requestData) +} + +func setEigrpCtxAfPolAttributes(ctx context.Context, diags *diag.Diagnostics, data *EigrpCtxAfPolResourceModel, requestData *container.Container) { + + readData := getEmptyEigrpCtxAfPolResourceModel() + if requestData.Search("imdata").Search("eigrpCtxAfPol").Data() != nil { classReadInfo := requestData.Search("imdata").Search("eigrpCtxAfPol").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_endpoint_security_group.go b/internal/provider/resource_aci_endpoint_security_group.go index 11765f1e9..e9ee00911 100644 --- a/internal/provider/resource_aci_endpoint_security_group.go +++ b/internal/provider/resource_aci_endpoint_security_group.go @@ -33,12 +33,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvESgResource{} +var _ resource.ResourceWithIdentity = &FvESgResource{} var _ resource.ResourceWithImportState = &FvESgResource{} func NewFvESgResource() resource.Resource { return &FvESgResource{} } +func (r FvESgResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvESgResource defines the resource implementation. type FvESgResource struct { client *client.Client @@ -2970,6 +2975,7 @@ func (r *FvESgResource) Create(ctx context.Context, req resource.CreateRequest, // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_endpoint_security_group with id '%s'", data.Id.ValueString())) } @@ -2994,6 +3000,7 @@ func (r *FvESgResource) Read(ctx context.Context, req resource.ReadRequest, resp resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_endpoint_security_group with id '%s'", data.Id.ValueString())) @@ -3060,6 +3067,7 @@ func (r *FvESgResource) Update(ctx context.Context, req resource.UpdateRequest, // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_endpoint_security_group with id '%s'", data.Id.ValueString())) } @@ -3088,10 +3096,11 @@ func (r *FvESgResource) Delete(ctx context.Context, req resource.DeleteRequest, func (r *FvESgResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_endpoint_security_group") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvESgResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_endpoint_security_group with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_endpoint_security_group") @@ -3100,11 +3109,17 @@ func (r *FvESgResource) ImportState(ctx context.Context, req resource.ImportStat func getAndSetFvESgAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvESgResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvESg,fvRsCons,fvRsConsIf,fvRsIntraEpg,fvRsProv,fvRsScope,fvRsSecInherited,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvESgResourceModel() - if diags.HasError() { return } + + setFvESgAttributes(ctx, diags, data, requestData) +} + +func setFvESgAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvESgResourceModel, requestData *container.Container) { + + readData := getEmptyFvESgResourceModel() + if requestData.Search("imdata").Search("fvESg").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvESg").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_endpoint_tag_ip.go b/internal/provider/resource_aci_endpoint_tag_ip.go index 4f2fc3b5a..3a081d4f2 100644 --- a/internal/provider/resource_aci_endpoint_tag_ip.go +++ b/internal/provider/resource_aci_endpoint_tag_ip.go @@ -28,12 +28,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvEpIpTagResource{} +var _ resource.ResourceWithIdentity = &FvEpIpTagResource{} var _ resource.ResourceWithImportState = &FvEpIpTagResource{} func NewFvEpIpTagResource() resource.Resource { return &FvEpIpTagResource{} } +func (r FvEpIpTagResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvEpIpTagResource defines the resource implementation. type FvEpIpTagResource struct { client *client.Client @@ -364,6 +369,7 @@ func (r *FvEpIpTagResource) Create(ctx context.Context, req resource.CreateReque // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_endpoint_tag_ip with id '%s'", data.Id.ValueString())) } @@ -388,6 +394,7 @@ func (r *FvEpIpTagResource) Read(ctx context.Context, req resource.ReadRequest, resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_endpoint_tag_ip with id '%s'", data.Id.ValueString())) @@ -430,6 +437,7 @@ func (r *FvEpIpTagResource) Update(ctx context.Context, req resource.UpdateReque // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_endpoint_tag_ip with id '%s'", data.Id.ValueString())) } @@ -458,10 +466,11 @@ func (r *FvEpIpTagResource) Delete(ctx context.Context, req resource.DeleteReque func (r *FvEpIpTagResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_endpoint_tag_ip") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvEpIpTagResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_endpoint_tag_ip with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_endpoint_tag_ip") @@ -470,11 +479,17 @@ func (r *FvEpIpTagResource) ImportState(ctx context.Context, req resource.Import func getAndSetFvEpIpTagAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvEpIpTagResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvEpIpTag,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvEpIpTagResourceModel() - if diags.HasError() { return } + + setFvEpIpTagAttributes(ctx, diags, data, requestData) +} + +func setFvEpIpTagAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvEpIpTagResourceModel, requestData *container.Container) { + + readData := getEmptyFvEpIpTagResourceModel() + if requestData.Search("imdata").Search("fvEpIpTag").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvEpIpTag").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_endpoint_tag_mac.go b/internal/provider/resource_aci_endpoint_tag_mac.go index 781937fdc..7ee6e7d6c 100644 --- a/internal/provider/resource_aci_endpoint_tag_mac.go +++ b/internal/provider/resource_aci_endpoint_tag_mac.go @@ -28,12 +28,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvEpMacTagResource{} +var _ resource.ResourceWithIdentity = &FvEpMacTagResource{} var _ resource.ResourceWithImportState = &FvEpMacTagResource{} func NewFvEpMacTagResource() resource.Resource { return &FvEpMacTagResource{} } +func (r FvEpMacTagResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvEpMacTagResource defines the resource implementation. type FvEpMacTagResource struct { client *client.Client @@ -364,6 +369,7 @@ func (r *FvEpMacTagResource) Create(ctx context.Context, req resource.CreateRequ // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_endpoint_tag_mac with id '%s'", data.Id.ValueString())) } @@ -388,6 +394,7 @@ func (r *FvEpMacTagResource) Read(ctx context.Context, req resource.ReadRequest, resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_endpoint_tag_mac with id '%s'", data.Id.ValueString())) @@ -430,6 +437,7 @@ func (r *FvEpMacTagResource) Update(ctx context.Context, req resource.UpdateRequ // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_endpoint_tag_mac with id '%s'", data.Id.ValueString())) } @@ -458,10 +466,11 @@ func (r *FvEpMacTagResource) Delete(ctx context.Context, req resource.DeleteRequ func (r *FvEpMacTagResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_endpoint_tag_mac") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvEpMacTagResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_endpoint_tag_mac with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_endpoint_tag_mac") @@ -470,11 +479,17 @@ func (r *FvEpMacTagResource) ImportState(ctx context.Context, req resource.Impor func getAndSetFvEpMacTagAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvEpMacTagResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvEpMacTag,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvEpMacTagResourceModel() - if diags.HasError() { return } + + setFvEpMacTagAttributes(ctx, diags, data, requestData) +} + +func setFvEpMacTagAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvEpMacTagResourceModel, requestData *container.Container) { + + readData := getEmptyFvEpMacTagResourceModel() + if requestData.Search("imdata").Search("fvEpMacTag").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvEpMacTag").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_epg_useg_ad_group_attribute.go b/internal/provider/resource_aci_epg_useg_ad_group_attribute.go index 82fbe4bfc..0b259bd18 100644 --- a/internal/provider/resource_aci_epg_useg_ad_group_attribute.go +++ b/internal/provider/resource_aci_epg_useg_ad_group_attribute.go @@ -27,12 +27,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvIdGroupAttrResource{} +var _ resource.ResourceWithIdentity = &FvIdGroupAttrResource{} var _ resource.ResourceWithImportState = &FvIdGroupAttrResource{} func NewFvIdGroupAttrResource() resource.Resource { return &FvIdGroupAttrResource{} } +func (r FvIdGroupAttrResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvIdGroupAttrResource defines the resource implementation. type FvIdGroupAttrResource struct { client *client.Client @@ -373,6 +378,7 @@ func (r *FvIdGroupAttrResource) Create(ctx context.Context, req resource.CreateR // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_epg_useg_ad_group_attribute with id '%s'", data.Id.ValueString())) } @@ -397,6 +403,7 @@ func (r *FvIdGroupAttrResource) Read(ctx context.Context, req resource.ReadReque resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_epg_useg_ad_group_attribute with id '%s'", data.Id.ValueString())) @@ -439,6 +446,7 @@ func (r *FvIdGroupAttrResource) Update(ctx context.Context, req resource.UpdateR // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_epg_useg_ad_group_attribute with id '%s'", data.Id.ValueString())) } @@ -467,10 +475,11 @@ func (r *FvIdGroupAttrResource) Delete(ctx context.Context, req resource.DeleteR func (r *FvIdGroupAttrResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_epg_useg_ad_group_attribute") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvIdGroupAttrResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_epg_useg_ad_group_attribute with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_epg_useg_ad_group_attribute") @@ -479,11 +488,17 @@ func (r *FvIdGroupAttrResource) ImportState(ctx context.Context, req resource.Im func getAndSetFvIdGroupAttrAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvIdGroupAttrResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvIdGroupAttr,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvIdGroupAttrResourceModel() - if diags.HasError() { return } + + setFvIdGroupAttrAttributes(ctx, diags, data, requestData) +} + +func setFvIdGroupAttrAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvIdGroupAttrResourceModel, requestData *container.Container) { + + readData := getEmptyFvIdGroupAttrResourceModel() + if requestData.Search("imdata").Search("fvIdGroupAttr").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvIdGroupAttr").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_epg_useg_block_statement.go b/internal/provider/resource_aci_epg_useg_block_statement.go index 2b64adc65..fa107d6f2 100644 --- a/internal/provider/resource_aci_epg_useg_block_statement.go +++ b/internal/provider/resource_aci_epg_useg_block_statement.go @@ -29,12 +29,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvCrtrnResource{} +var _ resource.ResourceWithIdentity = &FvCrtrnResource{} var _ resource.ResourceWithImportState = &FvCrtrnResource{} func NewFvCrtrnResource() resource.Resource { return &FvCrtrnResource{} } +func (r FvCrtrnResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvCrtrnResource defines the resource implementation. type FvCrtrnResource struct { client *client.Client @@ -399,6 +404,7 @@ func (r *FvCrtrnResource) Create(ctx context.Context, req resource.CreateRequest // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_epg_useg_block_statement with id '%s'", data.Id.ValueString())) } @@ -423,6 +429,7 @@ func (r *FvCrtrnResource) Read(ctx context.Context, req resource.ReadRequest, re resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_epg_useg_block_statement with id '%s'", data.Id.ValueString())) @@ -465,6 +472,7 @@ func (r *FvCrtrnResource) Update(ctx context.Context, req resource.UpdateRequest // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_epg_useg_block_statement with id '%s'", data.Id.ValueString())) } @@ -493,10 +501,11 @@ func (r *FvCrtrnResource) Delete(ctx context.Context, req resource.DeleteRequest func (r *FvCrtrnResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_epg_useg_block_statement") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvCrtrnResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_epg_useg_block_statement with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_epg_useg_block_statement") @@ -505,11 +514,17 @@ func (r *FvCrtrnResource) ImportState(ctx context.Context, req resource.ImportSt func getAndSetFvCrtrnAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvCrtrnResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvCrtrn,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvCrtrnResourceModel() - if diags.HasError() { return } + + setFvCrtrnAttributes(ctx, diags, data, requestData) +} + +func setFvCrtrnAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvCrtrnResourceModel, requestData *container.Container) { + + readData := getEmptyFvCrtrnResourceModel() + if requestData.Search("imdata").Search("fvCrtrn").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvCrtrn").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_epg_useg_dns_attribute.go b/internal/provider/resource_aci_epg_useg_dns_attribute.go index 948503f7d..c098d8139 100644 --- a/internal/provider/resource_aci_epg_useg_dns_attribute.go +++ b/internal/provider/resource_aci_epg_useg_dns_attribute.go @@ -27,12 +27,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvDnsAttrResource{} +var _ resource.ResourceWithIdentity = &FvDnsAttrResource{} var _ resource.ResourceWithImportState = &FvDnsAttrResource{} func NewFvDnsAttrResource() resource.Resource { return &FvDnsAttrResource{} } +func (r FvDnsAttrResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvDnsAttrResource defines the resource implementation. type FvDnsAttrResource struct { client *client.Client @@ -373,6 +378,7 @@ func (r *FvDnsAttrResource) Create(ctx context.Context, req resource.CreateReque // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_epg_useg_dns_attribute with id '%s'", data.Id.ValueString())) } @@ -397,6 +403,7 @@ func (r *FvDnsAttrResource) Read(ctx context.Context, req resource.ReadRequest, resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_epg_useg_dns_attribute with id '%s'", data.Id.ValueString())) @@ -439,6 +446,7 @@ func (r *FvDnsAttrResource) Update(ctx context.Context, req resource.UpdateReque // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_epg_useg_dns_attribute with id '%s'", data.Id.ValueString())) } @@ -467,10 +475,11 @@ func (r *FvDnsAttrResource) Delete(ctx context.Context, req resource.DeleteReque func (r *FvDnsAttrResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_epg_useg_dns_attribute") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvDnsAttrResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_epg_useg_dns_attribute with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_epg_useg_dns_attribute") @@ -479,11 +488,17 @@ func (r *FvDnsAttrResource) ImportState(ctx context.Context, req resource.Import func getAndSetFvDnsAttrAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvDnsAttrResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvDnsAttr,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvDnsAttrResourceModel() - if diags.HasError() { return } + + setFvDnsAttrAttributes(ctx, diags, data, requestData) +} + +func setFvDnsAttrAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvDnsAttrResourceModel, requestData *container.Container) { + + readData := getEmptyFvDnsAttrResourceModel() + if requestData.Search("imdata").Search("fvDnsAttr").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvDnsAttr").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_epg_useg_ip_attribute.go b/internal/provider/resource_aci_epg_useg_ip_attribute.go index 57572e7d0..8bfab9cde 100644 --- a/internal/provider/resource_aci_epg_useg_ip_attribute.go +++ b/internal/provider/resource_aci_epg_useg_ip_attribute.go @@ -29,12 +29,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvIpAttrResource{} +var _ resource.ResourceWithIdentity = &FvIpAttrResource{} var _ resource.ResourceWithImportState = &FvIpAttrResource{} func NewFvIpAttrResource() resource.Resource { return &FvIpAttrResource{} } +func (r FvIpAttrResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvIpAttrResource defines the resource implementation. type FvIpAttrResource struct { client *client.Client @@ -388,6 +393,7 @@ func (r *FvIpAttrResource) Create(ctx context.Context, req resource.CreateReques // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_epg_useg_ip_attribute with id '%s'", data.Id.ValueString())) } @@ -412,6 +418,7 @@ func (r *FvIpAttrResource) Read(ctx context.Context, req resource.ReadRequest, r resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_epg_useg_ip_attribute with id '%s'", data.Id.ValueString())) @@ -454,6 +461,7 @@ func (r *FvIpAttrResource) Update(ctx context.Context, req resource.UpdateReques // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_epg_useg_ip_attribute with id '%s'", data.Id.ValueString())) } @@ -482,10 +490,11 @@ func (r *FvIpAttrResource) Delete(ctx context.Context, req resource.DeleteReques func (r *FvIpAttrResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_epg_useg_ip_attribute") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvIpAttrResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_epg_useg_ip_attribute with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_epg_useg_ip_attribute") @@ -494,11 +503,17 @@ func (r *FvIpAttrResource) ImportState(ctx context.Context, req resource.ImportS func getAndSetFvIpAttrAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvIpAttrResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvIpAttr,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvIpAttrResourceModel() - if diags.HasError() { return } + + setFvIpAttrAttributes(ctx, diags, data, requestData) +} + +func setFvIpAttrAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvIpAttrResourceModel, requestData *container.Container) { + + readData := getEmptyFvIpAttrResourceModel() + if requestData.Search("imdata").Search("fvIpAttr").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvIpAttr").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_epg_useg_mac_attribute.go b/internal/provider/resource_aci_epg_useg_mac_attribute.go index 6972a78b2..a724392ae 100644 --- a/internal/provider/resource_aci_epg_useg_mac_attribute.go +++ b/internal/provider/resource_aci_epg_useg_mac_attribute.go @@ -27,12 +27,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvMacAttrResource{} +var _ resource.ResourceWithIdentity = &FvMacAttrResource{} var _ resource.ResourceWithImportState = &FvMacAttrResource{} func NewFvMacAttrResource() resource.Resource { return &FvMacAttrResource{} } +func (r FvMacAttrResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvMacAttrResource defines the resource implementation. type FvMacAttrResource struct { client *client.Client @@ -372,6 +377,7 @@ func (r *FvMacAttrResource) Create(ctx context.Context, req resource.CreateReque // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_epg_useg_mac_attribute with id '%s'", data.Id.ValueString())) } @@ -396,6 +402,7 @@ func (r *FvMacAttrResource) Read(ctx context.Context, req resource.ReadRequest, resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_epg_useg_mac_attribute with id '%s'", data.Id.ValueString())) @@ -438,6 +445,7 @@ func (r *FvMacAttrResource) Update(ctx context.Context, req resource.UpdateReque // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_epg_useg_mac_attribute with id '%s'", data.Id.ValueString())) } @@ -466,10 +474,11 @@ func (r *FvMacAttrResource) Delete(ctx context.Context, req resource.DeleteReque func (r *FvMacAttrResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_epg_useg_mac_attribute") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvMacAttrResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_epg_useg_mac_attribute with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_epg_useg_mac_attribute") @@ -478,11 +487,17 @@ func (r *FvMacAttrResource) ImportState(ctx context.Context, req resource.Import func getAndSetFvMacAttrAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvMacAttrResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvMacAttr,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvMacAttrResourceModel() - if diags.HasError() { return } + + setFvMacAttrAttributes(ctx, diags, data, requestData) +} + +func setFvMacAttrAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvMacAttrResourceModel, requestData *container.Container) { + + readData := getEmptyFvMacAttrResourceModel() + if requestData.Search("imdata").Search("fvMacAttr").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvMacAttr").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_epg_useg_sub_block_statement.go b/internal/provider/resource_aci_epg_useg_sub_block_statement.go index 56ce7cc0a..711976ebd 100644 --- a/internal/provider/resource_aci_epg_useg_sub_block_statement.go +++ b/internal/provider/resource_aci_epg_useg_sub_block_statement.go @@ -29,12 +29,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvSCrtrnResource{} +var _ resource.ResourceWithIdentity = &FvSCrtrnResource{} var _ resource.ResourceWithImportState = &FvSCrtrnResource{} func NewFvSCrtrnResource() resource.Resource { return &FvSCrtrnResource{} } +func (r FvSCrtrnResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvSCrtrnResource defines the resource implementation. type FvSCrtrnResource struct { client *client.Client @@ -378,6 +383,7 @@ func (r *FvSCrtrnResource) Create(ctx context.Context, req resource.CreateReques // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_epg_useg_sub_block_statement with id '%s'", data.Id.ValueString())) } @@ -402,6 +408,7 @@ func (r *FvSCrtrnResource) Read(ctx context.Context, req resource.ReadRequest, r resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_epg_useg_sub_block_statement with id '%s'", data.Id.ValueString())) @@ -444,6 +451,7 @@ func (r *FvSCrtrnResource) Update(ctx context.Context, req resource.UpdateReques // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_epg_useg_sub_block_statement with id '%s'", data.Id.ValueString())) } @@ -472,10 +480,11 @@ func (r *FvSCrtrnResource) Delete(ctx context.Context, req resource.DeleteReques func (r *FvSCrtrnResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_epg_useg_sub_block_statement") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvSCrtrnResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_epg_useg_sub_block_statement with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_epg_useg_sub_block_statement") @@ -484,11 +493,17 @@ func (r *FvSCrtrnResource) ImportState(ctx context.Context, req resource.ImportS func getAndSetFvSCrtrnAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvSCrtrnResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvSCrtrn,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvSCrtrnResourceModel() - if diags.HasError() { return } + + setFvSCrtrnAttributes(ctx, diags, data, requestData) +} + +func setFvSCrtrnAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvSCrtrnResourceModel, requestData *container.Container) { + + readData := getEmptyFvSCrtrnResourceModel() + if requestData.Search("imdata").Search("fvSCrtrn").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvSCrtrn").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_epg_useg_vm_attribute.go b/internal/provider/resource_aci_epg_useg_vm_attribute.go index 28b1da57b..9ba2b4e34 100644 --- a/internal/provider/resource_aci_epg_useg_vm_attribute.go +++ b/internal/provider/resource_aci_epg_useg_vm_attribute.go @@ -29,12 +29,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvVmAttrResource{} +var _ resource.ResourceWithIdentity = &FvVmAttrResource{} var _ resource.ResourceWithImportState = &FvVmAttrResource{} func NewFvVmAttrResource() resource.Resource { return &FvVmAttrResource{} } +func (r FvVmAttrResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvVmAttrResource defines the resource implementation. type FvVmAttrResource struct { client *client.Client @@ -424,6 +429,7 @@ func (r *FvVmAttrResource) Create(ctx context.Context, req resource.CreateReques // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_epg_useg_vm_attribute with id '%s'", data.Id.ValueString())) } @@ -448,6 +454,7 @@ func (r *FvVmAttrResource) Read(ctx context.Context, req resource.ReadRequest, r resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_epg_useg_vm_attribute with id '%s'", data.Id.ValueString())) @@ -490,6 +497,7 @@ func (r *FvVmAttrResource) Update(ctx context.Context, req resource.UpdateReques // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_epg_useg_vm_attribute with id '%s'", data.Id.ValueString())) } @@ -518,10 +526,11 @@ func (r *FvVmAttrResource) Delete(ctx context.Context, req resource.DeleteReques func (r *FvVmAttrResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_epg_useg_vm_attribute") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvVmAttrResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_epg_useg_vm_attribute with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_epg_useg_vm_attribute") @@ -530,11 +539,17 @@ func (r *FvVmAttrResource) ImportState(ctx context.Context, req resource.ImportS func getAndSetFvVmAttrAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvVmAttrResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvVmAttr,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvVmAttrResourceModel() - if diags.HasError() { return } + + setFvVmAttrAttributes(ctx, diags, data, requestData) +} + +func setFvVmAttrAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvVmAttrResourceModel, requestData *container.Container) { + + readData := getEmptyFvVmAttrResourceModel() + if requestData.Search("imdata").Search("fvVmAttr").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvVmAttr").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_external_epg.go b/internal/provider/resource_aci_external_epg.go index 9ade256f5..9b56674ea 100644 --- a/internal/provider/resource_aci_external_epg.go +++ b/internal/provider/resource_aci_external_epg.go @@ -32,12 +32,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &L3extInstPResource{} +var _ resource.ResourceWithIdentity = &L3extInstPResource{} var _ resource.ResourceWithImportState = &L3extInstPResource{} func NewL3extInstPResource() resource.Resource { return &L3extInstPResource{} } +func (r L3extInstPResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // L3extInstPResource defines the resource implementation. type L3extInstPResource struct { client *client.Client @@ -2307,6 +2312,7 @@ func (r *L3extInstPResource) Create(ctx context.Context, req resource.CreateRequ // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_external_epg with id '%s'", data.Id.ValueString())) } @@ -2331,6 +2337,7 @@ func (r *L3extInstPResource) Read(ctx context.Context, req resource.ReadRequest, resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_external_epg with id '%s'", data.Id.ValueString())) @@ -2403,6 +2410,7 @@ func (r *L3extInstPResource) Update(ctx context.Context, req resource.UpdateRequ // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_external_epg with id '%s'", data.Id.ValueString())) } @@ -2431,10 +2439,11 @@ func (r *L3extInstPResource) Delete(ctx context.Context, req resource.DeleteRequ func (r *L3extInstPResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_external_epg") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *L3extInstPResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_external_epg with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_external_epg") @@ -2443,11 +2452,17 @@ func (r *L3extInstPResource) ImportState(ctx context.Context, req resource.Impor func getAndSetL3extInstPAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *L3extInstPResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "l3extInstP,fvRsCons,fvRsConsIf,fvRsCustQosPol,fvRsIntraEpg,fvRsProtBy,fvRsProv,fvRsSecInherited,l3extRsInstPToProfile,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyL3extInstPResourceModel() - if diags.HasError() { return } + + setL3extInstPAttributes(ctx, diags, data, requestData) +} + +func setL3extInstPAttributes(ctx context.Context, diags *diag.Diagnostics, data *L3extInstPResourceModel, requestData *container.Container) { + + readData := getEmptyL3extInstPResourceModel() + if requestData.Search("imdata").Search("l3extInstP").Data() != nil { classReadInfo := requestData.Search("imdata").Search("l3extInstP").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_external_management_network_instance_profile.go b/internal/provider/resource_aci_external_management_network_instance_profile.go index ceca19639..fac59eeb7 100644 --- a/internal/provider/resource_aci_external_management_network_instance_profile.go +++ b/internal/provider/resource_aci_external_management_network_instance_profile.go @@ -32,12 +32,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &MgmtInstPResource{} +var _ resource.ResourceWithIdentity = &MgmtInstPResource{} var _ resource.ResourceWithImportState = &MgmtInstPResource{} func NewMgmtInstPResource() resource.Resource { return &MgmtInstPResource{} } +func (r MgmtInstPResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // MgmtInstPResource defines the resource implementation. type MgmtInstPResource struct { client *client.Client @@ -573,6 +578,7 @@ func (r *MgmtInstPResource) Create(ctx context.Context, req resource.CreateReque // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_external_management_network_instance_profile with id '%s'", data.Id.ValueString())) } @@ -597,6 +603,7 @@ func (r *MgmtInstPResource) Read(ctx context.Context, req resource.ReadRequest, resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_external_management_network_instance_profile with id '%s'", data.Id.ValueString())) @@ -642,6 +649,7 @@ func (r *MgmtInstPResource) Update(ctx context.Context, req resource.UpdateReque // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_external_management_network_instance_profile with id '%s'", data.Id.ValueString())) } @@ -670,10 +678,11 @@ func (r *MgmtInstPResource) Delete(ctx context.Context, req resource.DeleteReque func (r *MgmtInstPResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_external_management_network_instance_profile") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *MgmtInstPResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_external_management_network_instance_profile with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_external_management_network_instance_profile") @@ -682,11 +691,17 @@ func (r *MgmtInstPResource) ImportState(ctx context.Context, req resource.Import func getAndSetMgmtInstPAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *MgmtInstPResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "mgmtInstP,mgmtRsOoBCons,tagAnnotation,tagTag,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyMgmtInstPResourceModel() - if diags.HasError() { return } + + setMgmtInstPAttributes(ctx, diags, data, requestData) +} + +func setMgmtInstPAttributes(ctx context.Context, diags *diag.Diagnostics, data *MgmtInstPResourceModel, requestData *container.Container) { + + readData := getEmptyMgmtInstPResourceModel() + if requestData.Search("imdata").Search("mgmtInstP").Data() != nil { classReadInfo := requestData.Search("imdata").Search("mgmtInstP").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_external_management_network_subnet.go b/internal/provider/resource_aci_external_management_network_subnet.go index 555309aff..42c838671 100644 --- a/internal/provider/resource_aci_external_management_network_subnet.go +++ b/internal/provider/resource_aci_external_management_network_subnet.go @@ -27,12 +27,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &MgmtSubnetResource{} +var _ resource.ResourceWithIdentity = &MgmtSubnetResource{} var _ resource.ResourceWithImportState = &MgmtSubnetResource{} func NewMgmtSubnetResource() resource.Resource { return &MgmtSubnetResource{} } +func (r MgmtSubnetResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // MgmtSubnetResource defines the resource implementation. type MgmtSubnetResource struct { client *client.Client @@ -351,6 +356,7 @@ func (r *MgmtSubnetResource) Create(ctx context.Context, req resource.CreateRequ // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_external_management_network_subnet with id '%s'", data.Id.ValueString())) } @@ -375,6 +381,7 @@ func (r *MgmtSubnetResource) Read(ctx context.Context, req resource.ReadRequest, resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_external_management_network_subnet with id '%s'", data.Id.ValueString())) @@ -417,6 +424,7 @@ func (r *MgmtSubnetResource) Update(ctx context.Context, req resource.UpdateRequ // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_external_management_network_subnet with id '%s'", data.Id.ValueString())) } @@ -445,10 +453,11 @@ func (r *MgmtSubnetResource) Delete(ctx context.Context, req resource.DeleteRequ func (r *MgmtSubnetResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_external_management_network_subnet") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *MgmtSubnetResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_external_management_network_subnet with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_external_management_network_subnet") @@ -457,11 +466,17 @@ func (r *MgmtSubnetResource) ImportState(ctx context.Context, req resource.Impor func getAndSetMgmtSubnetAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *MgmtSubnetResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "mgmtSubnet,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyMgmtSubnetResourceModel() - if diags.HasError() { return } + + setMgmtSubnetAttributes(ctx, diags, data, requestData) +} + +func setMgmtSubnetAttributes(ctx context.Context, diags *diag.Diagnostics, data *MgmtSubnetResourceModel, requestData *container.Container) { + + readData := getEmptyMgmtSubnetResourceModel() + if requestData.Search("imdata").Search("mgmtSubnet").Data() != nil { classReadInfo := requestData.Search("imdata").Search("mgmtSubnet").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_fabric_external_connection_policy.go b/internal/provider/resource_aci_fabric_external_connection_policy.go index ac4c8a383..c2585b3c9 100644 --- a/internal/provider/resource_aci_fabric_external_connection_policy.go +++ b/internal/provider/resource_aci_fabric_external_connection_policy.go @@ -30,12 +30,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvFabricExtConnPResource{} +var _ resource.ResourceWithIdentity = &FvFabricExtConnPResource{} var _ resource.ResourceWithImportState = &FvFabricExtConnPResource{} func NewFvFabricExtConnPResource() resource.Resource { return &FvFabricExtConnPResource{} } +func (r FvFabricExtConnPResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvFabricExtConnPResource defines the resource implementation. type FvFabricExtConnPResource struct { client *client.Client @@ -645,6 +650,7 @@ func (r *FvFabricExtConnPResource) Create(ctx context.Context, req resource.Crea // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_fabric_external_connection_policy with id '%s'", data.Id.ValueString())) } @@ -669,6 +675,7 @@ func (r *FvFabricExtConnPResource) Read(ctx context.Context, req resource.ReadRe resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_fabric_external_connection_policy with id '%s'", data.Id.ValueString())) @@ -720,6 +727,7 @@ func (r *FvFabricExtConnPResource) Update(ctx context.Context, req resource.Upda // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_fabric_external_connection_policy with id '%s'", data.Id.ValueString())) } @@ -748,10 +756,11 @@ func (r *FvFabricExtConnPResource) Delete(ctx context.Context, req resource.Dele func (r *FvFabricExtConnPResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_fabric_external_connection_policy") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvFabricExtConnPResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_fabric_external_connection_policy with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_fabric_external_connection_policy") @@ -760,11 +769,17 @@ func (r *FvFabricExtConnPResource) ImportState(ctx context.Context, req resource func getAndSetFvFabricExtConnPAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvFabricExtConnPResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvFabricExtConnP,fvPeeringP,tagAnnotation,tagTag,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvFabricExtConnPResourceModel() - if diags.HasError() { return } + + setFvFabricExtConnPAttributes(ctx, diags, data, requestData) +} + +func setFvFabricExtConnPAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvFabricExtConnPResourceModel, requestData *container.Container) { + + readData := getEmptyFvFabricExtConnPResourceModel() + if requestData.Search("imdata").Search("fvFabricExtConnP").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvFabricExtConnP").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_fex_profile.go b/internal/provider/resource_aci_fex_profile.go index 20ee3421f..2526d2e63 100644 --- a/internal/provider/resource_aci_fex_profile.go +++ b/internal/provider/resource_aci_fex_profile.go @@ -28,12 +28,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &InfraFexPResource{} +var _ resource.ResourceWithIdentity = &InfraFexPResource{} var _ resource.ResourceWithImportState = &InfraFexPResource{} func NewInfraFexPResource() resource.Resource { return &InfraFexPResource{} } +func (r InfraFexPResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // InfraFexPResource defines the resource implementation. type InfraFexPResource struct { client *client.Client @@ -354,6 +359,7 @@ func (r *InfraFexPResource) Create(ctx context.Context, req resource.CreateReque // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_fex_profile with id '%s'", data.Id.ValueString())) } @@ -378,6 +384,7 @@ func (r *InfraFexPResource) Read(ctx context.Context, req resource.ReadRequest, resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_fex_profile with id '%s'", data.Id.ValueString())) @@ -420,6 +427,7 @@ func (r *InfraFexPResource) Update(ctx context.Context, req resource.UpdateReque // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_fex_profile with id '%s'", data.Id.ValueString())) } @@ -448,10 +456,11 @@ func (r *InfraFexPResource) Delete(ctx context.Context, req resource.DeleteReque func (r *InfraFexPResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_fex_profile") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *InfraFexPResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_fex_profile with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_fex_profile") @@ -460,11 +469,17 @@ func (r *InfraFexPResource) ImportState(ctx context.Context, req resource.Import func getAndSetInfraFexPAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *InfraFexPResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "infraFexP,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyInfraFexPResourceModel() - if diags.HasError() { return } + + setInfraFexPAttributes(ctx, diags, data, requestData) +} + +func setInfraFexPAttributes(ctx context.Context, diags *diag.Diagnostics, data *InfraFexPResourceModel, requestData *container.Container) { + + readData := getEmptyInfraFexPResourceModel() + if requestData.Search("imdata").Search("infraFexP").Data() != nil { classReadInfo := requestData.Search("imdata").Search("infraFexP").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_first_hop_security_policy.go b/internal/provider/resource_aci_first_hop_security_policy.go index a4a5065d1..02421dc81 100644 --- a/internal/provider/resource_aci_first_hop_security_policy.go +++ b/internal/provider/resource_aci_first_hop_security_policy.go @@ -30,12 +30,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FhsBDPolResource{} +var _ resource.ResourceWithIdentity = &FhsBDPolResource{} var _ resource.ResourceWithImportState = &FhsBDPolResource{} func NewFhsBDPolResource() resource.Resource { return &FhsBDPolResource{} } +func (r FhsBDPolResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FhsBDPolResource defines the resource implementation. type FhsBDPolResource struct { client *client.Client @@ -724,6 +729,7 @@ func (r *FhsBDPolResource) Create(ctx context.Context, req resource.CreateReques // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_first_hop_security_policy with id '%s'", data.Id.ValueString())) } @@ -748,6 +754,7 @@ func (r *FhsBDPolResource) Read(ctx context.Context, req resource.ReadRequest, r resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_first_hop_security_policy with id '%s'", data.Id.ValueString())) @@ -793,6 +800,7 @@ func (r *FhsBDPolResource) Update(ctx context.Context, req resource.UpdateReques // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_first_hop_security_policy with id '%s'", data.Id.ValueString())) } @@ -821,10 +829,11 @@ func (r *FhsBDPolResource) Delete(ctx context.Context, req resource.DeleteReques func (r *FhsBDPolResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_first_hop_security_policy") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FhsBDPolResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_first_hop_security_policy with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_first_hop_security_policy") @@ -833,11 +842,17 @@ func (r *FhsBDPolResource) ImportState(ctx context.Context, req resource.ImportS func getAndSetFhsBDPolAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FhsBDPolResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fhsBDPol,fhsRaGuardPol,tagAnnotation,tagTag,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFhsBDPolResourceModel() - if diags.HasError() { return } + + setFhsBDPolAttributes(ctx, diags, data, requestData) +} + +func setFhsBDPolAttributes(ctx context.Context, diags *diag.Diagnostics, data *FhsBDPolResourceModel, requestData *container.Container) { + + readData := getEmptyFhsBDPolResourceModel() + if requestData.Search("imdata").Search("fhsBDPol").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fhsBDPol").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_igmp_snooping_policy.go b/internal/provider/resource_aci_igmp_snooping_policy.go index 0fad704cb..55697d47c 100644 --- a/internal/provider/resource_aci_igmp_snooping_policy.go +++ b/internal/provider/resource_aci_igmp_snooping_policy.go @@ -31,12 +31,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &IgmpSnoopPolResource{} +var _ resource.ResourceWithIdentity = &IgmpSnoopPolResource{} var _ resource.ResourceWithImportState = &IgmpSnoopPolResource{} func NewIgmpSnoopPolResource() resource.Resource { return &IgmpSnoopPolResource{} } +func (r IgmpSnoopPolResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // IgmpSnoopPolResource defines the resource implementation. type IgmpSnoopPolResource struct { client *client.Client @@ -467,6 +472,7 @@ func (r *IgmpSnoopPolResource) Create(ctx context.Context, req resource.CreateRe // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_igmp_snooping_policy with id '%s'", data.Id.ValueString())) } @@ -491,6 +497,7 @@ func (r *IgmpSnoopPolResource) Read(ctx context.Context, req resource.ReadReques resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_igmp_snooping_policy with id '%s'", data.Id.ValueString())) @@ -533,6 +540,7 @@ func (r *IgmpSnoopPolResource) Update(ctx context.Context, req resource.UpdateRe // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_igmp_snooping_policy with id '%s'", data.Id.ValueString())) } @@ -561,10 +569,11 @@ func (r *IgmpSnoopPolResource) Delete(ctx context.Context, req resource.DeleteRe func (r *IgmpSnoopPolResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_igmp_snooping_policy") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *IgmpSnoopPolResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_igmp_snooping_policy with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_igmp_snooping_policy") @@ -573,11 +582,17 @@ func (r *IgmpSnoopPolResource) ImportState(ctx context.Context, req resource.Imp func getAndSetIgmpSnoopPolAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *IgmpSnoopPolResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "igmpSnoopPol,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyIgmpSnoopPolResourceModel() - if diags.HasError() { return } + + setIgmpSnoopPolAttributes(ctx, diags, data, requestData) +} + +func setIgmpSnoopPolAttributes(ctx context.Context, diags *diag.Diagnostics, data *IgmpSnoopPolResourceModel, requestData *container.Container) { + + readData := getEmptyIgmpSnoopPolResourceModel() + if requestData.Search("imdata").Search("igmpSnoopPol").Data() != nil { classReadInfo := requestData.Search("imdata").Search("igmpSnoopPol").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_imported_logical_device.go b/internal/provider/resource_aci_imported_logical_device.go index f938eb98d..b2988e22e 100644 --- a/internal/provider/resource_aci_imported_logical_device.go +++ b/internal/provider/resource_aci_imported_logical_device.go @@ -27,12 +27,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &VnsLDevIfResource{} +var _ resource.ResourceWithIdentity = &VnsLDevIfResource{} var _ resource.ResourceWithImportState = &VnsLDevIfResource{} func NewVnsLDevIfResource() resource.Resource { return &VnsLDevIfResource{} } +func (r VnsLDevIfResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // VnsLDevIfResource defines the resource implementation. type VnsLDevIfResource struct { client *client.Client @@ -352,6 +357,7 @@ func (r *VnsLDevIfResource) Create(ctx context.Context, req resource.CreateReque // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_imported_logical_device with id '%s'", data.Id.ValueString())) } @@ -376,6 +382,7 @@ func (r *VnsLDevIfResource) Read(ctx context.Context, req resource.ReadRequest, resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_imported_logical_device with id '%s'", data.Id.ValueString())) @@ -418,6 +425,7 @@ func (r *VnsLDevIfResource) Update(ctx context.Context, req resource.UpdateReque // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_imported_logical_device with id '%s'", data.Id.ValueString())) } @@ -446,10 +454,11 @@ func (r *VnsLDevIfResource) Delete(ctx context.Context, req resource.DeleteReque func (r *VnsLDevIfResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_imported_logical_device") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *VnsLDevIfResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_imported_logical_device with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_imported_logical_device") @@ -458,11 +467,17 @@ func (r *VnsLDevIfResource) ImportState(ctx context.Context, req resource.Import func getAndSetVnsLDevIfAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *VnsLDevIfResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "vnsLDevIf,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyVnsLDevIfResourceModel() - if diags.HasError() { return } + + setVnsLDevIfAttributes(ctx, diags, data, requestData) +} + +func setVnsLDevIfAttributes(ctx context.Context, diags *diag.Diagnostics, data *VnsLDevIfResourceModel, requestData *container.Container) { + + readData := getEmptyVnsLDevIfResourceModel() + if requestData.Search("imdata").Search("vnsLDevIf").Data() != nil { classReadInfo := requestData.Search("imdata").Search("vnsLDevIf").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_ip_sla_track_list.go b/internal/provider/resource_aci_ip_sla_track_list.go index 1ca4c5713..3a50d7000 100644 --- a/internal/provider/resource_aci_ip_sla_track_list.go +++ b/internal/provider/resource_aci_ip_sla_track_list.go @@ -29,12 +29,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvTrackListResource{} +var _ resource.ResourceWithIdentity = &FvTrackListResource{} var _ resource.ResourceWithImportState = &FvTrackListResource{} func NewFvTrackListResource() resource.Resource { return &FvTrackListResource{} } +func (r FvTrackListResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvTrackListResource defines the resource implementation. type FvTrackListResource struct { client *client.Client @@ -636,6 +641,7 @@ func (r *FvTrackListResource) Create(ctx context.Context, req resource.CreateReq // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_ip_sla_track_list with id '%s'", data.Id.ValueString())) } @@ -660,6 +666,7 @@ func (r *FvTrackListResource) Read(ctx context.Context, req resource.ReadRequest resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_ip_sla_track_list with id '%s'", data.Id.ValueString())) @@ -705,6 +712,7 @@ func (r *FvTrackListResource) Update(ctx context.Context, req resource.UpdateReq // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_ip_sla_track_list with id '%s'", data.Id.ValueString())) } @@ -733,10 +741,11 @@ func (r *FvTrackListResource) Delete(ctx context.Context, req resource.DeleteReq func (r *FvTrackListResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_ip_sla_track_list") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvTrackListResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_ip_sla_track_list with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_ip_sla_track_list") @@ -745,11 +754,17 @@ func (r *FvTrackListResource) ImportState(ctx context.Context, req resource.Impo func getAndSetFvTrackListAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvTrackListResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvTrackList,fvRsOtmListMember,tagAnnotation,tagTag,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvTrackListResourceModel() - if diags.HasError() { return } + + setFvTrackListAttributes(ctx, diags, data, requestData) +} + +func setFvTrackListAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvTrackListResourceModel, requestData *container.Container) { + + readData := getEmptyFvTrackListResourceModel() + if requestData.Search("imdata").Search("fvTrackList").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvTrackList").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_ip_sla_track_member.go b/internal/provider/resource_aci_ip_sla_track_member.go index a42233e5a..b2151302e 100644 --- a/internal/provider/resource_aci_ip_sla_track_member.go +++ b/internal/provider/resource_aci_ip_sla_track_member.go @@ -28,12 +28,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvTrackMemberResource{} +var _ resource.ResourceWithIdentity = &FvTrackMemberResource{} var _ resource.ResourceWithImportState = &FvTrackMemberResource{} func NewFvTrackMemberResource() resource.Resource { return &FvTrackMemberResource{} } +func (r FvTrackMemberResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvTrackMemberResource defines the resource implementation. type FvTrackMemberResource struct { client *client.Client @@ -551,6 +556,7 @@ func (r *FvTrackMemberResource) Create(ctx context.Context, req resource.CreateR // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_ip_sla_track_member with id '%s'", data.Id.ValueString())) } @@ -575,6 +581,7 @@ func (r *FvTrackMemberResource) Read(ctx context.Context, req resource.ReadReque resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_ip_sla_track_member with id '%s'", data.Id.ValueString())) @@ -626,6 +633,7 @@ func (r *FvTrackMemberResource) Update(ctx context.Context, req resource.UpdateR // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_ip_sla_track_member with id '%s'", data.Id.ValueString())) } @@ -654,10 +662,11 @@ func (r *FvTrackMemberResource) Delete(ctx context.Context, req resource.DeleteR func (r *FvTrackMemberResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_ip_sla_track_member") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvTrackMemberResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_ip_sla_track_member with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_ip_sla_track_member") @@ -666,11 +675,17 @@ func (r *FvTrackMemberResource) ImportState(ctx context.Context, req resource.Im func getAndSetFvTrackMemberAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvTrackMemberResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvTrackMember,fvRsIpslaMonPol,tagAnnotation,tagTag,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvTrackMemberResourceModel() - if diags.HasError() { return } + + setFvTrackMemberAttributes(ctx, diags, data, requestData) +} + +func setFvTrackMemberAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvTrackMemberResourceModel, requestData *container.Container) { + + readData := getEmptyFvTrackMemberResourceModel() + if requestData.Search("imdata").Search("fvTrackMember").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvTrackMember").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_key_ring.go b/internal/provider/resource_aci_key_ring.go index 36633be26..09b2eed3d 100644 --- a/internal/provider/resource_aci_key_ring.go +++ b/internal/provider/resource_aci_key_ring.go @@ -30,12 +30,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &PkiKeyRingResource{} +var _ resource.ResourceWithIdentity = &PkiKeyRingResource{} var _ resource.ResourceWithImportState = &PkiKeyRingResource{} func NewPkiKeyRingResource() resource.Resource { return &PkiKeyRingResource{} } +func (r PkiKeyRingResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // PkiKeyRingResource defines the resource implementation. type PkiKeyRingResource struct { client *client.Client @@ -479,6 +484,7 @@ func (r *PkiKeyRingResource) Create(ctx context.Context, req resource.CreateRequ // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_key_ring with id '%s'", data.Id.ValueString())) } @@ -503,6 +509,7 @@ func (r *PkiKeyRingResource) Read(ctx context.Context, req resource.ReadRequest, resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_key_ring with id '%s'", data.Id.ValueString())) @@ -557,6 +564,7 @@ func (r *PkiKeyRingResource) Update(ctx context.Context, req resource.UpdateRequ // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_key_ring with id '%s'", data.Id.ValueString())) } @@ -585,10 +593,11 @@ func (r *PkiKeyRingResource) Delete(ctx context.Context, req resource.DeleteRequ func (r *PkiKeyRingResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_key_ring") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *PkiKeyRingResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_key_ring with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_key_ring") @@ -597,11 +606,17 @@ func (r *PkiKeyRingResource) ImportState(ctx context.Context, req resource.Impor func getAndSetPkiKeyRingAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *PkiKeyRingResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "pkiKeyRing,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyPkiKeyRingResourceModel() - if diags.HasError() { return } + + setPkiKeyRingAttributes(ctx, diags, data, requestData) +} + +func setPkiKeyRingAttributes(ctx context.Context, diags *diag.Diagnostics, data *PkiKeyRingResourceModel, requestData *container.Container) { + + readData := getEmptyPkiKeyRingResourceModel() + if requestData.Search("imdata").Search("pkiKeyRing").Data() != nil { classReadInfo := requestData.Search("imdata").Search("pkiKeyRing").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_l3out_consumer_label.go b/internal/provider/resource_aci_l3out_consumer_label.go index 6bb969701..5da81686b 100644 --- a/internal/provider/resource_aci_l3out_consumer_label.go +++ b/internal/provider/resource_aci_l3out_consumer_label.go @@ -29,12 +29,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &L3extConsLblResource{} +var _ resource.ResourceWithIdentity = &L3extConsLblResource{} var _ resource.ResourceWithImportState = &L3extConsLblResource{} func NewL3extConsLblResource() resource.Resource { return &L3extConsLblResource{} } +func (r L3extConsLblResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // L3extConsLblResource defines the resource implementation. type L3extConsLblResource struct { client *client.Client @@ -805,6 +810,7 @@ func (r *L3extConsLblResource) Create(ctx context.Context, req resource.CreateRe // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_l3out_consumer_label with id '%s'", data.Id.ValueString())) } @@ -829,6 +835,7 @@ func (r *L3extConsLblResource) Read(ctx context.Context, req resource.ReadReques resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_l3out_consumer_label with id '%s'", data.Id.ValueString())) @@ -877,6 +884,7 @@ func (r *L3extConsLblResource) Update(ctx context.Context, req resource.UpdateRe // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_l3out_consumer_label with id '%s'", data.Id.ValueString())) } @@ -905,10 +913,11 @@ func (r *L3extConsLblResource) Delete(ctx context.Context, req resource.DeleteRe func (r *L3extConsLblResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_l3out_consumer_label") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *L3extConsLblResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_l3out_consumer_label with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_l3out_consumer_label") @@ -917,11 +926,17 @@ func (r *L3extConsLblResource) ImportState(ctx context.Context, req resource.Imp func getAndSetL3extConsLblAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *L3extConsLblResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "l3extConsLbl,l3extRsLblToInstP,l3extRsLblToProfile,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyL3extConsLblResourceModel() - if diags.HasError() { return } + + setL3extConsLblAttributes(ctx, diags, data, requestData) +} + +func setL3extConsLblAttributes(ctx context.Context, diags *diag.Diagnostics, data *L3extConsLblResourceModel, requestData *container.Container) { + + readData := getEmptyL3extConsLblResourceModel() + if requestData.Search("imdata").Search("l3extConsLbl").Data() != nil { classReadInfo := requestData.Search("imdata").Search("l3extConsLbl").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_l3out_node_sid_profile.go b/internal/provider/resource_aci_l3out_node_sid_profile.go index b778eebc3..5d895dd6e 100644 --- a/internal/provider/resource_aci_l3out_node_sid_profile.go +++ b/internal/provider/resource_aci_l3out_node_sid_profile.go @@ -27,12 +27,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &MplsNodeSidPResource{} +var _ resource.ResourceWithIdentity = &MplsNodeSidPResource{} var _ resource.ResourceWithImportState = &MplsNodeSidPResource{} func NewMplsNodeSidPResource() resource.Resource { return &MplsNodeSidPResource{} } +func (r MplsNodeSidPResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // MplsNodeSidPResource defines the resource implementation. type MplsNodeSidPResource struct { client *client.Client @@ -362,6 +367,7 @@ func (r *MplsNodeSidPResource) Create(ctx context.Context, req resource.CreateRe // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_l3out_node_sid_profile with id '%s'", data.Id.ValueString())) } @@ -386,6 +392,7 @@ func (r *MplsNodeSidPResource) Read(ctx context.Context, req resource.ReadReques resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_l3out_node_sid_profile with id '%s'", data.Id.ValueString())) @@ -428,6 +435,7 @@ func (r *MplsNodeSidPResource) Update(ctx context.Context, req resource.UpdateRe // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_l3out_node_sid_profile with id '%s'", data.Id.ValueString())) } @@ -456,10 +464,11 @@ func (r *MplsNodeSidPResource) Delete(ctx context.Context, req resource.DeleteRe func (r *MplsNodeSidPResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_l3out_node_sid_profile") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *MplsNodeSidPResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_l3out_node_sid_profile with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_l3out_node_sid_profile") @@ -468,11 +477,17 @@ func (r *MplsNodeSidPResource) ImportState(ctx context.Context, req resource.Imp func getAndSetMplsNodeSidPAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *MplsNodeSidPResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "mplsNodeSidP,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyMplsNodeSidPResourceModel() - if diags.HasError() { return } + + setMplsNodeSidPAttributes(ctx, diags, data, requestData) +} + +func setMplsNodeSidPAttributes(ctx context.Context, diags *diag.Diagnostics, data *MplsNodeSidPResourceModel, requestData *container.Container) { + + readData := getEmptyMplsNodeSidPResourceModel() + if requestData.Search("imdata").Search("mplsNodeSidP").Data() != nil { classReadInfo := requestData.Search("imdata").Search("mplsNodeSidP").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_l3out_provider_label.go b/internal/provider/resource_aci_l3out_provider_label.go index f6e28f3c2..cec28b1c8 100644 --- a/internal/provider/resource_aci_l3out_provider_label.go +++ b/internal/provider/resource_aci_l3out_provider_label.go @@ -29,12 +29,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &L3extProvLblResource{} +var _ resource.ResourceWithIdentity = &L3extProvLblResource{} var _ resource.ResourceWithImportState = &L3extProvLblResource{} func NewL3extProvLblResource() resource.Resource { return &L3extProvLblResource{} } +func (r L3extProvLblResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // L3extProvLblResource defines the resource implementation. type L3extProvLblResource struct { client *client.Client @@ -378,6 +383,7 @@ func (r *L3extProvLblResource) Create(ctx context.Context, req resource.CreateRe // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_l3out_provider_label with id '%s'", data.Id.ValueString())) } @@ -402,6 +408,7 @@ func (r *L3extProvLblResource) Read(ctx context.Context, req resource.ReadReques resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_l3out_provider_label with id '%s'", data.Id.ValueString())) @@ -444,6 +451,7 @@ func (r *L3extProvLblResource) Update(ctx context.Context, req resource.UpdateRe // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_l3out_provider_label with id '%s'", data.Id.ValueString())) } @@ -472,10 +480,11 @@ func (r *L3extProvLblResource) Delete(ctx context.Context, req resource.DeleteRe func (r *L3extProvLblResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_l3out_provider_label") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *L3extProvLblResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_l3out_provider_label with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_l3out_provider_label") @@ -484,11 +493,17 @@ func (r *L3extProvLblResource) ImportState(ctx context.Context, req resource.Imp func getAndSetL3extProvLblAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *L3extProvLblResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "l3extProvLbl,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyL3extProvLblResourceModel() - if diags.HasError() { return } + + setL3extProvLblAttributes(ctx, diags, data, requestData) +} + +func setL3extProvLblAttributes(ctx context.Context, diags *diag.Diagnostics, data *L3extProvLblResourceModel, requestData *container.Container) { + + readData := getEmptyL3extProvLblResourceModel() + if requestData.Search("imdata").Search("l3extProvLbl").Data() != nil { classReadInfo := requestData.Search("imdata").Search("l3extProvLbl").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_l3out_redistribute_policy.go b/internal/provider/resource_aci_l3out_redistribute_policy.go index 8ef1123cf..72d3eefe1 100644 --- a/internal/provider/resource_aci_l3out_redistribute_policy.go +++ b/internal/provider/resource_aci_l3out_redistribute_policy.go @@ -29,12 +29,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &L3extRsRedistributePolResource{} +var _ resource.ResourceWithIdentity = &L3extRsRedistributePolResource{} var _ resource.ResourceWithImportState = &L3extRsRedistributePolResource{} func NewL3extRsRedistributePolResource() resource.Resource { return &L3extRsRedistributePolResource{} } +func (r L3extRsRedistributePolResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // L3extRsRedistributePolResource defines the resource implementation. type L3extRsRedistributePolResource struct { client *client.Client @@ -335,6 +340,7 @@ func (r *L3extRsRedistributePolResource) Create(ctx context.Context, req resourc // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_l3out_redistribute_policy with id '%s'", data.Id.ValueString())) } @@ -359,6 +365,7 @@ func (r *L3extRsRedistributePolResource) Read(ctx context.Context, req resource. resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_l3out_redistribute_policy with id '%s'", data.Id.ValueString())) @@ -401,6 +408,7 @@ func (r *L3extRsRedistributePolResource) Update(ctx context.Context, req resourc // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_l3out_redistribute_policy with id '%s'", data.Id.ValueString())) } @@ -429,10 +437,11 @@ func (r *L3extRsRedistributePolResource) Delete(ctx context.Context, req resourc func (r *L3extRsRedistributePolResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_l3out_redistribute_policy") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *L3extRsRedistributePolResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_l3out_redistribute_policy with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_l3out_redistribute_policy") @@ -441,11 +450,17 @@ func (r *L3extRsRedistributePolResource) ImportState(ctx context.Context, req re func getAndSetL3extRsRedistributePolAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *L3extRsRedistributePolResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "l3extRsRedistributePol,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyL3extRsRedistributePolResourceModel() - if diags.HasError() { return } + + setL3extRsRedistributePolAttributes(ctx, diags, data, requestData) +} + +func setL3extRsRedistributePolAttributes(ctx context.Context, diags *diag.Diagnostics, data *L3extRsRedistributePolResourceModel, requestData *container.Container) { + + readData := getEmptyL3extRsRedistributePolResourceModel() + if requestData.Search("imdata").Search("l3extRsRedistributePol").Data() != nil { classReadInfo := requestData.Search("imdata").Search("l3extRsRedistributePol").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_lacp_enhanced_lag_policy.go b/internal/provider/resource_aci_lacp_enhanced_lag_policy.go index 12019abae..fdb0e51d9 100644 --- a/internal/provider/resource_aci_lacp_enhanced_lag_policy.go +++ b/internal/provider/resource_aci_lacp_enhanced_lag_policy.go @@ -29,12 +29,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &LacpEnhancedLagPolResource{} +var _ resource.ResourceWithIdentity = &LacpEnhancedLagPolResource{} var _ resource.ResourceWithImportState = &LacpEnhancedLagPolResource{} func NewLacpEnhancedLagPolResource() resource.Resource { return &LacpEnhancedLagPolResource{} } +func (r LacpEnhancedLagPolResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // LacpEnhancedLagPolResource defines the resource implementation. type LacpEnhancedLagPolResource struct { client *client.Client @@ -370,6 +375,7 @@ func (r *LacpEnhancedLagPolResource) Create(ctx context.Context, req resource.Cr // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_lacp_enhanced_lag_policy with id '%s'", data.Id.ValueString())) } @@ -394,6 +400,7 @@ func (r *LacpEnhancedLagPolResource) Read(ctx context.Context, req resource.Read resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_lacp_enhanced_lag_policy with id '%s'", data.Id.ValueString())) @@ -436,6 +443,7 @@ func (r *LacpEnhancedLagPolResource) Update(ctx context.Context, req resource.Up // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_lacp_enhanced_lag_policy with id '%s'", data.Id.ValueString())) } @@ -464,10 +472,11 @@ func (r *LacpEnhancedLagPolResource) Delete(ctx context.Context, req resource.De func (r *LacpEnhancedLagPolResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_lacp_enhanced_lag_policy") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *LacpEnhancedLagPolResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_lacp_enhanced_lag_policy with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_lacp_enhanced_lag_policy") @@ -476,11 +485,17 @@ func (r *LacpEnhancedLagPolResource) ImportState(ctx context.Context, req resour func getAndSetLacpEnhancedLagPolAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *LacpEnhancedLagPolResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "lacpEnhancedLagPol,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyLacpEnhancedLagPolResourceModel() - if diags.HasError() { return } + + setLacpEnhancedLagPolAttributes(ctx, diags, data, requestData) +} + +func setLacpEnhancedLagPolAttributes(ctx context.Context, diags *diag.Diagnostics, data *LacpEnhancedLagPolResourceModel, requestData *container.Container) { + + readData := getEmptyLacpEnhancedLagPolResourceModel() + if requestData.Search("imdata").Search("lacpEnhancedLagPol").Data() != nil { classReadInfo := requestData.Search("imdata").Search("lacpEnhancedLagPol").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_leaf_interface_profile.go b/internal/provider/resource_aci_leaf_interface_profile.go index ac8f40149..184f50350 100644 --- a/internal/provider/resource_aci_leaf_interface_profile.go +++ b/internal/provider/resource_aci_leaf_interface_profile.go @@ -28,12 +28,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &InfraAccPortPResource{} +var _ resource.ResourceWithIdentity = &InfraAccPortPResource{} var _ resource.ResourceWithImportState = &InfraAccPortPResource{} func NewInfraAccPortPResource() resource.Resource { return &InfraAccPortPResource{} } +func (r InfraAccPortPResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // InfraAccPortPResource defines the resource implementation. type InfraAccPortPResource struct { client *client.Client @@ -354,6 +359,7 @@ func (r *InfraAccPortPResource) Create(ctx context.Context, req resource.CreateR // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_leaf_interface_profile with id '%s'", data.Id.ValueString())) } @@ -378,6 +384,7 @@ func (r *InfraAccPortPResource) Read(ctx context.Context, req resource.ReadReque resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_leaf_interface_profile with id '%s'", data.Id.ValueString())) @@ -420,6 +427,7 @@ func (r *InfraAccPortPResource) Update(ctx context.Context, req resource.UpdateR // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_leaf_interface_profile with id '%s'", data.Id.ValueString())) } @@ -448,10 +456,11 @@ func (r *InfraAccPortPResource) Delete(ctx context.Context, req resource.DeleteR func (r *InfraAccPortPResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_leaf_interface_profile") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *InfraAccPortPResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_leaf_interface_profile with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_leaf_interface_profile") @@ -460,11 +469,17 @@ func (r *InfraAccPortPResource) ImportState(ctx context.Context, req resource.Im func getAndSetInfraAccPortPAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *InfraAccPortPResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "infraAccPortP,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyInfraAccPortPResourceModel() - if diags.HasError() { return } + + setInfraAccPortPAttributes(ctx, diags, data, requestData) +} + +func setInfraAccPortPAttributes(ctx context.Context, diags *diag.Diagnostics, data *InfraAccPortPResourceModel, requestData *container.Container) { + + readData := getEmptyInfraAccPortPResourceModel() + if requestData.Search("imdata").Search("infraAccPortP").Data() != nil { classReadInfo := requestData.Search("imdata").Search("infraAccPortP").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_management_access_policy.go b/internal/provider/resource_aci_management_access_policy.go index 2e624e01d..26c4f7038 100644 --- a/internal/provider/resource_aci_management_access_policy.go +++ b/internal/provider/resource_aci_management_access_policy.go @@ -32,12 +32,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &CommPolResource{} +var _ resource.ResourceWithIdentity = &CommPolResource{} var _ resource.ResourceWithImportState = &CommPolResource{} func NewCommPolResource() resource.Resource { return &CommPolResource{} } +func (r CommPolResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // CommPolResource defines the resource implementation. type CommPolResource struct { client *client.Client @@ -2306,6 +2311,7 @@ func (r *CommPolResource) Create(ctx context.Context, req resource.CreateRequest // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_management_access_policy with id '%s'", data.Id.ValueString())) } @@ -2330,6 +2336,7 @@ func (r *CommPolResource) Read(ctx context.Context, req resource.ReadRequest, re resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_management_access_policy with id '%s'", data.Id.ValueString())) @@ -2427,6 +2434,7 @@ func (r *CommPolResource) Update(ctx context.Context, req resource.UpdateRequest // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_management_access_policy with id '%s'", data.Id.ValueString())) } @@ -2455,10 +2463,11 @@ func (r *CommPolResource) Delete(ctx context.Context, req resource.DeleteRequest func (r *CommPolResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_management_access_policy") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *CommPolResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_management_access_policy with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_management_access_policy") @@ -2467,11 +2476,17 @@ func (r *CommPolResource) ImportState(ctx context.Context, req resource.ImportSt func getAndSetCommPolAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *CommPolResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "commPol,commHttp,commHttps,commShellinabox,commSsh,commTelnet,tagAnnotation,tagTag,tagAnnotation,tagTag,commRsClientCertCA,commRsKeyRing,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyCommPolResourceModel() - if diags.HasError() { return } + + setCommPolAttributes(ctx, diags, data, requestData) +} + +func setCommPolAttributes(ctx context.Context, diags *diag.Diagnostics, data *CommPolResourceModel, requestData *container.Container) { + + readData := getEmptyCommPolResourceModel() + if requestData.Search("imdata").Search("commPol").Data() != nil { classReadInfo := requestData.Search("imdata").Search("commPol").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_mld_snooping_policy.go b/internal/provider/resource_aci_mld_snooping_policy.go index 1bd3849f0..d003e9511 100644 --- a/internal/provider/resource_aci_mld_snooping_policy.go +++ b/internal/provider/resource_aci_mld_snooping_policy.go @@ -31,12 +31,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &MldSnoopPolResource{} +var _ resource.ResourceWithIdentity = &MldSnoopPolResource{} var _ resource.ResourceWithImportState = &MldSnoopPolResource{} func NewMldSnoopPolResource() resource.Resource { return &MldSnoopPolResource{} } +func (r MldSnoopPolResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // MldSnoopPolResource defines the resource implementation. type MldSnoopPolResource struct { client *client.Client @@ -467,6 +472,7 @@ func (r *MldSnoopPolResource) Create(ctx context.Context, req resource.CreateReq // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_mld_snooping_policy with id '%s'", data.Id.ValueString())) } @@ -491,6 +497,7 @@ func (r *MldSnoopPolResource) Read(ctx context.Context, req resource.ReadRequest resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_mld_snooping_policy with id '%s'", data.Id.ValueString())) @@ -533,6 +540,7 @@ func (r *MldSnoopPolResource) Update(ctx context.Context, req resource.UpdateReq // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_mld_snooping_policy with id '%s'", data.Id.ValueString())) } @@ -561,10 +569,11 @@ func (r *MldSnoopPolResource) Delete(ctx context.Context, req resource.DeleteReq func (r *MldSnoopPolResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_mld_snooping_policy") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *MldSnoopPolResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_mld_snooping_policy with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_mld_snooping_policy") @@ -573,11 +582,17 @@ func (r *MldSnoopPolResource) ImportState(ctx context.Context, req resource.Impo func getAndSetMldSnoopPolAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *MldSnoopPolResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "mldSnoopPol,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyMldSnoopPolResourceModel() - if diags.HasError() { return } + + setMldSnoopPolAttributes(ctx, diags, data, requestData) +} + +func setMldSnoopPolAttributes(ctx context.Context, diags *diag.Diagnostics, data *MldSnoopPolResourceModel, requestData *container.Container) { + + readData := getEmptyMldSnoopPolResourceModel() + if requestData.Search("imdata").Search("mldSnoopPol").Data() != nil { classReadInfo := requestData.Search("imdata").Search("mldSnoopPol").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_neighbor_discovery_interface_policy.go b/internal/provider/resource_aci_neighbor_discovery_interface_policy.go index bf7ef8f33..f3574688d 100644 --- a/internal/provider/resource_aci_neighbor_discovery_interface_policy.go +++ b/internal/provider/resource_aci_neighbor_discovery_interface_policy.go @@ -31,12 +31,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &NdIfPolResource{} +var _ resource.ResourceWithIdentity = &NdIfPolResource{} var _ resource.ResourceWithImportState = &NdIfPolResource{} func NewNdIfPolResource() resource.Resource { return &NdIfPolResource{} } +func (r NdIfPolResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // NdIfPolResource defines the resource implementation. type NdIfPolResource struct { client *client.Client @@ -505,6 +510,7 @@ func (r *NdIfPolResource) Create(ctx context.Context, req resource.CreateRequest // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_neighbor_discovery_interface_policy with id '%s'", data.Id.ValueString())) } @@ -529,6 +535,7 @@ func (r *NdIfPolResource) Read(ctx context.Context, req resource.ReadRequest, re resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_neighbor_discovery_interface_policy with id '%s'", data.Id.ValueString())) @@ -571,6 +578,7 @@ func (r *NdIfPolResource) Update(ctx context.Context, req resource.UpdateRequest // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_neighbor_discovery_interface_policy with id '%s'", data.Id.ValueString())) } @@ -599,10 +607,11 @@ func (r *NdIfPolResource) Delete(ctx context.Context, req resource.DeleteRequest func (r *NdIfPolResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_neighbor_discovery_interface_policy") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *NdIfPolResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_neighbor_discovery_interface_policy with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_neighbor_discovery_interface_policy") @@ -611,11 +620,17 @@ func (r *NdIfPolResource) ImportState(ctx context.Context, req resource.ImportSt func getAndSetNdIfPolAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *NdIfPolResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "ndIfPol,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyNdIfPolResourceModel() - if diags.HasError() { return } + + setNdIfPolAttributes(ctx, diags, data, requestData) +} + +func setNdIfPolAttributes(ctx context.Context, diags *diag.Diagnostics, data *NdIfPolResourceModel, requestData *container.Container) { + + readData := getEmptyNdIfPolResourceModel() + if requestData.Search("imdata").Search("ndIfPol").Data() != nil { classReadInfo := requestData.Search("imdata").Search("ndIfPol").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_netflow_exporter_policy.go b/internal/provider/resource_aci_netflow_exporter_policy.go index 98253b79c..a2d968f46 100644 --- a/internal/provider/resource_aci_netflow_exporter_policy.go +++ b/internal/provider/resource_aci_netflow_exporter_policy.go @@ -32,12 +32,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &NetflowExporterPolResource{} +var _ resource.ResourceWithIdentity = &NetflowExporterPolResource{} var _ resource.ResourceWithImportState = &NetflowExporterPolResource{} func NewNetflowExporterPolResource() resource.Resource { return &NetflowExporterPolResource{} } +func (r NetflowExporterPolResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // NetflowExporterPolResource defines the resource implementation. type NetflowExporterPolResource struct { client *client.Client @@ -792,6 +797,7 @@ func (r *NetflowExporterPolResource) Create(ctx context.Context, req resource.Cr // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_netflow_exporter_policy with id '%s'", data.Id.ValueString())) } @@ -816,6 +822,7 @@ func (r *NetflowExporterPolResource) Read(ctx context.Context, req resource.Read resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_netflow_exporter_policy with id '%s'", data.Id.ValueString())) @@ -864,6 +871,7 @@ func (r *NetflowExporterPolResource) Update(ctx context.Context, req resource.Up // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_netflow_exporter_policy with id '%s'", data.Id.ValueString())) } @@ -892,10 +900,11 @@ func (r *NetflowExporterPolResource) Delete(ctx context.Context, req resource.De func (r *NetflowExporterPolResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_netflow_exporter_policy") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *NetflowExporterPolResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_netflow_exporter_policy with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_netflow_exporter_policy") @@ -904,11 +913,17 @@ func (r *NetflowExporterPolResource) ImportState(ctx context.Context, req resour func getAndSetNetflowExporterPolAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *NetflowExporterPolResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "netflowExporterPol,netflowRsExporterToCtx,netflowRsExporterToEPg,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyNetflowExporterPolResourceModel() - if diags.HasError() { return } + + setNetflowExporterPolAttributes(ctx, diags, data, requestData) +} + +func setNetflowExporterPolAttributes(ctx context.Context, diags *diag.Diagnostics, data *NetflowExporterPolResourceModel, requestData *container.Container) { + + readData := getEmptyNetflowExporterPolResourceModel() + if requestData.Search("imdata").Search("netflowExporterPol").Data() != nil { classReadInfo := requestData.Search("imdata").Search("netflowExporterPol").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_netflow_monitor_policy.go b/internal/provider/resource_aci_netflow_monitor_policy.go index 2d2cbe610..b1c38b23f 100644 --- a/internal/provider/resource_aci_netflow_monitor_policy.go +++ b/internal/provider/resource_aci_netflow_monitor_policy.go @@ -28,12 +28,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &NetflowMonitorPolResource{} +var _ resource.ResourceWithIdentity = &NetflowMonitorPolResource{} var _ resource.ResourceWithImportState = &NetflowMonitorPolResource{} func NewNetflowMonitorPolResource() resource.Resource { return &NetflowMonitorPolResource{} } +func (r NetflowMonitorPolResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // NetflowMonitorPolResource defines the resource implementation. type NetflowMonitorPolResource struct { client *client.Client @@ -909,6 +914,7 @@ func (r *NetflowMonitorPolResource) Create(ctx context.Context, req resource.Cre // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_netflow_monitor_policy with id '%s'", data.Id.ValueString())) } @@ -933,6 +939,7 @@ func (r *NetflowMonitorPolResource) Read(ctx context.Context, req resource.ReadR resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_netflow_monitor_policy with id '%s'", data.Id.ValueString())) @@ -987,6 +994,7 @@ func (r *NetflowMonitorPolResource) Update(ctx context.Context, req resource.Upd // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_netflow_monitor_policy with id '%s'", data.Id.ValueString())) } @@ -1015,10 +1023,11 @@ func (r *NetflowMonitorPolResource) Delete(ctx context.Context, req resource.Del func (r *NetflowMonitorPolResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_netflow_monitor_policy") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *NetflowMonitorPolResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_netflow_monitor_policy with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_netflow_monitor_policy") @@ -1027,11 +1036,17 @@ func (r *NetflowMonitorPolResource) ImportState(ctx context.Context, req resourc func getAndSetNetflowMonitorPolAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *NetflowMonitorPolResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "netflowMonitorPol,netflowRsMonitorToExporter,netflowRsMonitorToRecord,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyNetflowMonitorPolResourceModel() - if diags.HasError() { return } + + setNetflowMonitorPolAttributes(ctx, diags, data, requestData) +} + +func setNetflowMonitorPolAttributes(ctx context.Context, diags *diag.Diagnostics, data *NetflowMonitorPolResourceModel, requestData *container.Container) { + + readData := getEmptyNetflowMonitorPolResourceModel() + if requestData.Search("imdata").Search("netflowMonitorPol").Data() != nil { classReadInfo := requestData.Search("imdata").Search("netflowMonitorPol").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_netflow_record_policy.go b/internal/provider/resource_aci_netflow_record_policy.go index 7668210b6..ff72d645e 100644 --- a/internal/provider/resource_aci_netflow_record_policy.go +++ b/internal/provider/resource_aci_netflow_record_policy.go @@ -31,12 +31,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &NetflowRecordPolResource{} +var _ resource.ResourceWithIdentity = &NetflowRecordPolResource{} var _ resource.ResourceWithImportState = &NetflowRecordPolResource{} func NewNetflowRecordPolResource() resource.Resource { return &NetflowRecordPolResource{} } +func (r NetflowRecordPolResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // NetflowRecordPolResource defines the resource implementation. type NetflowRecordPolResource struct { client *client.Client @@ -404,6 +409,7 @@ func (r *NetflowRecordPolResource) Create(ctx context.Context, req resource.Crea // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_netflow_record_policy with id '%s'", data.Id.ValueString())) } @@ -428,6 +434,7 @@ func (r *NetflowRecordPolResource) Read(ctx context.Context, req resource.ReadRe resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_netflow_record_policy with id '%s'", data.Id.ValueString())) @@ -470,6 +477,7 @@ func (r *NetflowRecordPolResource) Update(ctx context.Context, req resource.Upda // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_netflow_record_policy with id '%s'", data.Id.ValueString())) } @@ -498,10 +506,11 @@ func (r *NetflowRecordPolResource) Delete(ctx context.Context, req resource.Dele func (r *NetflowRecordPolResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_netflow_record_policy") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *NetflowRecordPolResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_netflow_record_policy with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_netflow_record_policy") @@ -510,11 +519,17 @@ func (r *NetflowRecordPolResource) ImportState(ctx context.Context, req resource func getAndSetNetflowRecordPolAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *NetflowRecordPolResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "netflowRecordPol,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyNetflowRecordPolResourceModel() - if diags.HasError() { return } + + setNetflowRecordPolAttributes(ctx, diags, data, requestData) +} + +func setNetflowRecordPolAttributes(ctx context.Context, diags *diag.Diagnostics, data *NetflowRecordPolResourceModel, requestData *container.Container) { + + readData := getEmptyNetflowRecordPolResourceModel() + if requestData.Search("imdata").Search("netflowRecordPol").Data() != nil { classReadInfo := requestData.Search("imdata").Search("netflowRecordPol").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_out_of_band_contract.go b/internal/provider/resource_aci_out_of_band_contract.go index 6f72c7883..6fe4c0053 100644 --- a/internal/provider/resource_aci_out_of_band_contract.go +++ b/internal/provider/resource_aci_out_of_band_contract.go @@ -32,12 +32,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &VzOOBBrCPResource{} +var _ resource.ResourceWithIdentity = &VzOOBBrCPResource{} var _ resource.ResourceWithImportState = &VzOOBBrCPResource{} func NewVzOOBBrCPResource() resource.Resource { return &VzOOBBrCPResource{} } +func (r VzOOBBrCPResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // VzOOBBrCPResource defines the resource implementation. type VzOOBBrCPResource struct { client *client.Client @@ -421,6 +426,7 @@ func (r *VzOOBBrCPResource) Create(ctx context.Context, req resource.CreateReque // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_out_of_band_contract with id '%s'", data.Id.ValueString())) } @@ -445,6 +451,7 @@ func (r *VzOOBBrCPResource) Read(ctx context.Context, req resource.ReadRequest, resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_out_of_band_contract with id '%s'", data.Id.ValueString())) @@ -487,6 +494,7 @@ func (r *VzOOBBrCPResource) Update(ctx context.Context, req resource.UpdateReque // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_out_of_band_contract with id '%s'", data.Id.ValueString())) } @@ -515,10 +523,11 @@ func (r *VzOOBBrCPResource) Delete(ctx context.Context, req resource.DeleteReque func (r *VzOOBBrCPResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_out_of_band_contract") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *VzOOBBrCPResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_out_of_band_contract with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_out_of_band_contract") @@ -527,11 +536,17 @@ func (r *VzOOBBrCPResource) ImportState(ctx context.Context, req resource.Import func getAndSetVzOOBBrCPAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *VzOOBBrCPResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "vzOOBBrCP,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyVzOOBBrCPResourceModel() - if diags.HasError() { return } + + setVzOOBBrCPAttributes(ctx, diags, data, requestData) +} + +func setVzOOBBrCPAttributes(ctx context.Context, diags *diag.Diagnostics, data *VzOOBBrCPResourceModel, requestData *container.Container) { + + readData := getEmptyVzOOBBrCPResourceModel() + if requestData.Search("imdata").Search("vzOOBBrCP").Data() != nil { classReadInfo := requestData.Search("imdata").Search("vzOOBBrCP").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_pim_route_map_entry.go b/internal/provider/resource_aci_pim_route_map_entry.go index 56ac6857b..3dfb4bdcc 100644 --- a/internal/provider/resource_aci_pim_route_map_entry.go +++ b/internal/provider/resource_aci_pim_route_map_entry.go @@ -29,12 +29,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &PimRouteMapEntryResource{} +var _ resource.ResourceWithIdentity = &PimRouteMapEntryResource{} var _ resource.ResourceWithImportState = &PimRouteMapEntryResource{} func NewPimRouteMapEntryResource() resource.Resource { return &PimRouteMapEntryResource{} } +func (r PimRouteMapEntryResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // PimRouteMapEntryResource defines the resource implementation. type PimRouteMapEntryResource struct { client *client.Client @@ -400,6 +405,7 @@ func (r *PimRouteMapEntryResource) Create(ctx context.Context, req resource.Crea // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_pim_route_map_entry with id '%s'", data.Id.ValueString())) } @@ -424,6 +430,7 @@ func (r *PimRouteMapEntryResource) Read(ctx context.Context, req resource.ReadRe resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_pim_route_map_entry with id '%s'", data.Id.ValueString())) @@ -466,6 +473,7 @@ func (r *PimRouteMapEntryResource) Update(ctx context.Context, req resource.Upda // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_pim_route_map_entry with id '%s'", data.Id.ValueString())) } @@ -494,10 +502,11 @@ func (r *PimRouteMapEntryResource) Delete(ctx context.Context, req resource.Dele func (r *PimRouteMapEntryResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_pim_route_map_entry") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *PimRouteMapEntryResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_pim_route_map_entry with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_pim_route_map_entry") @@ -506,11 +515,17 @@ func (r *PimRouteMapEntryResource) ImportState(ctx context.Context, req resource func getAndSetPimRouteMapEntryAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *PimRouteMapEntryResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "pimRouteMapEntry,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyPimRouteMapEntryResourceModel() - if diags.HasError() { return } + + setPimRouteMapEntryAttributes(ctx, diags, data, requestData) +} + +func setPimRouteMapEntryAttributes(ctx context.Context, diags *diag.Diagnostics, data *PimRouteMapEntryResourceModel, requestData *container.Container) { + + readData := getEmptyPimRouteMapEntryResourceModel() + if requestData.Search("imdata").Search("pimRouteMapEntry").Data() != nil { classReadInfo := requestData.Search("imdata").Search("pimRouteMapEntry").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_pim_route_map_policy.go b/internal/provider/resource_aci_pim_route_map_policy.go index ba82a048f..d269037ab 100644 --- a/internal/provider/resource_aci_pim_route_map_policy.go +++ b/internal/provider/resource_aci_pim_route_map_policy.go @@ -27,12 +27,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &PimRouteMapPolResource{} +var _ resource.ResourceWithIdentity = &PimRouteMapPolResource{} var _ resource.ResourceWithImportState = &PimRouteMapPolResource{} func NewPimRouteMapPolResource() resource.Resource { return &PimRouteMapPolResource{} } +func (r PimRouteMapPolResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // PimRouteMapPolResource defines the resource implementation. type PimRouteMapPolResource struct { client *client.Client @@ -362,6 +367,7 @@ func (r *PimRouteMapPolResource) Create(ctx context.Context, req resource.Create // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_pim_route_map_policy with id '%s'", data.Id.ValueString())) } @@ -386,6 +392,7 @@ func (r *PimRouteMapPolResource) Read(ctx context.Context, req resource.ReadRequ resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_pim_route_map_policy with id '%s'", data.Id.ValueString())) @@ -428,6 +435,7 @@ func (r *PimRouteMapPolResource) Update(ctx context.Context, req resource.Update // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_pim_route_map_policy with id '%s'", data.Id.ValueString())) } @@ -456,10 +464,11 @@ func (r *PimRouteMapPolResource) Delete(ctx context.Context, req resource.Delete func (r *PimRouteMapPolResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_pim_route_map_policy") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *PimRouteMapPolResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_pim_route_map_policy with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_pim_route_map_policy") @@ -468,11 +477,17 @@ func (r *PimRouteMapPolResource) ImportState(ctx context.Context, req resource.I func getAndSetPimRouteMapPolAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *PimRouteMapPolResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "pimRouteMapPol,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyPimRouteMapPolResourceModel() - if diags.HasError() { return } + + setPimRouteMapPolAttributes(ctx, diags, data, requestData) +} + +func setPimRouteMapPolAttributes(ctx context.Context, diags *diag.Diagnostics, data *PimRouteMapPolResourceModel, requestData *container.Container) { + + readData := getEmptyPimRouteMapPolResourceModel() + if requestData.Search("imdata").Search("pimRouteMapPol").Data() != nil { classReadInfo := requestData.Search("imdata").Search("pimRouteMapPol").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_relation_from_any_to_consumer_contract.go b/internal/provider/resource_aci_relation_from_any_to_consumer_contract.go index bddc226d2..c0980a1dd 100644 --- a/internal/provider/resource_aci_relation_from_any_to_consumer_contract.go +++ b/internal/provider/resource_aci_relation_from_any_to_consumer_contract.go @@ -31,12 +31,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &VzRsAnyToConsResource{} +var _ resource.ResourceWithIdentity = &VzRsAnyToConsResource{} var _ resource.ResourceWithImportState = &VzRsAnyToConsResource{} func NewVzRsAnyToConsResource() resource.Resource { return &VzRsAnyToConsResource{} } +func (r VzRsAnyToConsResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // VzRsAnyToConsResource defines the resource implementation. type VzRsAnyToConsResource struct { client *client.Client @@ -340,6 +345,7 @@ func (r *VzRsAnyToConsResource) Create(ctx context.Context, req resource.CreateR // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_relation_from_any_to_consumer_contract with id '%s'", data.Id.ValueString())) } @@ -364,6 +370,7 @@ func (r *VzRsAnyToConsResource) Read(ctx context.Context, req resource.ReadReque resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_relation_from_any_to_consumer_contract with id '%s'", data.Id.ValueString())) @@ -406,6 +413,7 @@ func (r *VzRsAnyToConsResource) Update(ctx context.Context, req resource.UpdateR // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_relation_from_any_to_consumer_contract with id '%s'", data.Id.ValueString())) } @@ -434,10 +442,11 @@ func (r *VzRsAnyToConsResource) Delete(ctx context.Context, req resource.DeleteR func (r *VzRsAnyToConsResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_relation_from_any_to_consumer_contract") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *VzRsAnyToConsResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_relation_from_any_to_consumer_contract with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_relation_from_any_to_consumer_contract") @@ -446,11 +455,17 @@ func (r *VzRsAnyToConsResource) ImportState(ctx context.Context, req resource.Im func getAndSetVzRsAnyToConsAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *VzRsAnyToConsResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "vzRsAnyToCons,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyVzRsAnyToConsResourceModel() - if diags.HasError() { return } + + setVzRsAnyToConsAttributes(ctx, diags, data, requestData) +} + +func setVzRsAnyToConsAttributes(ctx context.Context, diags *diag.Diagnostics, data *VzRsAnyToConsResourceModel, requestData *container.Container) { + + readData := getEmptyVzRsAnyToConsResourceModel() + if requestData.Search("imdata").Search("vzRsAnyToCons").Data() != nil { classReadInfo := requestData.Search("imdata").Search("vzRsAnyToCons").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_relation_from_any_to_contract_interface.go b/internal/provider/resource_aci_relation_from_any_to_contract_interface.go index 5baae38bc..5bd94d05f 100644 --- a/internal/provider/resource_aci_relation_from_any_to_contract_interface.go +++ b/internal/provider/resource_aci_relation_from_any_to_contract_interface.go @@ -31,12 +31,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &VzRsAnyToConsIfResource{} +var _ resource.ResourceWithIdentity = &VzRsAnyToConsIfResource{} var _ resource.ResourceWithImportState = &VzRsAnyToConsIfResource{} func NewVzRsAnyToConsIfResource() resource.Resource { return &VzRsAnyToConsIfResource{} } +func (r VzRsAnyToConsIfResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // VzRsAnyToConsIfResource defines the resource implementation. type VzRsAnyToConsIfResource struct { client *client.Client @@ -340,6 +345,7 @@ func (r *VzRsAnyToConsIfResource) Create(ctx context.Context, req resource.Creat // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_relation_from_any_to_contract_interface with id '%s'", data.Id.ValueString())) } @@ -364,6 +370,7 @@ func (r *VzRsAnyToConsIfResource) Read(ctx context.Context, req resource.ReadReq resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_relation_from_any_to_contract_interface with id '%s'", data.Id.ValueString())) @@ -406,6 +413,7 @@ func (r *VzRsAnyToConsIfResource) Update(ctx context.Context, req resource.Updat // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_relation_from_any_to_contract_interface with id '%s'", data.Id.ValueString())) } @@ -434,10 +442,11 @@ func (r *VzRsAnyToConsIfResource) Delete(ctx context.Context, req resource.Delet func (r *VzRsAnyToConsIfResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_relation_from_any_to_contract_interface") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *VzRsAnyToConsIfResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_relation_from_any_to_contract_interface with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_relation_from_any_to_contract_interface") @@ -446,11 +455,17 @@ func (r *VzRsAnyToConsIfResource) ImportState(ctx context.Context, req resource. func getAndSetVzRsAnyToConsIfAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *VzRsAnyToConsIfResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "vzRsAnyToConsIf,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyVzRsAnyToConsIfResourceModel() - if diags.HasError() { return } + + setVzRsAnyToConsIfAttributes(ctx, diags, data, requestData) +} + +func setVzRsAnyToConsIfAttributes(ctx context.Context, diags *diag.Diagnostics, data *VzRsAnyToConsIfResourceModel, requestData *container.Container) { + + readData := getEmptyVzRsAnyToConsIfResourceModel() + if requestData.Search("imdata").Search("vzRsAnyToConsIf").Data() != nil { classReadInfo := requestData.Search("imdata").Search("vzRsAnyToConsIf").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_relation_from_any_to_provider_contract.go b/internal/provider/resource_aci_relation_from_any_to_provider_contract.go index 6c4c87930..081fd45be 100644 --- a/internal/provider/resource_aci_relation_from_any_to_provider_contract.go +++ b/internal/provider/resource_aci_relation_from_any_to_provider_contract.go @@ -31,12 +31,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &VzRsAnyToProvResource{} +var _ resource.ResourceWithIdentity = &VzRsAnyToProvResource{} var _ resource.ResourceWithImportState = &VzRsAnyToProvResource{} func NewVzRsAnyToProvResource() resource.Resource { return &VzRsAnyToProvResource{} } +func (r VzRsAnyToProvResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // VzRsAnyToProvResource defines the resource implementation. type VzRsAnyToProvResource struct { client *client.Client @@ -354,6 +359,7 @@ func (r *VzRsAnyToProvResource) Create(ctx context.Context, req resource.CreateR // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_relation_from_any_to_provider_contract with id '%s'", data.Id.ValueString())) } @@ -378,6 +384,7 @@ func (r *VzRsAnyToProvResource) Read(ctx context.Context, req resource.ReadReque resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_relation_from_any_to_provider_contract with id '%s'", data.Id.ValueString())) @@ -420,6 +427,7 @@ func (r *VzRsAnyToProvResource) Update(ctx context.Context, req resource.UpdateR // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_relation_from_any_to_provider_contract with id '%s'", data.Id.ValueString())) } @@ -448,10 +456,11 @@ func (r *VzRsAnyToProvResource) Delete(ctx context.Context, req resource.DeleteR func (r *VzRsAnyToProvResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_relation_from_any_to_provider_contract") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *VzRsAnyToProvResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_relation_from_any_to_provider_contract with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_relation_from_any_to_provider_contract") @@ -460,11 +469,17 @@ func (r *VzRsAnyToProvResource) ImportState(ctx context.Context, req resource.Im func getAndSetVzRsAnyToProvAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *VzRsAnyToProvResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "vzRsAnyToProv,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyVzRsAnyToProvResourceModel() - if diags.HasError() { return } + + setVzRsAnyToProvAttributes(ctx, diags, data, requestData) +} + +func setVzRsAnyToProvAttributes(ctx context.Context, diags *diag.Diagnostics, data *VzRsAnyToProvResourceModel, requestData *container.Container) { + + readData := getEmptyVzRsAnyToProvResourceModel() + if requestData.Search("imdata").Search("vzRsAnyToProv").Data() != nil { classReadInfo := requestData.Search("imdata").Search("vzRsAnyToProv").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_relation_from_application_epg_to_attachable_access_entity_profile.go b/internal/provider/resource_aci_relation_from_application_epg_to_attachable_access_entity_profile.go index 2822a4306..1190af17f 100644 --- a/internal/provider/resource_aci_relation_from_application_epg_to_attachable_access_entity_profile.go +++ b/internal/provider/resource_aci_relation_from_application_epg_to_attachable_access_entity_profile.go @@ -28,12 +28,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvRsAepAttResource{} +var _ resource.ResourceWithIdentity = &FvRsAepAttResource{} var _ resource.ResourceWithImportState = &FvRsAepAttResource{} func NewFvRsAepAttResource() resource.Resource { return &FvRsAepAttResource{} } +func (r FvRsAepAttResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvRsAepAttResource defines the resource implementation. type FvRsAepAttResource struct { client *client.Client @@ -356,6 +361,7 @@ func (r *FvRsAepAttResource) Create(ctx context.Context, req resource.CreateRequ // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_relation_from_application_epg_to_attachable_access_entity_profile with id '%s'", data.Id.ValueString())) } @@ -380,6 +386,7 @@ func (r *FvRsAepAttResource) Read(ctx context.Context, req resource.ReadRequest, resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_relation_from_application_epg_to_attachable_access_entity_profile with id '%s'", data.Id.ValueString())) @@ -422,6 +429,7 @@ func (r *FvRsAepAttResource) Update(ctx context.Context, req resource.UpdateRequ // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_relation_from_application_epg_to_attachable_access_entity_profile with id '%s'", data.Id.ValueString())) } @@ -450,10 +458,11 @@ func (r *FvRsAepAttResource) Delete(ctx context.Context, req resource.DeleteRequ func (r *FvRsAepAttResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_relation_from_application_epg_to_attachable_access_entity_profile") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvRsAepAttResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_relation_from_application_epg_to_attachable_access_entity_profile with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_relation_from_application_epg_to_attachable_access_entity_profile") @@ -462,11 +471,17 @@ func (r *FvRsAepAttResource) ImportState(ctx context.Context, req resource.Impor func getAndSetFvRsAepAttAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvRsAepAttResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvRsAepAtt,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvRsAepAttResourceModel() - if diags.HasError() { return } + + setFvRsAepAttAttributes(ctx, diags, data, requestData) +} + +func setFvRsAepAttAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvRsAepAttResourceModel, requestData *container.Container) { + + readData := getEmptyFvRsAepAttResourceModel() + if requestData.Search("imdata").Search("fvRsAepAtt").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvRsAepAtt").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_relation_from_attachable_access_entity_profile_to_domain.go b/internal/provider/resource_aci_relation_from_attachable_access_entity_profile_to_domain.go index 16b5fc8dd..103377ff0 100644 --- a/internal/provider/resource_aci_relation_from_attachable_access_entity_profile_to_domain.go +++ b/internal/provider/resource_aci_relation_from_attachable_access_entity_profile_to_domain.go @@ -27,12 +27,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &InfraRsDomPResource{} +var _ resource.ResourceWithIdentity = &InfraRsDomPResource{} var _ resource.ResourceWithImportState = &InfraRsDomPResource{} func NewInfraRsDomPResource() resource.Resource { return &InfraRsDomPResource{} } +func (r InfraRsDomPResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // InfraRsDomPResource defines the resource implementation. type InfraRsDomPResource struct { client *client.Client @@ -318,6 +323,7 @@ func (r *InfraRsDomPResource) Create(ctx context.Context, req resource.CreateReq // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_relation_from_attachable_access_entity_profile_to_domain with id '%s'", data.Id.ValueString())) } @@ -342,6 +348,7 @@ func (r *InfraRsDomPResource) Read(ctx context.Context, req resource.ReadRequest resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_relation_from_attachable_access_entity_profile_to_domain with id '%s'", data.Id.ValueString())) @@ -384,6 +391,7 @@ func (r *InfraRsDomPResource) Update(ctx context.Context, req resource.UpdateReq // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_relation_from_attachable_access_entity_profile_to_domain with id '%s'", data.Id.ValueString())) } @@ -412,10 +420,11 @@ func (r *InfraRsDomPResource) Delete(ctx context.Context, req resource.DeleteReq func (r *InfraRsDomPResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_relation_from_attachable_access_entity_profile_to_domain") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *InfraRsDomPResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_relation_from_attachable_access_entity_profile_to_domain with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_relation_from_attachable_access_entity_profile_to_domain") @@ -424,11 +433,17 @@ func (r *InfraRsDomPResource) ImportState(ctx context.Context, req resource.Impo func getAndSetInfraRsDomPAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *InfraRsDomPResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "infraRsDomP,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyInfraRsDomPResourceModel() - if diags.HasError() { return } + + setInfraRsDomPAttributes(ctx, diags, data, requestData) +} + +func setInfraRsDomPAttributes(ctx context.Context, diags *diag.Diagnostics, data *InfraRsDomPResourceModel, requestData *container.Container) { + + readData := getEmptyInfraRsDomPResourceModel() + if requestData.Search("imdata").Search("infraRsDomP").Data() != nil { classReadInfo := requestData.Search("imdata").Search("infraRsDomP").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_relation_from_bridge_domain_to_l3_outside.go b/internal/provider/resource_aci_relation_from_bridge_domain_to_l3_outside.go index 842734103..3f935c1c7 100644 --- a/internal/provider/resource_aci_relation_from_bridge_domain_to_l3_outside.go +++ b/internal/provider/resource_aci_relation_from_bridge_domain_to_l3_outside.go @@ -27,12 +27,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvRsBDToOutResource{} +var _ resource.ResourceWithIdentity = &FvRsBDToOutResource{} var _ resource.ResourceWithImportState = &FvRsBDToOutResource{} func NewFvRsBDToOutResource() resource.Resource { return &FvRsBDToOutResource{} } +func (r FvRsBDToOutResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvRsBDToOutResource defines the resource implementation. type FvRsBDToOutResource struct { client *client.Client @@ -318,6 +323,7 @@ func (r *FvRsBDToOutResource) Create(ctx context.Context, req resource.CreateReq // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_relation_from_bridge_domain_to_l3_outside with id '%s'", data.Id.ValueString())) } @@ -342,6 +348,7 @@ func (r *FvRsBDToOutResource) Read(ctx context.Context, req resource.ReadRequest resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_relation_from_bridge_domain_to_l3_outside with id '%s'", data.Id.ValueString())) @@ -384,6 +391,7 @@ func (r *FvRsBDToOutResource) Update(ctx context.Context, req resource.UpdateReq // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_relation_from_bridge_domain_to_l3_outside with id '%s'", data.Id.ValueString())) } @@ -412,10 +420,11 @@ func (r *FvRsBDToOutResource) Delete(ctx context.Context, req resource.DeleteReq func (r *FvRsBDToOutResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_relation_from_bridge_domain_to_l3_outside") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvRsBDToOutResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_relation_from_bridge_domain_to_l3_outside with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_relation_from_bridge_domain_to_l3_outside") @@ -424,11 +433,17 @@ func (r *FvRsBDToOutResource) ImportState(ctx context.Context, req resource.Impo func getAndSetFvRsBDToOutAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvRsBDToOutResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvRsBDToOut,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvRsBDToOutResourceModel() - if diags.HasError() { return } + + setFvRsBDToOutAttributes(ctx, diags, data, requestData) +} + +func setFvRsBDToOutAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvRsBDToOutResourceModel, requestData *container.Container) { + + readData := getEmptyFvRsBDToOutResourceModel() + if requestData.Search("imdata").Search("fvRsBDToOut").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvRsBDToOut").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_relation_from_bridge_domain_to_netflow_monitor_policy.go b/internal/provider/resource_aci_relation_from_bridge_domain_to_netflow_monitor_policy.go index 05238c205..b41ce0e6a 100644 --- a/internal/provider/resource_aci_relation_from_bridge_domain_to_netflow_monitor_policy.go +++ b/internal/provider/resource_aci_relation_from_bridge_domain_to_netflow_monitor_policy.go @@ -29,12 +29,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvRsBDToNetflowMonitorPolResource{} +var _ resource.ResourceWithIdentity = &FvRsBDToNetflowMonitorPolResource{} var _ resource.ResourceWithImportState = &FvRsBDToNetflowMonitorPolResource{} func NewFvRsBDToNetflowMonitorPolResource() resource.Resource { return &FvRsBDToNetflowMonitorPolResource{} } +func (r FvRsBDToNetflowMonitorPolResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvRsBDToNetflowMonitorPolResource defines the resource implementation. type FvRsBDToNetflowMonitorPolResource struct { client *client.Client @@ -335,6 +340,7 @@ func (r *FvRsBDToNetflowMonitorPolResource) Create(ctx context.Context, req reso // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_relation_from_bridge_domain_to_netflow_monitor_policy with id '%s'", data.Id.ValueString())) } @@ -359,6 +365,7 @@ func (r *FvRsBDToNetflowMonitorPolResource) Read(ctx context.Context, req resour resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_relation_from_bridge_domain_to_netflow_monitor_policy with id '%s'", data.Id.ValueString())) @@ -401,6 +408,7 @@ func (r *FvRsBDToNetflowMonitorPolResource) Update(ctx context.Context, req reso // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_relation_from_bridge_domain_to_netflow_monitor_policy with id '%s'", data.Id.ValueString())) } @@ -429,10 +437,11 @@ func (r *FvRsBDToNetflowMonitorPolResource) Delete(ctx context.Context, req reso func (r *FvRsBDToNetflowMonitorPolResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_relation_from_bridge_domain_to_netflow_monitor_policy") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvRsBDToNetflowMonitorPolResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_relation_from_bridge_domain_to_netflow_monitor_policy with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_relation_from_bridge_domain_to_netflow_monitor_policy") @@ -441,11 +450,17 @@ func (r *FvRsBDToNetflowMonitorPolResource) ImportState(ctx context.Context, req func getAndSetFvRsBDToNetflowMonitorPolAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvRsBDToNetflowMonitorPolResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvRsBDToNetflowMonitorPol,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvRsBDToNetflowMonitorPolResourceModel() - if diags.HasError() { return } + + setFvRsBDToNetflowMonitorPolAttributes(ctx, diags, data, requestData) +} + +func setFvRsBDToNetflowMonitorPolAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvRsBDToNetflowMonitorPolResourceModel, requestData *container.Container) { + + readData := getEmptyFvRsBDToNetflowMonitorPolResourceModel() + if requestData.Search("imdata").Search("fvRsBDToNetflowMonitorPol").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvRsBDToNetflowMonitorPol").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_relation_from_external_epg_to_route_control_profile.go b/internal/provider/resource_aci_relation_from_external_epg_to_route_control_profile.go index 8c83f9386..197e5c23e 100644 --- a/internal/provider/resource_aci_relation_from_external_epg_to_route_control_profile.go +++ b/internal/provider/resource_aci_relation_from_external_epg_to_route_control_profile.go @@ -29,12 +29,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &L3extRsInstPToProfileResource{} +var _ resource.ResourceWithIdentity = &L3extRsInstPToProfileResource{} var _ resource.ResourceWithImportState = &L3extRsInstPToProfileResource{} func NewL3extRsInstPToProfileResource() resource.Resource { return &L3extRsInstPToProfileResource{} } +func (r L3extRsInstPToProfileResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // L3extRsInstPToProfileResource defines the resource implementation. type L3extRsInstPToProfileResource struct { client *client.Client @@ -335,6 +340,7 @@ func (r *L3extRsInstPToProfileResource) Create(ctx context.Context, req resource // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_relation_from_external_epg_to_route_control_profile with id '%s'", data.Id.ValueString())) } @@ -359,6 +365,7 @@ func (r *L3extRsInstPToProfileResource) Read(ctx context.Context, req resource.R resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_relation_from_external_epg_to_route_control_profile with id '%s'", data.Id.ValueString())) @@ -401,6 +408,7 @@ func (r *L3extRsInstPToProfileResource) Update(ctx context.Context, req resource // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_relation_from_external_epg_to_route_control_profile with id '%s'", data.Id.ValueString())) } @@ -429,10 +437,11 @@ func (r *L3extRsInstPToProfileResource) Delete(ctx context.Context, req resource func (r *L3extRsInstPToProfileResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_relation_from_external_epg_to_route_control_profile") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *L3extRsInstPToProfileResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_relation_from_external_epg_to_route_control_profile with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_relation_from_external_epg_to_route_control_profile") @@ -441,11 +450,17 @@ func (r *L3extRsInstPToProfileResource) ImportState(ctx context.Context, req res func getAndSetL3extRsInstPToProfileAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *L3extRsInstPToProfileResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "l3extRsInstPToProfile,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyL3extRsInstPToProfileResourceModel() - if diags.HasError() { return } + + setL3extRsInstPToProfileAttributes(ctx, diags, data, requestData) +} + +func setL3extRsInstPToProfileAttributes(ctx context.Context, diags *diag.Diagnostics, data *L3extRsInstPToProfileResourceModel, requestData *container.Container) { + + readData := getEmptyL3extRsInstPToProfileResourceModel() + if requestData.Search("imdata").Search("l3extRsInstPToProfile").Data() != nil { classReadInfo := requestData.Search("imdata").Search("l3extRsInstPToProfile").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_relation_from_l3out_consumer_label_to_external_epg.go b/internal/provider/resource_aci_relation_from_l3out_consumer_label_to_external_epg.go index 9067d431e..95eceb517 100644 --- a/internal/provider/resource_aci_relation_from_l3out_consumer_label_to_external_epg.go +++ b/internal/provider/resource_aci_relation_from_l3out_consumer_label_to_external_epg.go @@ -27,12 +27,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &L3extRsLblToInstPResource{} +var _ resource.ResourceWithIdentity = &L3extRsLblToInstPResource{} var _ resource.ResourceWithImportState = &L3extRsLblToInstPResource{} func NewL3extRsLblToInstPResource() resource.Resource { return &L3extRsLblToInstPResource{} } +func (r L3extRsLblToInstPResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // L3extRsLblToInstPResource defines the resource implementation. type L3extRsLblToInstPResource struct { client *client.Client @@ -318,6 +323,7 @@ func (r *L3extRsLblToInstPResource) Create(ctx context.Context, req resource.Cre // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_relation_from_l3out_consumer_label_to_external_epg with id '%s'", data.Id.ValueString())) } @@ -342,6 +348,7 @@ func (r *L3extRsLblToInstPResource) Read(ctx context.Context, req resource.ReadR resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_relation_from_l3out_consumer_label_to_external_epg with id '%s'", data.Id.ValueString())) @@ -384,6 +391,7 @@ func (r *L3extRsLblToInstPResource) Update(ctx context.Context, req resource.Upd // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_relation_from_l3out_consumer_label_to_external_epg with id '%s'", data.Id.ValueString())) } @@ -412,10 +420,11 @@ func (r *L3extRsLblToInstPResource) Delete(ctx context.Context, req resource.Del func (r *L3extRsLblToInstPResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_relation_from_l3out_consumer_label_to_external_epg") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *L3extRsLblToInstPResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_relation_from_l3out_consumer_label_to_external_epg with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_relation_from_l3out_consumer_label_to_external_epg") @@ -424,11 +433,17 @@ func (r *L3extRsLblToInstPResource) ImportState(ctx context.Context, req resourc func getAndSetL3extRsLblToInstPAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *L3extRsLblToInstPResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "l3extRsLblToInstP,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyL3extRsLblToInstPResourceModel() - if diags.HasError() { return } + + setL3extRsLblToInstPAttributes(ctx, diags, data, requestData) +} + +func setL3extRsLblToInstPAttributes(ctx context.Context, diags *diag.Diagnostics, data *L3extRsLblToInstPResourceModel, requestData *container.Container) { + + readData := getEmptyL3extRsLblToInstPResourceModel() + if requestData.Search("imdata").Search("l3extRsLblToInstP").Data() != nil { classReadInfo := requestData.Search("imdata").Search("l3extRsLblToInstP").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_relation_from_l3out_consumer_label_to_route_control_profile.go b/internal/provider/resource_aci_relation_from_l3out_consumer_label_to_route_control_profile.go index 106e2d27e..b4a503317 100644 --- a/internal/provider/resource_aci_relation_from_l3out_consumer_label_to_route_control_profile.go +++ b/internal/provider/resource_aci_relation_from_l3out_consumer_label_to_route_control_profile.go @@ -29,12 +29,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &L3extRsLblToProfileResource{} +var _ resource.ResourceWithIdentity = &L3extRsLblToProfileResource{} var _ resource.ResourceWithImportState = &L3extRsLblToProfileResource{} func NewL3extRsLblToProfileResource() resource.Resource { return &L3extRsLblToProfileResource{} } +func (r L3extRsLblToProfileResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // L3extRsLblToProfileResource defines the resource implementation. type L3extRsLblToProfileResource struct { client *client.Client @@ -335,6 +340,7 @@ func (r *L3extRsLblToProfileResource) Create(ctx context.Context, req resource.C // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_relation_from_l3out_consumer_label_to_route_control_profile with id '%s'", data.Id.ValueString())) } @@ -359,6 +365,7 @@ func (r *L3extRsLblToProfileResource) Read(ctx context.Context, req resource.Rea resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_relation_from_l3out_consumer_label_to_route_control_profile with id '%s'", data.Id.ValueString())) @@ -401,6 +408,7 @@ func (r *L3extRsLblToProfileResource) Update(ctx context.Context, req resource.U // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_relation_from_l3out_consumer_label_to_route_control_profile with id '%s'", data.Id.ValueString())) } @@ -429,10 +437,11 @@ func (r *L3extRsLblToProfileResource) Delete(ctx context.Context, req resource.D func (r *L3extRsLblToProfileResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_relation_from_l3out_consumer_label_to_route_control_profile") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *L3extRsLblToProfileResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_relation_from_l3out_consumer_label_to_route_control_profile with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_relation_from_l3out_consumer_label_to_route_control_profile") @@ -441,11 +450,17 @@ func (r *L3extRsLblToProfileResource) ImportState(ctx context.Context, req resou func getAndSetL3extRsLblToProfileAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *L3extRsLblToProfileResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "l3extRsLblToProfile,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyL3extRsLblToProfileResourceModel() - if diags.HasError() { return } + + setL3extRsLblToProfileAttributes(ctx, diags, data, requestData) +} + +func setL3extRsLblToProfileAttributes(ctx context.Context, diags *diag.Diagnostics, data *L3extRsLblToProfileResourceModel, requestData *container.Container) { + + readData := getEmptyL3extRsLblToProfileResourceModel() + if requestData.Search("imdata").Search("l3extRsLblToProfile").Data() != nil { classReadInfo := requestData.Search("imdata").Search("l3extRsLblToProfile").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_relation_from_taboo_contract_subject_to_filter.go b/internal/provider/resource_aci_relation_from_taboo_contract_subject_to_filter.go index 638b38a53..90f7d30e0 100644 --- a/internal/provider/resource_aci_relation_from_taboo_contract_subject_to_filter.go +++ b/internal/provider/resource_aci_relation_from_taboo_contract_subject_to_filter.go @@ -31,12 +31,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &VzRsDenyRuleResource{} +var _ resource.ResourceWithIdentity = &VzRsDenyRuleResource{} var _ resource.ResourceWithImportState = &VzRsDenyRuleResource{} func NewVzRsDenyRuleResource() resource.Resource { return &VzRsDenyRuleResource{} } +func (r VzRsDenyRuleResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // VzRsDenyRuleResource defines the resource implementation. type VzRsDenyRuleResource struct { client *client.Client @@ -340,6 +345,7 @@ func (r *VzRsDenyRuleResource) Create(ctx context.Context, req resource.CreateRe // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_relation_from_taboo_contract_subject_to_filter with id '%s'", data.Id.ValueString())) } @@ -364,6 +370,7 @@ func (r *VzRsDenyRuleResource) Read(ctx context.Context, req resource.ReadReques resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_relation_from_taboo_contract_subject_to_filter with id '%s'", data.Id.ValueString())) @@ -406,6 +413,7 @@ func (r *VzRsDenyRuleResource) Update(ctx context.Context, req resource.UpdateRe // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_relation_from_taboo_contract_subject_to_filter with id '%s'", data.Id.ValueString())) } @@ -434,10 +442,11 @@ func (r *VzRsDenyRuleResource) Delete(ctx context.Context, req resource.DeleteRe func (r *VzRsDenyRuleResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_relation_from_taboo_contract_subject_to_filter") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *VzRsDenyRuleResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_relation_from_taboo_contract_subject_to_filter with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_relation_from_taboo_contract_subject_to_filter") @@ -446,11 +455,17 @@ func (r *VzRsDenyRuleResource) ImportState(ctx context.Context, req resource.Imp func getAndSetVzRsDenyRuleAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *VzRsDenyRuleResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "vzRsDenyRule,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyVzRsDenyRuleResourceModel() - if diags.HasError() { return } + + setVzRsDenyRuleAttributes(ctx, diags, data, requestData) +} + +func setVzRsDenyRuleAttributes(ctx context.Context, diags *diag.Diagnostics, data *VzRsDenyRuleResourceModel, requestData *container.Container) { + + readData := getEmptyVzRsDenyRuleResourceModel() + if requestData.Search("imdata").Search("vzRsDenyRule").Data() != nil { classReadInfo := requestData.Search("imdata").Search("vzRsDenyRule").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_relation_from_vrf_to_address_family_ospf_timers.go b/internal/provider/resource_aci_relation_from_vrf_to_address_family_ospf_timers.go index 934c87946..35676a1a0 100644 --- a/internal/provider/resource_aci_relation_from_vrf_to_address_family_ospf_timers.go +++ b/internal/provider/resource_aci_relation_from_vrf_to_address_family_ospf_timers.go @@ -29,12 +29,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvRsCtxToOspfCtxPolResource{} +var _ resource.ResourceWithIdentity = &FvRsCtxToOspfCtxPolResource{} var _ resource.ResourceWithImportState = &FvRsCtxToOspfCtxPolResource{} func NewFvRsCtxToOspfCtxPolResource() resource.Resource { return &FvRsCtxToOspfCtxPolResource{} } +func (r FvRsCtxToOspfCtxPolResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvRsCtxToOspfCtxPolResource defines the resource implementation. type FvRsCtxToOspfCtxPolResource struct { client *client.Client @@ -335,6 +340,7 @@ func (r *FvRsCtxToOspfCtxPolResource) Create(ctx context.Context, req resource.C // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_relation_from_vrf_to_address_family_ospf_timers with id '%s'", data.Id.ValueString())) } @@ -359,6 +365,7 @@ func (r *FvRsCtxToOspfCtxPolResource) Read(ctx context.Context, req resource.Rea resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_relation_from_vrf_to_address_family_ospf_timers with id '%s'", data.Id.ValueString())) @@ -401,6 +408,7 @@ func (r *FvRsCtxToOspfCtxPolResource) Update(ctx context.Context, req resource.U // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_relation_from_vrf_to_address_family_ospf_timers with id '%s'", data.Id.ValueString())) } @@ -429,10 +437,11 @@ func (r *FvRsCtxToOspfCtxPolResource) Delete(ctx context.Context, req resource.D func (r *FvRsCtxToOspfCtxPolResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_relation_from_vrf_to_address_family_ospf_timers") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvRsCtxToOspfCtxPolResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_relation_from_vrf_to_address_family_ospf_timers with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_relation_from_vrf_to_address_family_ospf_timers") @@ -441,11 +450,17 @@ func (r *FvRsCtxToOspfCtxPolResource) ImportState(ctx context.Context, req resou func getAndSetFvRsCtxToOspfCtxPolAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvRsCtxToOspfCtxPolResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvRsCtxToOspfCtxPol,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvRsCtxToOspfCtxPolResourceModel() - if diags.HasError() { return } + + setFvRsCtxToOspfCtxPolAttributes(ctx, diags, data, requestData) +} + +func setFvRsCtxToOspfCtxPolAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvRsCtxToOspfCtxPolResourceModel, requestData *container.Container) { + + readData := getEmptyFvRsCtxToOspfCtxPolResourceModel() + if requestData.Search("imdata").Search("fvRsCtxToOspfCtxPol").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvRsCtxToOspfCtxPol").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_relation_from_vrf_to_bgp_address_family_context.go b/internal/provider/resource_aci_relation_from_vrf_to_bgp_address_family_context.go index c35ebe765..0aca0177c 100644 --- a/internal/provider/resource_aci_relation_from_vrf_to_bgp_address_family_context.go +++ b/internal/provider/resource_aci_relation_from_vrf_to_bgp_address_family_context.go @@ -29,12 +29,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvRsCtxToBgpCtxAfPolResource{} +var _ resource.ResourceWithIdentity = &FvRsCtxToBgpCtxAfPolResource{} var _ resource.ResourceWithImportState = &FvRsCtxToBgpCtxAfPolResource{} func NewFvRsCtxToBgpCtxAfPolResource() resource.Resource { return &FvRsCtxToBgpCtxAfPolResource{} } +func (r FvRsCtxToBgpCtxAfPolResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvRsCtxToBgpCtxAfPolResource defines the resource implementation. type FvRsCtxToBgpCtxAfPolResource struct { client *client.Client @@ -335,6 +340,7 @@ func (r *FvRsCtxToBgpCtxAfPolResource) Create(ctx context.Context, req resource. // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_relation_from_vrf_to_bgp_address_family_context with id '%s'", data.Id.ValueString())) } @@ -359,6 +365,7 @@ func (r *FvRsCtxToBgpCtxAfPolResource) Read(ctx context.Context, req resource.Re resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_relation_from_vrf_to_bgp_address_family_context with id '%s'", data.Id.ValueString())) @@ -401,6 +408,7 @@ func (r *FvRsCtxToBgpCtxAfPolResource) Update(ctx context.Context, req resource. // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_relation_from_vrf_to_bgp_address_family_context with id '%s'", data.Id.ValueString())) } @@ -429,10 +437,11 @@ func (r *FvRsCtxToBgpCtxAfPolResource) Delete(ctx context.Context, req resource. func (r *FvRsCtxToBgpCtxAfPolResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_relation_from_vrf_to_bgp_address_family_context") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvRsCtxToBgpCtxAfPolResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_relation_from_vrf_to_bgp_address_family_context with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_relation_from_vrf_to_bgp_address_family_context") @@ -441,11 +450,17 @@ func (r *FvRsCtxToBgpCtxAfPolResource) ImportState(ctx context.Context, req reso func getAndSetFvRsCtxToBgpCtxAfPolAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvRsCtxToBgpCtxAfPolResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvRsCtxToBgpCtxAfPol,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvRsCtxToBgpCtxAfPolResourceModel() - if diags.HasError() { return } + + setFvRsCtxToBgpCtxAfPolAttributes(ctx, diags, data, requestData) +} + +func setFvRsCtxToBgpCtxAfPolAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvRsCtxToBgpCtxAfPolResourceModel, requestData *container.Container) { + + readData := getEmptyFvRsCtxToBgpCtxAfPolResourceModel() + if requestData.Search("imdata").Search("fvRsCtxToBgpCtxAfPol").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvRsCtxToBgpCtxAfPol").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_relation_from_vrf_to_eigrp_address_family_context.go b/internal/provider/resource_aci_relation_from_vrf_to_eigrp_address_family_context.go index 9c96fe460..128980a6f 100644 --- a/internal/provider/resource_aci_relation_from_vrf_to_eigrp_address_family_context.go +++ b/internal/provider/resource_aci_relation_from_vrf_to_eigrp_address_family_context.go @@ -29,12 +29,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvRsCtxToEigrpCtxAfPolResource{} +var _ resource.ResourceWithIdentity = &FvRsCtxToEigrpCtxAfPolResource{} var _ resource.ResourceWithImportState = &FvRsCtxToEigrpCtxAfPolResource{} func NewFvRsCtxToEigrpCtxAfPolResource() resource.Resource { return &FvRsCtxToEigrpCtxAfPolResource{} } +func (r FvRsCtxToEigrpCtxAfPolResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvRsCtxToEigrpCtxAfPolResource defines the resource implementation. type FvRsCtxToEigrpCtxAfPolResource struct { client *client.Client @@ -335,6 +340,7 @@ func (r *FvRsCtxToEigrpCtxAfPolResource) Create(ctx context.Context, req resourc // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_relation_from_vrf_to_eigrp_address_family_context with id '%s'", data.Id.ValueString())) } @@ -359,6 +365,7 @@ func (r *FvRsCtxToEigrpCtxAfPolResource) Read(ctx context.Context, req resource. resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_relation_from_vrf_to_eigrp_address_family_context with id '%s'", data.Id.ValueString())) @@ -401,6 +408,7 @@ func (r *FvRsCtxToEigrpCtxAfPolResource) Update(ctx context.Context, req resourc // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_relation_from_vrf_to_eigrp_address_family_context with id '%s'", data.Id.ValueString())) } @@ -429,10 +437,11 @@ func (r *FvRsCtxToEigrpCtxAfPolResource) Delete(ctx context.Context, req resourc func (r *FvRsCtxToEigrpCtxAfPolResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_relation_from_vrf_to_eigrp_address_family_context") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvRsCtxToEigrpCtxAfPolResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_relation_from_vrf_to_eigrp_address_family_context with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_relation_from_vrf_to_eigrp_address_family_context") @@ -441,11 +450,17 @@ func (r *FvRsCtxToEigrpCtxAfPolResource) ImportState(ctx context.Context, req re func getAndSetFvRsCtxToEigrpCtxAfPolAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvRsCtxToEigrpCtxAfPolResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvRsCtxToEigrpCtxAfPol,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvRsCtxToEigrpCtxAfPolResourceModel() - if diags.HasError() { return } + + setFvRsCtxToEigrpCtxAfPolAttributes(ctx, diags, data, requestData) +} + +func setFvRsCtxToEigrpCtxAfPolAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvRsCtxToEigrpCtxAfPolResourceModel, requestData *container.Container) { + + readData := getEmptyFvRsCtxToEigrpCtxAfPolResourceModel() + if requestData.Search("imdata").Search("fvRsCtxToEigrpCtxAfPol").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvRsCtxToEigrpCtxAfPol").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_relation_to_consumed_contract.go b/internal/provider/resource_aci_relation_to_consumed_contract.go index 7067d4d60..d24a4cd5b 100644 --- a/internal/provider/resource_aci_relation_to_consumed_contract.go +++ b/internal/provider/resource_aci_relation_to_consumed_contract.go @@ -31,12 +31,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvRsConsResource{} +var _ resource.ResourceWithIdentity = &FvRsConsResource{} var _ resource.ResourceWithImportState = &FvRsConsResource{} func NewFvRsConsResource() resource.Resource { return &FvRsConsResource{} } +func (r FvRsConsResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvRsConsResource defines the resource implementation. type FvRsConsResource struct { client *client.Client @@ -340,6 +345,7 @@ func (r *FvRsConsResource) Create(ctx context.Context, req resource.CreateReques // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_relation_to_consumed_contract with id '%s'", data.Id.ValueString())) } @@ -364,6 +370,7 @@ func (r *FvRsConsResource) Read(ctx context.Context, req resource.ReadRequest, r resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_relation_to_consumed_contract with id '%s'", data.Id.ValueString())) @@ -406,6 +413,7 @@ func (r *FvRsConsResource) Update(ctx context.Context, req resource.UpdateReques // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_relation_to_consumed_contract with id '%s'", data.Id.ValueString())) } @@ -434,10 +442,11 @@ func (r *FvRsConsResource) Delete(ctx context.Context, req resource.DeleteReques func (r *FvRsConsResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_relation_to_consumed_contract") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvRsConsResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_relation_to_consumed_contract with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_relation_to_consumed_contract") @@ -446,11 +455,17 @@ func (r *FvRsConsResource) ImportState(ctx context.Context, req resource.ImportS func getAndSetFvRsConsAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvRsConsResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvRsCons,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvRsConsResourceModel() - if diags.HasError() { return } + + setFvRsConsAttributes(ctx, diags, data, requestData) +} + +func setFvRsConsAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvRsConsResourceModel, requestData *container.Container) { + + readData := getEmptyFvRsConsResourceModel() + if requestData.Search("imdata").Search("fvRsCons").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvRsCons").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_relation_to_consumed_out_of_band_contract.go b/internal/provider/resource_aci_relation_to_consumed_out_of_band_contract.go index d78c579e2..0462cf73a 100644 --- a/internal/provider/resource_aci_relation_to_consumed_out_of_band_contract.go +++ b/internal/provider/resource_aci_relation_to_consumed_out_of_band_contract.go @@ -31,12 +31,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &MgmtRsOoBConsResource{} +var _ resource.ResourceWithIdentity = &MgmtRsOoBConsResource{} var _ resource.ResourceWithImportState = &MgmtRsOoBConsResource{} func NewMgmtRsOoBConsResource() resource.Resource { return &MgmtRsOoBConsResource{} } +func (r MgmtRsOoBConsResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // MgmtRsOoBConsResource defines the resource implementation. type MgmtRsOoBConsResource struct { client *client.Client @@ -340,6 +345,7 @@ func (r *MgmtRsOoBConsResource) Create(ctx context.Context, req resource.CreateR // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_relation_to_consumed_out_of_band_contract with id '%s'", data.Id.ValueString())) } @@ -364,6 +370,7 @@ func (r *MgmtRsOoBConsResource) Read(ctx context.Context, req resource.ReadReque resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_relation_to_consumed_out_of_band_contract with id '%s'", data.Id.ValueString())) @@ -406,6 +413,7 @@ func (r *MgmtRsOoBConsResource) Update(ctx context.Context, req resource.UpdateR // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_relation_to_consumed_out_of_band_contract with id '%s'", data.Id.ValueString())) } @@ -434,10 +442,11 @@ func (r *MgmtRsOoBConsResource) Delete(ctx context.Context, req resource.DeleteR func (r *MgmtRsOoBConsResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_relation_to_consumed_out_of_band_contract") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *MgmtRsOoBConsResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_relation_to_consumed_out_of_band_contract with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_relation_to_consumed_out_of_band_contract") @@ -446,11 +455,17 @@ func (r *MgmtRsOoBConsResource) ImportState(ctx context.Context, req resource.Im func getAndSetMgmtRsOoBConsAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *MgmtRsOoBConsResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "mgmtRsOoBCons,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyMgmtRsOoBConsResourceModel() - if diags.HasError() { return } + + setMgmtRsOoBConsAttributes(ctx, diags, data, requestData) +} + +func setMgmtRsOoBConsAttributes(ctx context.Context, diags *diag.Diagnostics, data *MgmtRsOoBConsResourceModel, requestData *container.Container) { + + readData := getEmptyMgmtRsOoBConsResourceModel() + if requestData.Search("imdata").Search("mgmtRsOoBCons").Data() != nil { classReadInfo := requestData.Search("imdata").Search("mgmtRsOoBCons").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_relation_to_contract_master.go b/internal/provider/resource_aci_relation_to_contract_master.go index 92e526149..e13be6b3e 100644 --- a/internal/provider/resource_aci_relation_to_contract_master.go +++ b/internal/provider/resource_aci_relation_to_contract_master.go @@ -27,12 +27,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvRsSecInheritedResource{} +var _ resource.ResourceWithIdentity = &FvRsSecInheritedResource{} var _ resource.ResourceWithImportState = &FvRsSecInheritedResource{} func NewFvRsSecInheritedResource() resource.Resource { return &FvRsSecInheritedResource{} } +func (r FvRsSecInheritedResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvRsSecInheritedResource defines the resource implementation. type FvRsSecInheritedResource struct { client *client.Client @@ -318,6 +323,7 @@ func (r *FvRsSecInheritedResource) Create(ctx context.Context, req resource.Crea // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_relation_to_contract_master with id '%s'", data.Id.ValueString())) } @@ -342,6 +348,7 @@ func (r *FvRsSecInheritedResource) Read(ctx context.Context, req resource.ReadRe resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_relation_to_contract_master with id '%s'", data.Id.ValueString())) @@ -384,6 +391,7 @@ func (r *FvRsSecInheritedResource) Update(ctx context.Context, req resource.Upda // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_relation_to_contract_master with id '%s'", data.Id.ValueString())) } @@ -412,10 +420,11 @@ func (r *FvRsSecInheritedResource) Delete(ctx context.Context, req resource.Dele func (r *FvRsSecInheritedResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_relation_to_contract_master") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvRsSecInheritedResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_relation_to_contract_master with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_relation_to_contract_master") @@ -424,11 +433,17 @@ func (r *FvRsSecInheritedResource) ImportState(ctx context.Context, req resource func getAndSetFvRsSecInheritedAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvRsSecInheritedResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvRsSecInherited,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvRsSecInheritedResourceModel() - if diags.HasError() { return } + + setFvRsSecInheritedAttributes(ctx, diags, data, requestData) +} + +func setFvRsSecInheritedAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvRsSecInheritedResourceModel, requestData *container.Container) { + + readData := getEmptyFvRsSecInheritedResourceModel() + if requestData.Search("imdata").Search("fvRsSecInherited").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvRsSecInherited").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_relation_to_domain.go b/internal/provider/resource_aci_relation_to_domain.go index b300f9962..9edde85bc 100644 --- a/internal/provider/resource_aci_relation_to_domain.go +++ b/internal/provider/resource_aci_relation_to_domain.go @@ -30,12 +30,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvRsDomAttResource{} +var _ resource.ResourceWithIdentity = &FvRsDomAttResource{} var _ resource.ResourceWithImportState = &FvRsDomAttResource{} func NewFvRsDomAttResource() resource.Resource { return &FvRsDomAttResource{} } +func (r FvRsDomAttResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvRsDomAttResource defines the resource implementation. type FvRsDomAttResource struct { client *client.Client @@ -856,6 +861,7 @@ func (r *FvRsDomAttResource) Create(ctx context.Context, req resource.CreateRequ // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_relation_to_domain with id '%s'", data.Id.ValueString())) } @@ -880,6 +886,7 @@ func (r *FvRsDomAttResource) Read(ctx context.Context, req resource.ReadRequest, resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_relation_to_domain with id '%s'", data.Id.ValueString())) @@ -931,6 +938,7 @@ func (r *FvRsDomAttResource) Update(ctx context.Context, req resource.UpdateRequ // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_relation_to_domain with id '%s'", data.Id.ValueString())) } @@ -959,10 +967,11 @@ func (r *FvRsDomAttResource) Delete(ctx context.Context, req resource.DeleteRequ func (r *FvRsDomAttResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_relation_to_domain") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvRsDomAttResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_relation_to_domain with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_relation_to_domain") @@ -971,11 +980,17 @@ func (r *FvRsDomAttResource) ImportState(ctx context.Context, req resource.Impor func getAndSetFvRsDomAttAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvRsDomAttResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvRsDomAtt,fvUplinkOrderCont,tagAnnotation,tagTag,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvRsDomAttResourceModel() - if diags.HasError() { return } + + setFvRsDomAttAttributes(ctx, diags, data, requestData) +} + +func setFvRsDomAttAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvRsDomAttResourceModel, requestData *container.Container) { + + readData := getEmptyFvRsDomAttResourceModel() + if requestData.Search("imdata").Search("fvRsDomAtt").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvRsDomAtt").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_relation_to_fibre_channel_path.go b/internal/provider/resource_aci_relation_to_fibre_channel_path.go index b6e9398b2..295e781c7 100644 --- a/internal/provider/resource_aci_relation_to_fibre_channel_path.go +++ b/internal/provider/resource_aci_relation_to_fibre_channel_path.go @@ -29,12 +29,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvRsFcPathAttResource{} +var _ resource.ResourceWithIdentity = &FvRsFcPathAttResource{} var _ resource.ResourceWithImportState = &FvRsFcPathAttResource{} func NewFvRsFcPathAttResource() resource.Resource { return &FvRsFcPathAttResource{} } +func (r FvRsFcPathAttResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvRsFcPathAttResource defines the resource implementation. type FvRsFcPathAttResource struct { client *client.Client @@ -356,6 +361,7 @@ func (r *FvRsFcPathAttResource) Create(ctx context.Context, req resource.CreateR // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_relation_to_fibre_channel_path with id '%s'", data.Id.ValueString())) } @@ -380,6 +386,7 @@ func (r *FvRsFcPathAttResource) Read(ctx context.Context, req resource.ReadReque resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_relation_to_fibre_channel_path with id '%s'", data.Id.ValueString())) @@ -422,6 +429,7 @@ func (r *FvRsFcPathAttResource) Update(ctx context.Context, req resource.UpdateR // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_relation_to_fibre_channel_path with id '%s'", data.Id.ValueString())) } @@ -450,10 +458,11 @@ func (r *FvRsFcPathAttResource) Delete(ctx context.Context, req resource.DeleteR func (r *FvRsFcPathAttResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_relation_to_fibre_channel_path") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvRsFcPathAttResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_relation_to_fibre_channel_path with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_relation_to_fibre_channel_path") @@ -462,11 +471,17 @@ func (r *FvRsFcPathAttResource) ImportState(ctx context.Context, req resource.Im func getAndSetFvRsFcPathAttAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvRsFcPathAttResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvRsFcPathAtt,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvRsFcPathAttResourceModel() - if diags.HasError() { return } + + setFvRsFcPathAttAttributes(ctx, diags, data, requestData) +} + +func setFvRsFcPathAttAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvRsFcPathAttResourceModel, requestData *container.Container) { + + readData := getEmptyFvRsFcPathAttResourceModel() + if requestData.Search("imdata").Search("fvRsFcPathAtt").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvRsFcPathAtt").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_relation_to_imported_contract.go b/internal/provider/resource_aci_relation_to_imported_contract.go index 1a0400063..e6a1b9120 100644 --- a/internal/provider/resource_aci_relation_to_imported_contract.go +++ b/internal/provider/resource_aci_relation_to_imported_contract.go @@ -31,12 +31,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvRsConsIfResource{} +var _ resource.ResourceWithIdentity = &FvRsConsIfResource{} var _ resource.ResourceWithImportState = &FvRsConsIfResource{} func NewFvRsConsIfResource() resource.Resource { return &FvRsConsIfResource{} } +func (r FvRsConsIfResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvRsConsIfResource defines the resource implementation. type FvRsConsIfResource struct { client *client.Client @@ -340,6 +345,7 @@ func (r *FvRsConsIfResource) Create(ctx context.Context, req resource.CreateRequ // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_relation_to_imported_contract with id '%s'", data.Id.ValueString())) } @@ -364,6 +370,7 @@ func (r *FvRsConsIfResource) Read(ctx context.Context, req resource.ReadRequest, resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_relation_to_imported_contract with id '%s'", data.Id.ValueString())) @@ -406,6 +413,7 @@ func (r *FvRsConsIfResource) Update(ctx context.Context, req resource.UpdateRequ // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_relation_to_imported_contract with id '%s'", data.Id.ValueString())) } @@ -434,10 +442,11 @@ func (r *FvRsConsIfResource) Delete(ctx context.Context, req resource.DeleteRequ func (r *FvRsConsIfResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_relation_to_imported_contract") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvRsConsIfResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_relation_to_imported_contract with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_relation_to_imported_contract") @@ -446,11 +455,17 @@ func (r *FvRsConsIfResource) ImportState(ctx context.Context, req resource.Impor func getAndSetFvRsConsIfAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvRsConsIfResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvRsConsIf,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvRsConsIfResourceModel() - if diags.HasError() { return } + + setFvRsConsIfAttributes(ctx, diags, data, requestData) +} + +func setFvRsConsIfAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvRsConsIfResourceModel, requestData *container.Container) { + + readData := getEmptyFvRsConsIfResourceModel() + if requestData.Search("imdata").Search("fvRsConsIf").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvRsConsIf").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_relation_to_intra_epg_contract.go b/internal/provider/resource_aci_relation_to_intra_epg_contract.go index dacb20ff6..05d2ca60d 100644 --- a/internal/provider/resource_aci_relation_to_intra_epg_contract.go +++ b/internal/provider/resource_aci_relation_to_intra_epg_contract.go @@ -27,12 +27,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvRsIntraEpgResource{} +var _ resource.ResourceWithIdentity = &FvRsIntraEpgResource{} var _ resource.ResourceWithImportState = &FvRsIntraEpgResource{} func NewFvRsIntraEpgResource() resource.Resource { return &FvRsIntraEpgResource{} } +func (r FvRsIntraEpgResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvRsIntraEpgResource defines the resource implementation. type FvRsIntraEpgResource struct { client *client.Client @@ -318,6 +323,7 @@ func (r *FvRsIntraEpgResource) Create(ctx context.Context, req resource.CreateRe // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_relation_to_intra_epg_contract with id '%s'", data.Id.ValueString())) } @@ -342,6 +348,7 @@ func (r *FvRsIntraEpgResource) Read(ctx context.Context, req resource.ReadReques resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_relation_to_intra_epg_contract with id '%s'", data.Id.ValueString())) @@ -384,6 +391,7 @@ func (r *FvRsIntraEpgResource) Update(ctx context.Context, req resource.UpdateRe // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_relation_to_intra_epg_contract with id '%s'", data.Id.ValueString())) } @@ -412,10 +420,11 @@ func (r *FvRsIntraEpgResource) Delete(ctx context.Context, req resource.DeleteRe func (r *FvRsIntraEpgResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_relation_to_intra_epg_contract") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvRsIntraEpgResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_relation_to_intra_epg_contract with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_relation_to_intra_epg_contract") @@ -424,11 +433,17 @@ func (r *FvRsIntraEpgResource) ImportState(ctx context.Context, req resource.Imp func getAndSetFvRsIntraEpgAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvRsIntraEpgResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvRsIntraEpg,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvRsIntraEpgResourceModel() - if diags.HasError() { return } + + setFvRsIntraEpgAttributes(ctx, diags, data, requestData) +} + +func setFvRsIntraEpgAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvRsIntraEpgResourceModel, requestData *container.Container) { + + readData := getEmptyFvRsIntraEpgResourceModel() + if requestData.Search("imdata").Search("fvRsIntraEpg").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvRsIntraEpg").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_relation_to_ip_sla_track_member.go b/internal/provider/resource_aci_relation_to_ip_sla_track_member.go index f7e26b8df..91691741c 100644 --- a/internal/provider/resource_aci_relation_to_ip_sla_track_member.go +++ b/internal/provider/resource_aci_relation_to_ip_sla_track_member.go @@ -27,12 +27,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvRsOtmListMemberResource{} +var _ resource.ResourceWithIdentity = &FvRsOtmListMemberResource{} var _ resource.ResourceWithImportState = &FvRsOtmListMemberResource{} func NewFvRsOtmListMemberResource() resource.Resource { return &FvRsOtmListMemberResource{} } +func (r FvRsOtmListMemberResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvRsOtmListMemberResource defines the resource implementation. type FvRsOtmListMemberResource struct { client *client.Client @@ -329,6 +334,7 @@ func (r *FvRsOtmListMemberResource) Create(ctx context.Context, req resource.Cre // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_relation_to_ip_sla_track_member with id '%s'", data.Id.ValueString())) } @@ -353,6 +359,7 @@ func (r *FvRsOtmListMemberResource) Read(ctx context.Context, req resource.ReadR resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_relation_to_ip_sla_track_member with id '%s'", data.Id.ValueString())) @@ -395,6 +402,7 @@ func (r *FvRsOtmListMemberResource) Update(ctx context.Context, req resource.Upd // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_relation_to_ip_sla_track_member with id '%s'", data.Id.ValueString())) } @@ -423,10 +431,11 @@ func (r *FvRsOtmListMemberResource) Delete(ctx context.Context, req resource.Del func (r *FvRsOtmListMemberResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_relation_to_ip_sla_track_member") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvRsOtmListMemberResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_relation_to_ip_sla_track_member with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_relation_to_ip_sla_track_member") @@ -435,11 +444,17 @@ func (r *FvRsOtmListMemberResource) ImportState(ctx context.Context, req resourc func getAndSetFvRsOtmListMemberAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvRsOtmListMemberResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvRsOtmListMember,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvRsOtmListMemberResourceModel() - if diags.HasError() { return } + + setFvRsOtmListMemberAttributes(ctx, diags, data, requestData) +} + +func setFvRsOtmListMemberAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvRsOtmListMemberResourceModel, requestData *container.Container) { + + readData := getEmptyFvRsOtmListMemberResourceModel() + if requestData.Search("imdata").Search("fvRsOtmListMember").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvRsOtmListMember").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_relation_to_netflow_exporter.go b/internal/provider/resource_aci_relation_to_netflow_exporter.go index 15244f208..c19ece70b 100644 --- a/internal/provider/resource_aci_relation_to_netflow_exporter.go +++ b/internal/provider/resource_aci_relation_to_netflow_exporter.go @@ -27,12 +27,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &NetflowRsMonitorToExporterResource{} +var _ resource.ResourceWithIdentity = &NetflowRsMonitorToExporterResource{} var _ resource.ResourceWithImportState = &NetflowRsMonitorToExporterResource{} func NewNetflowRsMonitorToExporterResource() resource.Resource { return &NetflowRsMonitorToExporterResource{} } +func (r NetflowRsMonitorToExporterResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // NetflowRsMonitorToExporterResource defines the resource implementation. type NetflowRsMonitorToExporterResource struct { client *client.Client @@ -318,6 +323,7 @@ func (r *NetflowRsMonitorToExporterResource) Create(ctx context.Context, req res // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_relation_to_netflow_exporter with id '%s'", data.Id.ValueString())) } @@ -342,6 +348,7 @@ func (r *NetflowRsMonitorToExporterResource) Read(ctx context.Context, req resou resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_relation_to_netflow_exporter with id '%s'", data.Id.ValueString())) @@ -384,6 +391,7 @@ func (r *NetflowRsMonitorToExporterResource) Update(ctx context.Context, req res // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_relation_to_netflow_exporter with id '%s'", data.Id.ValueString())) } @@ -412,10 +420,11 @@ func (r *NetflowRsMonitorToExporterResource) Delete(ctx context.Context, req res func (r *NetflowRsMonitorToExporterResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_relation_to_netflow_exporter") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *NetflowRsMonitorToExporterResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_relation_to_netflow_exporter with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_relation_to_netflow_exporter") @@ -424,11 +433,17 @@ func (r *NetflowRsMonitorToExporterResource) ImportState(ctx context.Context, re func getAndSetNetflowRsMonitorToExporterAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *NetflowRsMonitorToExporterResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "netflowRsMonitorToExporter,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyNetflowRsMonitorToExporterResourceModel() - if diags.HasError() { return } + + setNetflowRsMonitorToExporterAttributes(ctx, diags, data, requestData) +} + +func setNetflowRsMonitorToExporterAttributes(ctx context.Context, diags *diag.Diagnostics, data *NetflowRsMonitorToExporterResourceModel, requestData *container.Container) { + + readData := getEmptyNetflowRsMonitorToExporterResourceModel() + if requestData.Search("imdata").Search("netflowRsMonitorToExporter").Data() != nil { classReadInfo := requestData.Search("imdata").Search("netflowRsMonitorToExporter").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_relation_to_provided_contract.go b/internal/provider/resource_aci_relation_to_provided_contract.go index c6b46ab1d..93665255e 100644 --- a/internal/provider/resource_aci_relation_to_provided_contract.go +++ b/internal/provider/resource_aci_relation_to_provided_contract.go @@ -31,12 +31,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvRsProvResource{} +var _ resource.ResourceWithIdentity = &FvRsProvResource{} var _ resource.ResourceWithImportState = &FvRsProvResource{} func NewFvRsProvResource() resource.Resource { return &FvRsProvResource{} } +func (r FvRsProvResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvRsProvResource defines the resource implementation. type FvRsProvResource struct { client *client.Client @@ -354,6 +359,7 @@ func (r *FvRsProvResource) Create(ctx context.Context, req resource.CreateReques // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_relation_to_provided_contract with id '%s'", data.Id.ValueString())) } @@ -378,6 +384,7 @@ func (r *FvRsProvResource) Read(ctx context.Context, req resource.ReadRequest, r resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_relation_to_provided_contract with id '%s'", data.Id.ValueString())) @@ -420,6 +427,7 @@ func (r *FvRsProvResource) Update(ctx context.Context, req resource.UpdateReques // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_relation_to_provided_contract with id '%s'", data.Id.ValueString())) } @@ -448,10 +456,11 @@ func (r *FvRsProvResource) Delete(ctx context.Context, req resource.DeleteReques func (r *FvRsProvResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_relation_to_provided_contract") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvRsProvResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_relation_to_provided_contract with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_relation_to_provided_contract") @@ -460,11 +469,17 @@ func (r *FvRsProvResource) ImportState(ctx context.Context, req resource.ImportS func getAndSetFvRsProvAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvRsProvResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvRsProv,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvRsProvResourceModel() - if diags.HasError() { return } + + setFvRsProvAttributes(ctx, diags, data, requestData) +} + +func setFvRsProvAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvRsProvResourceModel, requestData *container.Container) { + + readData := getEmptyFvRsProvResourceModel() + if requestData.Search("imdata").Search("fvRsProv").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvRsProv").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_relation_to_static_leaf.go b/internal/provider/resource_aci_relation_to_static_leaf.go index e16013eea..4f7443b2b 100644 --- a/internal/provider/resource_aci_relation_to_static_leaf.go +++ b/internal/provider/resource_aci_relation_to_static_leaf.go @@ -29,12 +29,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvRsNodeAttResource{} +var _ resource.ResourceWithIdentity = &FvRsNodeAttResource{} var _ resource.ResourceWithImportState = &FvRsNodeAttResource{} func NewFvRsNodeAttResource() resource.Resource { return &FvRsNodeAttResource{} } +func (r FvRsNodeAttResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvRsNodeAttResource defines the resource implementation. type FvRsNodeAttResource struct { client *client.Client @@ -369,6 +374,7 @@ func (r *FvRsNodeAttResource) Create(ctx context.Context, req resource.CreateReq // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_relation_to_static_leaf with id '%s'", data.Id.ValueString())) } @@ -393,6 +399,7 @@ func (r *FvRsNodeAttResource) Read(ctx context.Context, req resource.ReadRequest resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_relation_to_static_leaf with id '%s'", data.Id.ValueString())) @@ -435,6 +442,7 @@ func (r *FvRsNodeAttResource) Update(ctx context.Context, req resource.UpdateReq // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_relation_to_static_leaf with id '%s'", data.Id.ValueString())) } @@ -463,10 +471,11 @@ func (r *FvRsNodeAttResource) Delete(ctx context.Context, req resource.DeleteReq func (r *FvRsNodeAttResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_relation_to_static_leaf") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvRsNodeAttResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_relation_to_static_leaf with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_relation_to_static_leaf") @@ -475,11 +484,17 @@ func (r *FvRsNodeAttResource) ImportState(ctx context.Context, req resource.Impo func getAndSetFvRsNodeAttAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvRsNodeAttResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvRsNodeAtt,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvRsNodeAttResourceModel() - if diags.HasError() { return } + + setFvRsNodeAttAttributes(ctx, diags, data, requestData) +} + +func setFvRsNodeAttAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvRsNodeAttResourceModel, requestData *container.Container) { + + readData := getEmptyFvRsNodeAttResourceModel() + if requestData.Search("imdata").Search("fvRsNodeAtt").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvRsNodeAtt").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_relation_to_static_path.go b/internal/provider/resource_aci_relation_to_static_path.go index e68bddb53..27f72def3 100644 --- a/internal/provider/resource_aci_relation_to_static_path.go +++ b/internal/provider/resource_aci_relation_to_static_path.go @@ -29,12 +29,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvRsPathAttResource{} +var _ resource.ResourceWithIdentity = &FvRsPathAttResource{} var _ resource.ResourceWithImportState = &FvRsPathAttResource{} func NewFvRsPathAttResource() resource.Resource { return &FvRsPathAttResource{} } +func (r FvRsPathAttResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvRsPathAttResource defines the resource implementation. type FvRsPathAttResource struct { client *client.Client @@ -380,6 +385,7 @@ func (r *FvRsPathAttResource) Create(ctx context.Context, req resource.CreateReq // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_relation_to_static_path with id '%s'", data.Id.ValueString())) } @@ -404,6 +410,7 @@ func (r *FvRsPathAttResource) Read(ctx context.Context, req resource.ReadRequest resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_relation_to_static_path with id '%s'", data.Id.ValueString())) @@ -446,6 +453,7 @@ func (r *FvRsPathAttResource) Update(ctx context.Context, req resource.UpdateReq // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_relation_to_static_path with id '%s'", data.Id.ValueString())) } @@ -474,10 +482,11 @@ func (r *FvRsPathAttResource) Delete(ctx context.Context, req resource.DeleteReq func (r *FvRsPathAttResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_relation_to_static_path") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvRsPathAttResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_relation_to_static_path with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_relation_to_static_path") @@ -486,11 +495,17 @@ func (r *FvRsPathAttResource) ImportState(ctx context.Context, req resource.Impo func getAndSetFvRsPathAttAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvRsPathAttResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvRsPathAtt,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvRsPathAttResourceModel() - if diags.HasError() { return } + + setFvRsPathAttAttributes(ctx, diags, data, requestData) +} + +func setFvRsPathAttAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvRsPathAttResourceModel, requestData *container.Container) { + + readData := getEmptyFvRsPathAttResourceModel() + if requestData.Search("imdata").Search("fvRsPathAtt").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvRsPathAtt").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_relation_to_taboo_contract.go b/internal/provider/resource_aci_relation_to_taboo_contract.go index ba6fc72bd..345d2c93d 100644 --- a/internal/provider/resource_aci_relation_to_taboo_contract.go +++ b/internal/provider/resource_aci_relation_to_taboo_contract.go @@ -27,12 +27,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvRsProtByResource{} +var _ resource.ResourceWithIdentity = &FvRsProtByResource{} var _ resource.ResourceWithImportState = &FvRsProtByResource{} func NewFvRsProtByResource() resource.Resource { return &FvRsProtByResource{} } +func (r FvRsProtByResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvRsProtByResource defines the resource implementation. type FvRsProtByResource struct { client *client.Client @@ -318,6 +323,7 @@ func (r *FvRsProtByResource) Create(ctx context.Context, req resource.CreateRequ // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_relation_to_taboo_contract with id '%s'", data.Id.ValueString())) } @@ -342,6 +348,7 @@ func (r *FvRsProtByResource) Read(ctx context.Context, req resource.ReadRequest, resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_relation_to_taboo_contract with id '%s'", data.Id.ValueString())) @@ -384,6 +391,7 @@ func (r *FvRsProtByResource) Update(ctx context.Context, req resource.UpdateRequ // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_relation_to_taboo_contract with id '%s'", data.Id.ValueString())) } @@ -412,10 +420,11 @@ func (r *FvRsProtByResource) Delete(ctx context.Context, req resource.DeleteRequ func (r *FvRsProtByResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_relation_to_taboo_contract") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvRsProtByResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_relation_to_taboo_contract with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_relation_to_taboo_contract") @@ -424,11 +433,17 @@ func (r *FvRsProtByResource) ImportState(ctx context.Context, req resource.Impor func getAndSetFvRsProtByAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvRsProtByResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvRsProtBy,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvRsProtByResourceModel() - if diags.HasError() { return } + + setFvRsProtByAttributes(ctx, diags, data, requestData) +} + +func setFvRsProtByAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvRsProtByResourceModel, requestData *container.Container) { + + readData := getEmptyFvRsProtByResourceModel() + if requestData.Search("imdata").Search("fvRsProtBy").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvRsProtBy").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_relation_to_vrf_fallback_route_group.go b/internal/provider/resource_aci_relation_to_vrf_fallback_route_group.go index 5c7bf3d03..1a6c302b3 100644 --- a/internal/provider/resource_aci_relation_to_vrf_fallback_route_group.go +++ b/internal/provider/resource_aci_relation_to_vrf_fallback_route_group.go @@ -27,12 +27,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &L3extRsOutToFBRGroupResource{} +var _ resource.ResourceWithIdentity = &L3extRsOutToFBRGroupResource{} var _ resource.ResourceWithImportState = &L3extRsOutToFBRGroupResource{} func NewL3extRsOutToFBRGroupResource() resource.Resource { return &L3extRsOutToFBRGroupResource{} } +func (r L3extRsOutToFBRGroupResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // L3extRsOutToFBRGroupResource defines the resource implementation. type L3extRsOutToFBRGroupResource struct { client *client.Client @@ -318,6 +323,7 @@ func (r *L3extRsOutToFBRGroupResource) Create(ctx context.Context, req resource. // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_relation_to_vrf_fallback_route_group with id '%s'", data.Id.ValueString())) } @@ -342,6 +348,7 @@ func (r *L3extRsOutToFBRGroupResource) Read(ctx context.Context, req resource.Re resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_relation_to_vrf_fallback_route_group with id '%s'", data.Id.ValueString())) @@ -384,6 +391,7 @@ func (r *L3extRsOutToFBRGroupResource) Update(ctx context.Context, req resource. // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_relation_to_vrf_fallback_route_group with id '%s'", data.Id.ValueString())) } @@ -412,10 +420,11 @@ func (r *L3extRsOutToFBRGroupResource) Delete(ctx context.Context, req resource. func (r *L3extRsOutToFBRGroupResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_relation_to_vrf_fallback_route_group") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *L3extRsOutToFBRGroupResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_relation_to_vrf_fallback_route_group with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_relation_to_vrf_fallback_route_group") @@ -424,11 +433,17 @@ func (r *L3extRsOutToFBRGroupResource) ImportState(ctx context.Context, req reso func getAndSetL3extRsOutToFBRGroupAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *L3extRsOutToFBRGroupResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "l3extRsOutToFBRGroup,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyL3extRsOutToFBRGroupResourceModel() - if diags.HasError() { return } + + setL3extRsOutToFBRGroupAttributes(ctx, diags, data, requestData) +} + +func setL3extRsOutToFBRGroupAttributes(ctx context.Context, diags *diag.Diagnostics, data *L3extRsOutToFBRGroupResourceModel, requestData *container.Container) { + + readData := getEmptyL3extRsOutToFBRGroupResourceModel() + if requestData.Search("imdata").Search("l3extRsOutToFBRGroup").Data() != nil { classReadInfo := requestData.Search("imdata").Search("l3extRsOutToFBRGroup").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_remote_site.go b/internal/provider/resource_aci_remote_site.go index 83a345f4d..262d1e35c 100644 --- a/internal/provider/resource_aci_remote_site.go +++ b/internal/provider/resource_aci_remote_site.go @@ -27,12 +27,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvRemoteIdResource{} +var _ resource.ResourceWithIdentity = &FvRemoteIdResource{} var _ resource.ResourceWithImportState = &FvRemoteIdResource{} func NewFvRemoteIdResource() resource.Resource { return &FvRemoteIdResource{} } +func (r FvRemoteIdResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvRemoteIdResource defines the resource implementation. type FvRemoteIdResource struct { client *client.Client @@ -395,6 +400,7 @@ func (r *FvRemoteIdResource) Create(ctx context.Context, req resource.CreateRequ // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_remote_site with id '%s'", data.Id.ValueString())) } @@ -419,6 +425,7 @@ func (r *FvRemoteIdResource) Read(ctx context.Context, req resource.ReadRequest, resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_remote_site with id '%s'", data.Id.ValueString())) @@ -461,6 +468,7 @@ func (r *FvRemoteIdResource) Update(ctx context.Context, req resource.UpdateRequ // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_remote_site with id '%s'", data.Id.ValueString())) } @@ -489,10 +497,11 @@ func (r *FvRemoteIdResource) Delete(ctx context.Context, req resource.DeleteRequ func (r *FvRemoteIdResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_remote_site") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvRemoteIdResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_remote_site with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_remote_site") @@ -501,11 +510,17 @@ func (r *FvRemoteIdResource) ImportState(ctx context.Context, req resource.Impor func getAndSetFvRemoteIdAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvRemoteIdResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvRemoteId,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvRemoteIdResourceModel() - if diags.HasError() { return } + + setFvRemoteIdAttributes(ctx, diags, data, requestData) +} + +func setFvRemoteIdAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvRemoteIdResourceModel, requestData *container.Container) { + + readData := getEmptyFvRemoteIdResourceModel() + if requestData.Search("imdata").Search("fvRemoteId").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvRemoteId").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_rogue_coop_exception.go b/internal/provider/resource_aci_rogue_coop_exception.go index fa8717534..68e29a879 100644 --- a/internal/provider/resource_aci_rogue_coop_exception.go +++ b/internal/provider/resource_aci_rogue_coop_exception.go @@ -27,12 +27,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvRogueExceptionMacResource{} +var _ resource.ResourceWithIdentity = &FvRogueExceptionMacResource{} var _ resource.ResourceWithImportState = &FvRogueExceptionMacResource{} func NewFvRogueExceptionMacResource() resource.Resource { return &FvRogueExceptionMacResource{} } +func (r FvRogueExceptionMacResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvRogueExceptionMacResource defines the resource implementation. type FvRogueExceptionMacResource struct { client *client.Client @@ -351,6 +356,7 @@ func (r *FvRogueExceptionMacResource) Create(ctx context.Context, req resource.C // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_rogue_coop_exception with id '%s'", data.Id.ValueString())) } @@ -375,6 +381,7 @@ func (r *FvRogueExceptionMacResource) Read(ctx context.Context, req resource.Rea resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_rogue_coop_exception with id '%s'", data.Id.ValueString())) @@ -417,6 +424,7 @@ func (r *FvRogueExceptionMacResource) Update(ctx context.Context, req resource.U // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_rogue_coop_exception with id '%s'", data.Id.ValueString())) } @@ -445,10 +453,11 @@ func (r *FvRogueExceptionMacResource) Delete(ctx context.Context, req resource.D func (r *FvRogueExceptionMacResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_rogue_coop_exception") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvRogueExceptionMacResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_rogue_coop_exception with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_rogue_coop_exception") @@ -457,11 +466,17 @@ func (r *FvRogueExceptionMacResource) ImportState(ctx context.Context, req resou func getAndSetFvRogueExceptionMacAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvRogueExceptionMacResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvRogueExceptionMac,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvRogueExceptionMacResourceModel() - if diags.HasError() { return } + + setFvRogueExceptionMacAttributes(ctx, diags, data, requestData) +} + +func setFvRogueExceptionMacAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvRogueExceptionMacResourceModel, requestData *container.Container) { + + readData := getEmptyFvRogueExceptionMacResourceModel() + if requestData.Search("imdata").Search("fvRogueExceptionMac").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvRogueExceptionMac").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_route_control_profile.go b/internal/provider/resource_aci_route_control_profile.go index b2ca6d34a..28da71987 100644 --- a/internal/provider/resource_aci_route_control_profile.go +++ b/internal/provider/resource_aci_route_control_profile.go @@ -29,12 +29,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &RtctrlProfileResource{} +var _ resource.ResourceWithIdentity = &RtctrlProfileResource{} var _ resource.ResourceWithImportState = &RtctrlProfileResource{} func NewRtctrlProfileResource() resource.Resource { return &RtctrlProfileResource{} } +func (r RtctrlProfileResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // RtctrlProfileResource defines the resource implementation. type RtctrlProfileResource struct { client *client.Client @@ -393,6 +398,7 @@ func (r *RtctrlProfileResource) Create(ctx context.Context, req resource.CreateR // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_route_control_profile with id '%s'", data.Id.ValueString())) } @@ -417,6 +423,7 @@ func (r *RtctrlProfileResource) Read(ctx context.Context, req resource.ReadReque resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_route_control_profile with id '%s'", data.Id.ValueString())) @@ -459,6 +466,7 @@ func (r *RtctrlProfileResource) Update(ctx context.Context, req resource.UpdateR // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_route_control_profile with id '%s'", data.Id.ValueString())) } @@ -487,10 +495,11 @@ func (r *RtctrlProfileResource) Delete(ctx context.Context, req resource.DeleteR func (r *RtctrlProfileResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_route_control_profile") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *RtctrlProfileResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_route_control_profile with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_route_control_profile") @@ -499,11 +508,17 @@ func (r *RtctrlProfileResource) ImportState(ctx context.Context, req resource.Im func getAndSetRtctrlProfileAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *RtctrlProfileResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "rtctrlProfile,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyRtctrlProfileResourceModel() - if diags.HasError() { return } + + setRtctrlProfileAttributes(ctx, diags, data, requestData) +} + +func setRtctrlProfileAttributes(ctx context.Context, diags *diag.Diagnostics, data *RtctrlProfileResourceModel, requestData *container.Container) { + + readData := getEmptyRtctrlProfileResourceModel() + if requestData.Search("imdata").Search("rtctrlProfile").Data() != nil { classReadInfo := requestData.Search("imdata").Search("rtctrlProfile").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_spine_access_port_selector.go b/internal/provider/resource_aci_spine_access_port_selector.go index c8aaf938f..ec4f143bd 100644 --- a/internal/provider/resource_aci_spine_access_port_selector.go +++ b/internal/provider/resource_aci_spine_access_port_selector.go @@ -30,12 +30,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &InfraSHPortSResource{} +var _ resource.ResourceWithIdentity = &InfraSHPortSResource{} var _ resource.ResourceWithImportState = &InfraSHPortSResource{} func NewInfraSHPortSResource() resource.Resource { return &InfraSHPortSResource{} } +func (r InfraSHPortSResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // InfraSHPortSResource defines the resource implementation. type InfraSHPortSResource struct { client *client.Client @@ -815,6 +820,7 @@ func (r *InfraSHPortSResource) Create(ctx context.Context, req resource.CreateRe // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_spine_access_port_selector with id '%s'", data.Id.ValueString())) } @@ -839,6 +845,7 @@ func (r *InfraSHPortSResource) Read(ctx context.Context, req resource.ReadReques resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_spine_access_port_selector with id '%s'", data.Id.ValueString())) @@ -884,6 +891,7 @@ func (r *InfraSHPortSResource) Update(ctx context.Context, req resource.UpdateRe // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_spine_access_port_selector with id '%s'", data.Id.ValueString())) } @@ -912,10 +920,11 @@ func (r *InfraSHPortSResource) Delete(ctx context.Context, req resource.DeleteRe func (r *InfraSHPortSResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_spine_access_port_selector") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *InfraSHPortSResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_spine_access_port_selector with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_spine_access_port_selector") @@ -924,11 +933,17 @@ func (r *InfraSHPortSResource) ImportState(ctx context.Context, req resource.Imp func getAndSetInfraSHPortSAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *InfraSHPortSResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "infraSHPortS,infraRsSpAccGrp,tagAnnotation,tagTag,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyInfraSHPortSResourceModel() - if diags.HasError() { return } + + setInfraSHPortSAttributes(ctx, diags, data, requestData) +} + +func setInfraSHPortSAttributes(ctx context.Context, diags *diag.Diagnostics, data *InfraSHPortSResourceModel, requestData *container.Container) { + + readData := getEmptyInfraSHPortSResourceModel() + if requestData.Search("imdata").Search("infraSHPortS").Data() != nil { classReadInfo := requestData.Search("imdata").Search("infraSHPortS").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_spine_interface_profile.go b/internal/provider/resource_aci_spine_interface_profile.go index 08082d211..537b553b2 100644 --- a/internal/provider/resource_aci_spine_interface_profile.go +++ b/internal/provider/resource_aci_spine_interface_profile.go @@ -28,12 +28,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &InfraSpAccPortPResource{} +var _ resource.ResourceWithIdentity = &InfraSpAccPortPResource{} var _ resource.ResourceWithImportState = &InfraSpAccPortPResource{} func NewInfraSpAccPortPResource() resource.Resource { return &InfraSpAccPortPResource{} } +func (r InfraSpAccPortPResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // InfraSpAccPortPResource defines the resource implementation. type InfraSpAccPortPResource struct { client *client.Client @@ -354,6 +359,7 @@ func (r *InfraSpAccPortPResource) Create(ctx context.Context, req resource.Creat // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_spine_interface_profile with id '%s'", data.Id.ValueString())) } @@ -378,6 +384,7 @@ func (r *InfraSpAccPortPResource) Read(ctx context.Context, req resource.ReadReq resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_spine_interface_profile with id '%s'", data.Id.ValueString())) @@ -420,6 +427,7 @@ func (r *InfraSpAccPortPResource) Update(ctx context.Context, req resource.Updat // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_spine_interface_profile with id '%s'", data.Id.ValueString())) } @@ -448,10 +456,11 @@ func (r *InfraSpAccPortPResource) Delete(ctx context.Context, req resource.Delet func (r *InfraSpAccPortPResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_spine_interface_profile") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *InfraSpAccPortPResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_spine_interface_profile with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_spine_interface_profile") @@ -460,11 +469,17 @@ func (r *InfraSpAccPortPResource) ImportState(ctx context.Context, req resource. func getAndSetInfraSpAccPortPAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *InfraSpAccPortPResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "infraSpAccPortP,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyInfraSpAccPortPResourceModel() - if diags.HasError() { return } + + setInfraSpAccPortPAttributes(ctx, diags, data, requestData) +} + +func setInfraSpAccPortPAttributes(ctx context.Context, diags *diag.Diagnostics, data *InfraSpAccPortPResourceModel, requestData *container.Container) { + + readData := getEmptyInfraSpAccPortPResourceModel() + if requestData.Search("imdata").Search("infraSpAccPortP").Data() != nil { classReadInfo := requestData.Search("imdata").Search("infraSpAccPortP").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_taboo_contract.go b/internal/provider/resource_aci_taboo_contract.go index 83b03ae09..4290a2046 100644 --- a/internal/provider/resource_aci_taboo_contract.go +++ b/internal/provider/resource_aci_taboo_contract.go @@ -29,12 +29,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &VzTabooResource{} +var _ resource.ResourceWithIdentity = &VzTabooResource{} var _ resource.ResourceWithImportState = &VzTabooResource{} func NewVzTabooResource() resource.Resource { return &VzTabooResource{} } +func (r VzTabooResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // VzTabooResource defines the resource implementation. type VzTabooResource struct { client *client.Client @@ -506,6 +511,7 @@ func (r *VzTabooResource) Create(ctx context.Context, req resource.CreateRequest // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_taboo_contract with id '%s'", data.Id.ValueString())) } @@ -530,6 +536,7 @@ func (r *VzTabooResource) Read(ctx context.Context, req resource.ReadRequest, re resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_taboo_contract with id '%s'", data.Id.ValueString())) @@ -572,6 +579,7 @@ func (r *VzTabooResource) Update(ctx context.Context, req resource.UpdateRequest // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_taboo_contract with id '%s'", data.Id.ValueString())) } @@ -600,10 +608,11 @@ func (r *VzTabooResource) Delete(ctx context.Context, req resource.DeleteRequest func (r *VzTabooResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_taboo_contract") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *VzTabooResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_taboo_contract with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_taboo_contract") @@ -612,11 +621,17 @@ func (r *VzTabooResource) ImportState(ctx context.Context, req resource.ImportSt func getAndSetVzTabooAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *VzTabooResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "vzTaboo,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyVzTabooResourceModel() - if diags.HasError() { return } + + setVzTabooAttributes(ctx, diags, data, requestData) +} + +func setVzTabooAttributes(ctx context.Context, diags *diag.Diagnostics, data *VzTabooResourceModel, requestData *container.Container) { + + readData := getEmptyVzTabooResourceModel() + if requestData.Search("imdata").Search("vzTaboo").Data() != nil { classReadInfo := requestData.Search("imdata").Search("vzTaboo").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_taboo_contract_subject.go b/internal/provider/resource_aci_taboo_contract_subject.go index bca3bede9..a33342db8 100644 --- a/internal/provider/resource_aci_taboo_contract_subject.go +++ b/internal/provider/resource_aci_taboo_contract_subject.go @@ -31,12 +31,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &VzTSubjResource{} +var _ resource.ResourceWithIdentity = &VzTSubjResource{} var _ resource.ResourceWithImportState = &VzTSubjResource{} func NewVzTSubjResource() resource.Resource { return &VzTSubjResource{} } +func (r VzTSubjResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // VzTSubjResource defines the resource implementation. type VzTSubjResource struct { client *client.Client @@ -564,6 +569,7 @@ func (r *VzTSubjResource) Create(ctx context.Context, req resource.CreateRequest // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_taboo_contract_subject with id '%s'", data.Id.ValueString())) } @@ -588,6 +594,7 @@ func (r *VzTSubjResource) Read(ctx context.Context, req resource.ReadRequest, re resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_taboo_contract_subject with id '%s'", data.Id.ValueString())) @@ -633,6 +640,7 @@ func (r *VzTSubjResource) Update(ctx context.Context, req resource.UpdateRequest // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_taboo_contract_subject with id '%s'", data.Id.ValueString())) } @@ -661,10 +669,11 @@ func (r *VzTSubjResource) Delete(ctx context.Context, req resource.DeleteRequest func (r *VzTSubjResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_taboo_contract_subject") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *VzTSubjResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_taboo_contract_subject with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_taboo_contract_subject") @@ -673,11 +682,17 @@ func (r *VzTSubjResource) ImportState(ctx context.Context, req resource.ImportSt func getAndSetVzTSubjAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *VzTSubjResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "vzTSubj,tagAnnotation,tagTag,vzRsDenyRule,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyVzTSubjResourceModel() - if diags.HasError() { return } + + setVzTSubjAttributes(ctx, diags, data, requestData) +} + +func setVzTSubjAttributes(ctx context.Context, diags *diag.Diagnostics, data *VzTSubjResourceModel, requestData *container.Container) { + + readData := getEmptyVzTSubjResourceModel() + if requestData.Search("imdata").Search("vzTSubj").Data() != nil { classReadInfo := requestData.Search("imdata").Search("vzTSubj").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_tag.go b/internal/provider/resource_aci_tag.go index d8fb61eaf..6e231ccfe 100644 --- a/internal/provider/resource_aci_tag.go +++ b/internal/provider/resource_aci_tag.go @@ -24,12 +24,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &TagTagResource{} +var _ resource.ResourceWithIdentity = &TagTagResource{} var _ resource.ResourceWithImportState = &TagTagResource{} func NewTagTagResource() resource.Resource { return &TagTagResource{} } +func (r TagTagResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // TagTagResource defines the resource implementation. type TagTagResource struct { client *client.Client @@ -188,6 +193,7 @@ func (r *TagTagResource) Create(ctx context.Context, req resource.CreateRequest, // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_tag with id '%s'", data.Id.ValueString())) } @@ -212,6 +218,7 @@ func (r *TagTagResource) Read(ctx context.Context, req resource.ReadRequest, res resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_tag with id '%s'", data.Id.ValueString())) @@ -246,6 +253,7 @@ func (r *TagTagResource) Update(ctx context.Context, req resource.UpdateRequest, // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_tag with id '%s'", data.Id.ValueString())) } @@ -274,10 +282,11 @@ func (r *TagTagResource) Delete(ctx context.Context, req resource.DeleteRequest, func (r *TagTagResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_tag") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *TagTagResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_tag with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_tag") @@ -286,11 +295,17 @@ func (r *TagTagResource) ImportState(ctx context.Context, req resource.ImportSta func getAndSetTagTagAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *TagTagResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "GET", nil) - readData := getEmptyTagTagResourceModel() - if diags.HasError() { return } + + setTagTagAttributes(ctx, diags, data, requestData) +} + +func setTagTagAttributes(ctx context.Context, diags *diag.Diagnostics, data *TagTagResourceModel, requestData *container.Container) { + + readData := getEmptyTagTagResourceModel() + if requestData.Search("imdata").Search("tagTag").Data() != nil { classReadInfo := requestData.Search("imdata").Search("tagTag").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_tenant.go b/internal/provider/resource_aci_tenant.go index 3bd248b10..37598c97c 100644 --- a/internal/provider/resource_aci_tenant.go +++ b/internal/provider/resource_aci_tenant.go @@ -31,12 +31,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvTenantResource{} +var _ resource.ResourceWithIdentity = &FvTenantResource{} var _ resource.ResourceWithImportState = &FvTenantResource{} func NewFvTenantResource() resource.Resource { return &FvTenantResource{} } +func (r FvTenantResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvTenantResource defines the resource implementation. type FvTenantResource struct { client *client.Client @@ -742,6 +747,7 @@ func (r *FvTenantResource) Create(ctx context.Context, req resource.CreateReques // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_tenant with id '%s'", data.Id.ValueString())) } @@ -766,6 +772,7 @@ func (r *FvTenantResource) Read(ctx context.Context, req resource.ReadRequest, r resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_tenant with id '%s'", data.Id.ValueString())) @@ -817,6 +824,7 @@ func (r *FvTenantResource) Update(ctx context.Context, req resource.UpdateReques // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_tenant with id '%s'", data.Id.ValueString())) } @@ -845,10 +853,11 @@ func (r *FvTenantResource) Delete(ctx context.Context, req resource.DeleteReques func (r *FvTenantResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_tenant") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvTenantResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_tenant with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_tenant") @@ -857,11 +866,17 @@ func (r *FvTenantResource) ImportState(ctx context.Context, req resource.ImportS func getAndSetFvTenantAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvTenantResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvTenant,fvRsTenantMonPol,tagAnnotation,tagTag,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvTenantResourceModel() - if diags.HasError() { return } + + setFvTenantAttributes(ctx, diags, data, requestData) +} + +func setFvTenantAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvTenantResourceModel, requestData *container.Container) { + + readData := getEmptyFvTenantResourceModel() + if requestData.Search("imdata").Search("fvTenant").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvTenant").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_trust_control_policy.go b/internal/provider/resource_aci_trust_control_policy.go index 8203f4d1a..6cab789e5 100644 --- a/internal/provider/resource_aci_trust_control_policy.go +++ b/internal/provider/resource_aci_trust_control_policy.go @@ -29,12 +29,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FhsTrustCtrlPolResource{} +var _ resource.ResourceWithIdentity = &FhsTrustCtrlPolResource{} var _ resource.ResourceWithImportState = &FhsTrustCtrlPolResource{} func NewFhsTrustCtrlPolResource() resource.Resource { return &FhsTrustCtrlPolResource{} } +func (r FhsTrustCtrlPolResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FhsTrustCtrlPolResource defines the resource implementation. type FhsTrustCtrlPolResource struct { client *client.Client @@ -448,6 +453,7 @@ func (r *FhsTrustCtrlPolResource) Create(ctx context.Context, req resource.Creat // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_trust_control_policy with id '%s'", data.Id.ValueString())) } @@ -472,6 +478,7 @@ func (r *FhsTrustCtrlPolResource) Read(ctx context.Context, req resource.ReadReq resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_trust_control_policy with id '%s'", data.Id.ValueString())) @@ -514,6 +521,7 @@ func (r *FhsTrustCtrlPolResource) Update(ctx context.Context, req resource.Updat // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_trust_control_policy with id '%s'", data.Id.ValueString())) } @@ -542,10 +550,11 @@ func (r *FhsTrustCtrlPolResource) Delete(ctx context.Context, req resource.Delet func (r *FhsTrustCtrlPolResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_trust_control_policy") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FhsTrustCtrlPolResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_trust_control_policy with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_trust_control_policy") @@ -554,11 +563,17 @@ func (r *FhsTrustCtrlPolResource) ImportState(ctx context.Context, req resource. func getAndSetFhsTrustCtrlPolAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FhsTrustCtrlPolResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fhsTrustCtrlPol,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFhsTrustCtrlPolResourceModel() - if diags.HasError() { return } + + setFhsTrustCtrlPolAttributes(ctx, diags, data, requestData) +} + +func setFhsTrustCtrlPolAttributes(ctx context.Context, diags *diag.Diagnostics, data *FhsTrustCtrlPolResourceModel, requestData *container.Container) { + + readData := getEmptyFhsTrustCtrlPolResourceModel() + if requestData.Search("imdata").Search("fhsTrustCtrlPol").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fhsTrustCtrlPol").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_vmm_credential.go b/internal/provider/resource_aci_vmm_credential.go index 5dff6a6b6..73506bc23 100644 --- a/internal/provider/resource_aci_vmm_credential.go +++ b/internal/provider/resource_aci_vmm_credential.go @@ -29,12 +29,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &VmmUsrAccPResource{} +var _ resource.ResourceWithIdentity = &VmmUsrAccPResource{} var _ resource.ResourceWithImportState = &VmmUsrAccPResource{} func NewVmmUsrAccPResource() resource.Resource { return &VmmUsrAccPResource{} } +func (r VmmUsrAccPResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // VmmUsrAccPResource defines the resource implementation. type VmmUsrAccPResource struct { client *client.Client @@ -600,6 +605,7 @@ func (r *VmmUsrAccPResource) Create(ctx context.Context, req resource.CreateRequ // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_vmm_credential with id '%s'", data.Id.ValueString())) } @@ -624,6 +630,7 @@ func (r *VmmUsrAccPResource) Read(ctx context.Context, req resource.ReadRequest, resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_vmm_credential with id '%s'", data.Id.ValueString())) @@ -666,6 +673,7 @@ func (r *VmmUsrAccPResource) Update(ctx context.Context, req resource.UpdateRequ // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_vmm_credential with id '%s'", data.Id.ValueString())) } @@ -694,10 +702,11 @@ func (r *VmmUsrAccPResource) Delete(ctx context.Context, req resource.DeleteRequ func (r *VmmUsrAccPResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_vmm_credential") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *VmmUsrAccPResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_vmm_credential with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_vmm_credential") @@ -706,11 +715,17 @@ func (r *VmmUsrAccPResource) ImportState(ctx context.Context, req resource.Impor func getAndSetVmmUsrAccPAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *VmmUsrAccPResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "vmmUsrAccP,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyVmmUsrAccPResourceModel() - if diags.HasError() { return } + + setVmmUsrAccPAttributes(ctx, diags, data, requestData) +} + +func setVmmUsrAccPAttributes(ctx context.Context, diags *diag.Diagnostics, data *VmmUsrAccPResourceModel, requestData *container.Container) { + + readData := getEmptyVmmUsrAccPResourceModel() + if requestData.Search("imdata").Search("vmmUsrAccP").Data() != nil { classReadInfo := requestData.Search("imdata").Search("vmmUsrAccP").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_vmm_uplink_container.go b/internal/provider/resource_aci_vmm_uplink_container.go index b33831a01..ec714e818 100644 --- a/internal/provider/resource_aci_vmm_uplink_container.go +++ b/internal/provider/resource_aci_vmm_uplink_container.go @@ -27,12 +27,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &VmmUplinkPContResource{} +var _ resource.ResourceWithIdentity = &VmmUplinkPContResource{} var _ resource.ResourceWithImportState = &VmmUplinkPContResource{} func NewVmmUplinkPContResource() resource.Resource { return &VmmUplinkPContResource{} } +func (r VmmUplinkPContResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // VmmUplinkPContResource defines the resource implementation. type VmmUplinkPContResource struct { client *client.Client @@ -552,6 +557,7 @@ func (r *VmmUplinkPContResource) Create(ctx context.Context, req resource.Create // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_vmm_uplink_container with id '%s'", data.Id.ValueString())) } @@ -576,6 +582,7 @@ func (r *VmmUplinkPContResource) Read(ctx context.Context, req resource.ReadRequ resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_vmm_uplink_container with id '%s'", data.Id.ValueString())) @@ -621,6 +628,7 @@ func (r *VmmUplinkPContResource) Update(ctx context.Context, req resource.Update // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_vmm_uplink_container with id '%s'", data.Id.ValueString())) } @@ -649,10 +657,11 @@ func (r *VmmUplinkPContResource) Delete(ctx context.Context, req resource.Delete func (r *VmmUplinkPContResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_vmm_uplink_container") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *VmmUplinkPContResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_vmm_uplink_container with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_vmm_uplink_container") @@ -661,11 +670,17 @@ func (r *VmmUplinkPContResource) ImportState(ctx context.Context, req resource.I func getAndSetVmmUplinkPContAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *VmmUplinkPContResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "vmmUplinkPCont,tagAnnotation,tagTag,vmmUplinkP,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyVmmUplinkPContResourceModel() - if diags.HasError() { return } + + setVmmUplinkPContAttributes(ctx, diags, data, requestData) +} + +func setVmmUplinkPContAttributes(ctx context.Context, diags *diag.Diagnostics, data *VmmUplinkPContResourceModel, requestData *container.Container) { + + readData := getEmptyVmmUplinkPContResourceModel() + if requestData.Search("imdata").Search("vmmUplinkPCont").Data() != nil { classReadInfo := requestData.Search("imdata").Search("vmmUplinkPCont").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_vmm_uplink_policy.go b/internal/provider/resource_aci_vmm_uplink_policy.go index 1ea647f11..e0af2ded7 100644 --- a/internal/provider/resource_aci_vmm_uplink_policy.go +++ b/internal/provider/resource_aci_vmm_uplink_policy.go @@ -27,12 +27,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &VmmUplinkPResource{} +var _ resource.ResourceWithIdentity = &VmmUplinkPResource{} var _ resource.ResourceWithImportState = &VmmUplinkPResource{} func NewVmmUplinkPResource() resource.Resource { return &VmmUplinkPResource{} } +func (r VmmUplinkPResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // VmmUplinkPResource defines the resource implementation. type VmmUplinkPResource struct { client *client.Client @@ -339,6 +344,7 @@ func (r *VmmUplinkPResource) Create(ctx context.Context, req resource.CreateRequ // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_vmm_uplink_policy with id '%s'", data.Id.ValueString())) } @@ -363,6 +369,7 @@ func (r *VmmUplinkPResource) Read(ctx context.Context, req resource.ReadRequest, resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_vmm_uplink_policy with id '%s'", data.Id.ValueString())) @@ -405,6 +412,7 @@ func (r *VmmUplinkPResource) Update(ctx context.Context, req resource.UpdateRequ // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_vmm_uplink_policy with id '%s'", data.Id.ValueString())) } @@ -433,10 +441,11 @@ func (r *VmmUplinkPResource) Delete(ctx context.Context, req resource.DeleteRequ func (r *VmmUplinkPResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_vmm_uplink_policy") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *VmmUplinkPResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_vmm_uplink_policy with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_vmm_uplink_policy") @@ -445,11 +454,17 @@ func (r *VmmUplinkPResource) ImportState(ctx context.Context, req resource.Impor func getAndSetVmmUplinkPAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *VmmUplinkPResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "vmmUplinkP,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyVmmUplinkPResourceModel() - if diags.HasError() { return } + + setVmmUplinkPAttributes(ctx, diags, data, requestData) +} + +func setVmmUplinkPAttributes(ctx context.Context, diags *diag.Diagnostics, data *VmmUplinkPResourceModel, requestData *container.Container) { + + readData := getEmptyVmmUplinkPResourceModel() + if requestData.Search("imdata").Search("vmmUplinkP").Data() != nil { classReadInfo := requestData.Search("imdata").Search("vmmUplinkP").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_vrf.go b/internal/provider/resource_aci_vrf.go index 7fd503e70..713cd76f9 100644 --- a/internal/provider/resource_aci_vrf.go +++ b/internal/provider/resource_aci_vrf.go @@ -30,12 +30,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvCtxResource{} +var _ resource.ResourceWithIdentity = &FvCtxResource{} var _ resource.ResourceWithImportState = &FvCtxResource{} func NewFvCtxResource() resource.Resource { return &FvCtxResource{} } +func (r FvCtxResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvCtxResource defines the resource implementation. type FvCtxResource struct { client *client.Client @@ -3519,6 +3524,7 @@ func (r *FvCtxResource) Create(ctx context.Context, req resource.CreateRequest, // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_vrf with id '%s'", data.Id.ValueString())) } @@ -3543,6 +3549,7 @@ func (r *FvCtxResource) Read(ctx context.Context, req resource.ReadRequest, resp resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_vrf with id '%s'", data.Id.ValueString())) @@ -3636,6 +3643,7 @@ func (r *FvCtxResource) Update(ctx context.Context, req resource.UpdateRequest, // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_vrf with id '%s'", data.Id.ValueString())) } @@ -3664,10 +3672,11 @@ func (r *FvCtxResource) Delete(ctx context.Context, req resource.DeleteRequest, func (r *FvCtxResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_vrf") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvCtxResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_vrf with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_vrf") @@ -3676,11 +3685,17 @@ func (r *FvCtxResource) ImportState(ctx context.Context, req resource.ImportStat func getAndSetFvCtxAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvCtxResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvCtx,fvRsBgpCtxPol,fvRsCtxMonPol,fvRsCtxToBgpCtxAfPol,fvRsCtxToEigrpCtxAfPol,fvRsCtxToEpRet,fvRsCtxToExtRouteTagPol,fvRsCtxToOspfCtxPol,fvRsCtxToSDWanVpn,fvRsOspfCtxPol,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvCtxResourceModel() - if diags.HasError() { return } + + setFvCtxAttributes(ctx, diags, data, requestData) +} + +func setFvCtxAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvCtxResourceModel, requestData *container.Container) { + + readData := getEmptyFvCtxResourceModel() + if requestData.Search("imdata").Search("fvCtx").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvCtx").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_vrf_fallback_route.go b/internal/provider/resource_aci_vrf_fallback_route.go index e9673b24e..ba4b52702 100644 --- a/internal/provider/resource_aci_vrf_fallback_route.go +++ b/internal/provider/resource_aci_vrf_fallback_route.go @@ -27,12 +27,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvFBRouteResource{} +var _ resource.ResourceWithIdentity = &FvFBRouteResource{} var _ resource.ResourceWithImportState = &FvFBRouteResource{} func NewFvFBRouteResource() resource.Resource { return &FvFBRouteResource{} } +func (r FvFBRouteResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvFBRouteResource defines the resource implementation. type FvFBRouteResource struct { client *client.Client @@ -351,6 +356,7 @@ func (r *FvFBRouteResource) Create(ctx context.Context, req resource.CreateReque // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_vrf_fallback_route with id '%s'", data.Id.ValueString())) } @@ -375,6 +381,7 @@ func (r *FvFBRouteResource) Read(ctx context.Context, req resource.ReadRequest, resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_vrf_fallback_route with id '%s'", data.Id.ValueString())) @@ -417,6 +424,7 @@ func (r *FvFBRouteResource) Update(ctx context.Context, req resource.UpdateReque // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_vrf_fallback_route with id '%s'", data.Id.ValueString())) } @@ -445,10 +453,11 @@ func (r *FvFBRouteResource) Delete(ctx context.Context, req resource.DeleteReque func (r *FvFBRouteResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_vrf_fallback_route") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvFBRouteResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_vrf_fallback_route with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_vrf_fallback_route") @@ -457,11 +466,17 @@ func (r *FvFBRouteResource) ImportState(ctx context.Context, req resource.Import func getAndSetFvFBRouteAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvFBRouteResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvFBRoute,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvFBRouteResourceModel() - if diags.HasError() { return } + + setFvFBRouteAttributes(ctx, diags, data, requestData) +} + +func setFvFBRouteAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvFBRouteResourceModel, requestData *container.Container) { + + readData := getEmptyFvFBRouteResourceModel() + if requestData.Search("imdata").Search("fvFBRoute").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvFBRoute").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_vrf_fallback_route_group.go b/internal/provider/resource_aci_vrf_fallback_route_group.go index 042dc119e..793e9ea98 100644 --- a/internal/provider/resource_aci_vrf_fallback_route_group.go +++ b/internal/provider/resource_aci_vrf_fallback_route_group.go @@ -29,12 +29,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvFBRGroupResource{} +var _ resource.ResourceWithIdentity = &FvFBRGroupResource{} var _ resource.ResourceWithImportState = &FvFBRGroupResource{} func NewFvFBRGroupResource() resource.Resource { return &FvFBRGroupResource{} } +func (r FvFBRGroupResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvFBRGroupResource defines the resource implementation. type FvFBRGroupResource struct { client *client.Client @@ -796,6 +801,7 @@ func (r *FvFBRGroupResource) Create(ctx context.Context, req resource.CreateRequ // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_vrf_fallback_route_group with id '%s'", data.Id.ValueString())) } @@ -820,6 +826,7 @@ func (r *FvFBRGroupResource) Read(ctx context.Context, req resource.ReadRequest, resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_vrf_fallback_route_group with id '%s'", data.Id.ValueString())) @@ -868,6 +875,7 @@ func (r *FvFBRGroupResource) Update(ctx context.Context, req resource.UpdateRequ // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_vrf_fallback_route_group with id '%s'", data.Id.ValueString())) } @@ -896,10 +904,11 @@ func (r *FvFBRGroupResource) Delete(ctx context.Context, req resource.DeleteRequ func (r *FvFBRGroupResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_vrf_fallback_route_group") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvFBRGroupResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_vrf_fallback_route_group with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_vrf_fallback_route_group") @@ -908,11 +917,17 @@ func (r *FvFBRGroupResource) ImportState(ctx context.Context, req resource.Impor func getAndSetFvFBRGroupAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvFBRGroupResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvFBRGroup,fvFBRMember,fvFBRoute,tagAnnotation,tagTag,tagAnnotation,tagTag,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvFBRGroupResourceModel() - if diags.HasError() { return } + + setFvFBRGroupAttributes(ctx, diags, data, requestData) +} + +func setFvFBRGroupAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvFBRGroupResourceModel, requestData *container.Container) { + + readData := getEmptyFvFBRGroupResourceModel() + if requestData.Search("imdata").Search("fvFBRGroup").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvFBRGroup").Data().([]interface{}) if len(classReadInfo) == 1 { diff --git a/internal/provider/resource_aci_vrf_fallback_route_group_member.go b/internal/provider/resource_aci_vrf_fallback_route_group_member.go index 9088d66ce..af678268c 100644 --- a/internal/provider/resource_aci_vrf_fallback_route_group_member.go +++ b/internal/provider/resource_aci_vrf_fallback_route_group_member.go @@ -27,12 +27,17 @@ import ( // Ensure provider defined types fully satisfy framework interfaces. var _ resource.Resource = &FvFBRMemberResource{} +var _ resource.ResourceWithIdentity = &FvFBRMemberResource{} var _ resource.ResourceWithImportState = &FvFBRMemberResource{} func NewFvFBRMemberResource() resource.Resource { return &FvFBRMemberResource{} } +func (r FvFBRMemberResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) { + resp.IdentitySchema = getIdentitySchema() +} + // FvFBRMemberResource defines the resource implementation. type FvFBRMemberResource struct { client *client.Client @@ -351,6 +356,7 @@ func (r *FvFBRMemberResource) Create(ctx context.Context, req resource.CreateReq // Save data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_vrf_fallback_route_group_member with id '%s'", data.Id.ValueString())) } @@ -375,6 +381,7 @@ func (r *FvFBRMemberResource) Read(ctx context.Context, req resource.ReadRequest resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) } else { resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) } tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_vrf_fallback_route_group_member with id '%s'", data.Id.ValueString())) @@ -417,6 +424,7 @@ func (r *FvFBRMemberResource) Update(ctx context.Context, req resource.UpdateReq // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...) tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_vrf_fallback_route_group_member with id '%s'", data.Id.ValueString())) } @@ -445,10 +453,11 @@ func (r *FvFBRMemberResource) Delete(ctx context.Context, req resource.DeleteReq func (r *FvFBRMemberResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { tflog.Debug(ctx, "Start import state of resource: aci_vrf_fallback_route_group_member") - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp) var stateData *FvFBRMemberResourceModel resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...) tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_vrf_fallback_route_group_member with id '%s'", stateData.Id.ValueString())) tflog.Debug(ctx, "End import of state resource: aci_vrf_fallback_route_group_member") @@ -457,11 +466,17 @@ func (r *FvFBRMemberResource) ImportState(ctx context.Context, req resource.Impo func getAndSetFvFBRMemberAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *FvFBRMemberResourceModel) { requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "fvFBRMember,tagAnnotation,tagTag"), "GET", nil) - readData := getEmptyFvFBRMemberResourceModel() - if diags.HasError() { return } + + setFvFBRMemberAttributes(ctx, diags, data, requestData) +} + +func setFvFBRMemberAttributes(ctx context.Context, diags *diag.Diagnostics, data *FvFBRMemberResourceModel, requestData *container.Container) { + + readData := getEmptyFvFBRMemberResourceModel() + if requestData.Search("imdata").Search("fvFBRMember").Data() != nil { classReadInfo := requestData.Search("imdata").Search("fvFBRMember").Data().([]interface{}) if len(classReadInfo) == 1 {