// Code generated by "gen/generator.go"; DO NOT EDIT.
// In order to regenerate this file execute `go generate` from the repository root.
// More details can be found in the [README](https://github.com/CiscoDevNet/terraform-provider-aci/blob/master/README.md).

package provider

import (
	"context"
	"encoding/json"
	"fmt"

	"github.com/ciscoecosystem/aci-go-client/v2/client"
	"github.com/ciscoecosystem/aci-go-client/v2/container"
	"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
	"github.com/hashicorp/terraform-plugin-framework/attr"
	"github.com/hashicorp/terraform-plugin-framework/diag"
	"github.com/hashicorp/terraform-plugin-framework/path"
	"github.com/hashicorp/terraform-plugin-framework/resource"
	"github.com/hashicorp/terraform-plugin-framework/resource/schema"
	"github.com/hashicorp/terraform-plugin-framework/resource/schema/objectplanmodifier"
	"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
	"github.com/hashicorp/terraform-plugin-framework/resource/schema/setplanmodifier"
	"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
	"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
	"github.com/hashicorp/terraform-plugin-framework/types"
	"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
	"github.com/hashicorp/terraform-plugin-log/tflog"
)

// Ensure provider defined types fully satisfy framework interfaces.
var _ resource.Resource = &FvFabricExtConnPResource{}
var _ resource.ResourceWithImportState = &FvFabricExtConnPResource{}

func NewFvFabricExtConnPResource() resource.Resource {
	return &FvFabricExtConnPResource{}
}

// FvFabricExtConnPResource defines the resource implementation.
type FvFabricExtConnPResource struct {
	client *client.Client
}

// FvFabricExtConnPResourceModel describes the resource data model.
type FvFabricExtConnPResourceModel struct {
	Id                 types.String `tfsdk:"id"`
	ParentDn           types.String `tfsdk:"parent_dn"`
	Annotation         types.String `tfsdk:"annotation"`
	Descr              types.String `tfsdk:"description"`
	FvFabricExtConnPId types.String `tfsdk:"fabric_id"`
	Name               types.String `tfsdk:"name"`
	NameAlias          types.String `tfsdk:"name_alias"`
	OwnerKey           types.String `tfsdk:"owner_key"`
	OwnerTag           types.String `tfsdk:"owner_tag"`
	Rt                 types.String `tfsdk:"community"`
	SiteId             types.String `tfsdk:"site_id"`
	FvPeeringP         types.Object `tfsdk:"peering_profile"`
	TagAnnotation      types.Set    `tfsdk:"annotations"`
	TagTag             types.Set    `tfsdk:"tags"`
}

func getEmptyFvFabricExtConnPResourceModel() *FvFabricExtConnPResourceModel {
	return &FvFabricExtConnPResourceModel{
		Id:                 basetypes.NewStringNull(),
		ParentDn:           basetypes.NewStringNull(),
		Annotation:         basetypes.NewStringNull(),
		Descr:              basetypes.NewStringNull(),
		FvFabricExtConnPId: basetypes.NewStringNull(),
		Name:               basetypes.NewStringNull(),
		NameAlias:          basetypes.NewStringNull(),
		OwnerKey:           basetypes.NewStringNull(),
		OwnerTag:           basetypes.NewStringNull(),
		Rt:                 basetypes.NewStringNull(),
		SiteId:             basetypes.NewStringNull(),
		FvPeeringP: types.ObjectNull(map[string]attr.Type{
			"annotation":  types.StringType,
			"description": types.StringType,
			"name":        types.StringType,
			"name_alias":  types.StringType,
			"owner_key":   types.StringType,
			"owner_tag":   types.StringType,
			"password":    types.StringType,
			"type":        types.StringType,
			"annotations": types.SetType{ElemType: TagAnnotationFvPeeringPFvFabricExtConnPType},
			"tags":        types.SetType{ElemType: TagTagFvPeeringPFvFabricExtConnPType},
		}),
		TagAnnotation: types.SetNull(types.ObjectType{
			AttrTypes: map[string]attr.Type{
				"key":   types.StringType,
				"value": types.StringType,
			},
		}),
		TagTag: types.SetNull(types.ObjectType{
			AttrTypes: map[string]attr.Type{
				"key":   types.StringType,
				"value": types.StringType,
			},
		}),
	}
}

// FvPeeringPFvFabricExtConnPResourceModel describes the resource data model for the children without relation ships.
type FvPeeringPFvFabricExtConnPResourceModel struct {
	Annotation    types.String `tfsdk:"annotation"`
	Descr         types.String `tfsdk:"description"`
	Name          types.String `tfsdk:"name"`
	NameAlias     types.String `tfsdk:"name_alias"`
	OwnerKey      types.String `tfsdk:"owner_key"`
	OwnerTag      types.String `tfsdk:"owner_tag"`
	Password      types.String `tfsdk:"password"`
	Type          types.String `tfsdk:"type"`
	TagAnnotation types.Set    `tfsdk:"annotations"`
	TagTag        types.Set    `tfsdk:"tags"`
}

func getEmptyFvPeeringPFvFabricExtConnPResourceModel() FvPeeringPFvFabricExtConnPResourceModel {
	return FvPeeringPFvFabricExtConnPResourceModel{
		Annotation: basetypes.NewStringNull(),
		Descr:      basetypes.NewStringNull(),
		Name:       basetypes.NewStringNull(),
		NameAlias:  basetypes.NewStringNull(),
		OwnerKey:   basetypes.NewStringNull(),
		OwnerTag:   basetypes.NewStringNull(),
		Password:   basetypes.NewStringNull(),
		Type:       basetypes.NewStringNull(),
		TagAnnotation: types.SetNull(types.ObjectType{
			AttrTypes: map[string]attr.Type{
				"key":   types.StringType,
				"value": types.StringType,
			},
		}),
		TagTag: types.SetNull(types.ObjectType{
			AttrTypes: map[string]attr.Type{
				"key":   types.StringType,
				"value": types.StringType,
			},
		}),
	}
}

var FvPeeringPFvFabricExtConnPType = map[string]attr.Type{
	"annotation":  types.StringType,
	"description": types.StringType,
	"name":        types.StringType,
	"name_alias":  types.StringType,
	"owner_key":   types.StringType,
	"owner_tag":   types.StringType,
	"password":    types.StringType,
	"type":        types.StringType,
	"annotations": types.SetType{ElemType: TagAnnotationFvPeeringPFvFabricExtConnPType},
	"tags":        types.SetType{ElemType: TagTagFvPeeringPFvFabricExtConnPType},
}

// TagAnnotationFvPeeringPFvFabricExtConnPResourceModel describes the resource data model for the children without relation ships.
type TagAnnotationFvPeeringPFvFabricExtConnPResourceModel struct {
	Key   types.String `tfsdk:"key"`
	Value types.String `tfsdk:"value"`
}

func getEmptyTagAnnotationFvPeeringPFvFabricExtConnPResourceModel() TagAnnotationFvPeeringPFvFabricExtConnPResourceModel {
	return TagAnnotationFvPeeringPFvFabricExtConnPResourceModel{
		Key:   basetypes.NewStringNull(),
		Value: basetypes.NewStringNull(),
	}
}

var TagAnnotationFvPeeringPFvFabricExtConnPType = types.ObjectType{
	AttrTypes: map[string]attr.Type{
		"key":   types.StringType,
		"value": types.StringType,
	},
}

// TagTagFvPeeringPFvFabricExtConnPResourceModel describes the resource data model for the children without relation ships.
type TagTagFvPeeringPFvFabricExtConnPResourceModel struct {
	Key   types.String `tfsdk:"key"`
	Value types.String `tfsdk:"value"`
}

func getEmptyTagTagFvPeeringPFvFabricExtConnPResourceModel() TagTagFvPeeringPFvFabricExtConnPResourceModel {
	return TagTagFvPeeringPFvFabricExtConnPResourceModel{
		Key:   basetypes.NewStringNull(),
		Value: basetypes.NewStringNull(),
	}
}

var TagTagFvPeeringPFvFabricExtConnPType = types.ObjectType{
	AttrTypes: map[string]attr.Type{
		"key":   types.StringType,
		"value": types.StringType,
	},
}

// TagAnnotationFvFabricExtConnPResourceModel describes the resource data model for the children without relation ships.
type TagAnnotationFvFabricExtConnPResourceModel struct {
	Key   types.String `tfsdk:"key"`
	Value types.String `tfsdk:"value"`
}

func getEmptyTagAnnotationFvFabricExtConnPResourceModel() TagAnnotationFvFabricExtConnPResourceModel {
	return TagAnnotationFvFabricExtConnPResourceModel{
		Key:   basetypes.NewStringNull(),
		Value: basetypes.NewStringNull(),
	}
}

var TagAnnotationFvFabricExtConnPType = types.ObjectType{
	AttrTypes: map[string]attr.Type{
		"key":   types.StringType,
		"value": types.StringType,
	},
}

// TagTagFvFabricExtConnPResourceModel describes the resource data model for the children without relation ships.
type TagTagFvFabricExtConnPResourceModel struct {
	Key   types.String `tfsdk:"key"`
	Value types.String `tfsdk:"value"`
}

func getEmptyTagTagFvFabricExtConnPResourceModel() TagTagFvFabricExtConnPResourceModel {
	return TagTagFvFabricExtConnPResourceModel{
		Key:   basetypes.NewStringNull(),
		Value: basetypes.NewStringNull(),
	}
}

var TagTagFvFabricExtConnPType = types.ObjectType{
	AttrTypes: map[string]attr.Type{
		"key":   types.StringType,
		"value": types.StringType,
	},
}

type FvFabricExtConnPIdentifier struct {
	Id types.String
}

func (r *FvFabricExtConnPResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) {
	if !req.Plan.Raw.IsNull() {
		var planData, stateData, configData *FvFabricExtConnPResourceModel
		resp.Diagnostics.Append(req.Plan.Get(ctx, &planData)...)
		resp.Diagnostics.Append(req.State.Get(ctx, &stateData)...)
		resp.Diagnostics.Append(req.Config.Get(ctx, &configData)...)

		if resp.Diagnostics.HasError() {
			return
		}

		if (planData.Id.IsUnknown() || planData.Id.IsNull()) && !planData.ParentDn.IsUnknown() && !planData.Id.IsUnknown() {
			setFvFabricExtConnPId(ctx, planData)
		}

		if stateData == nil && !globalAllowExistingOnCreate && !planData.Id.IsUnknown() && !planData.Id.IsNull() {
			CheckDn(ctx, &resp.Diagnostics, r.client, "fvFabricExtConnP", planData.Id.ValueString())
			if resp.Diagnostics.HasError() {
				return
			}
		}
		if !configData.FvPeeringP.IsNull() && stateData != nil {
			if IsEmptySingleNestedAttribute(configData.FvPeeringP.Attributes()) {
				FvPeeringPObject, _ := types.ObjectValueFrom(ctx, FvPeeringPFvFabricExtConnPType, getEmptyFvPeeringPFvFabricExtConnPResourceModel())
				planData.FvPeeringP = FvPeeringPObject
			}
		}

		resp.Diagnostics.Append(resp.Plan.Set(ctx, &planData)...)
	}
}

func (r *FvFabricExtConnPResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
	tflog.Debug(ctx, "Start metadata of resource: aci_fabric_external_connection_policy")
	resp.TypeName = req.ProviderTypeName + "_fabric_external_connection_policy"
	tflog.Debug(ctx, "End metadata of resource: aci_fabric_external_connection_policy")
}

func (r *FvFabricExtConnPResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
	tflog.Debug(ctx, "Start schema of resource: aci_fabric_external_connection_policy")
	resp.Schema = schema.Schema{
		// This description is used by the documentation generator and the language server.
		MarkdownDescription: "The fabric_external_connection_policy resource for the 'fvFabricExtConnP' class",

		Attributes: map[string]schema.Attribute{
			"id": schema.StringAttribute{
				Computed:            true,
				MarkdownDescription: "The distinguished name (DN) of the Fabric External Connection Policy object.",
				PlanModifiers: []planmodifier.String{
					stringplanmodifier.UseStateForUnknown(),
				},
			},
			"parent_dn": schema.StringAttribute{
				Optional:            true,
				Computed:            true,
				Default:             stringdefault.StaticString("uni/tn-infra"),
				MarkdownDescription: "The distinguished name (DN) of the parent object.",
				PlanModifiers: []planmodifier.String{
					stringplanmodifier.UseStateForUnknown(),
					stringplanmodifier.RequiresReplace(),
				},
			},
			"annotation": schema.StringAttribute{
				Optional: true,
				Computed: true,
				PlanModifiers: []planmodifier.String{
					stringplanmodifier.UseStateForUnknown(),
					SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(),
				},
				Default:             stringdefault.StaticString(globalAnnotation),
				MarkdownDescription: `The annotation of the Fabric External Connection Policy object.`,
			},
			"description": schema.StringAttribute{
				Optional: true,
				Computed: true,
				PlanModifiers: []planmodifier.String{
					stringplanmodifier.UseStateForUnknown(),
					SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(),
				},
				MarkdownDescription: `The description of the Fabric External Connection Policy object.`,
			},
			"fabric_id": schema.StringAttribute{
				Required: true,
				PlanModifiers: []planmodifier.String{
					stringplanmodifier.UseStateForUnknown(),
					SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(),
					stringplanmodifier.RequiresReplace(),
				},
				MarkdownDescription: `A unique identifier of the fabric, associated with the Fabric External Connection Policy object.`,
			},
			"name": schema.StringAttribute{
				Optional: true,
				Computed: true,
				PlanModifiers: []planmodifier.String{
					stringplanmodifier.UseStateForUnknown(),
					SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(),
				},
				MarkdownDescription: `The name of the Fabric External Connection Policy object.`,
			},
			"name_alias": schema.StringAttribute{
				Optional: true,
				Computed: true,
				PlanModifiers: []planmodifier.String{
					stringplanmodifier.UseStateForUnknown(),
					SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(),
				},
				MarkdownDescription: `The name alias of the Fabric External Connection Policy object.`,
			},
			"owner_key": schema.StringAttribute{
				Optional: true,
				Computed: true,
				PlanModifiers: []planmodifier.String{
					stringplanmodifier.UseStateForUnknown(),
					SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(),
				},
				MarkdownDescription: `The key for enabling clients to own their data for entity correlation.`,
			},
			"owner_tag": schema.StringAttribute{
				Optional: true,
				Computed: true,
				PlanModifiers: []planmodifier.String{
					stringplanmodifier.UseStateForUnknown(),
					SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(),
				},
				MarkdownDescription: `A tag for enabling clients to add their own data. For example, to indicate who created this object.`,
			},
			"community": schema.StringAttribute{
				Optional: true,
				Computed: true,
				PlanModifiers: []planmodifier.String{
					stringplanmodifier.UseStateForUnknown(),
					SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(),
				},
				MarkdownDescription: `A global route target used to define communities for route leaking or redistribution in multi-pod or multi-site deployments to manage routing policies across fabrics.`,
			},
			"site_id": schema.StringAttribute{
				Optional: true,
				Computed: true,
				PlanModifiers: []planmodifier.String{
					stringplanmodifier.UseStateForUnknown(),
					SetToStringNullWhenStateIsNullPlanIsUnknownDuringUpdate(),
				},
				MarkdownDescription: `A unique identifier for the site associated with the Fabric External Connection Policy object.`,
			},
			"peering_profile": schema.SingleNestedAttribute{
				MarkdownDescription: `Peering Profile`,
				Optional:            true,
				Computed:            true,
				PlanModifiers: []planmodifier.Object{
					objectplanmodifier.UseStateForUnknown(),
				},
				Attributes: map[string]schema.Attribute{
					"annotation": schema.StringAttribute{
						Optional: true,
						Computed: true,
						PlanModifiers: []planmodifier.String{
							stringplanmodifier.UseStateForUnknown(),
						},
						MarkdownDescription: `The annotation of the BGP EVPN Peering Profile object.`,
					},
					"description": schema.StringAttribute{
						Optional: true,
						Computed: true,
						PlanModifiers: []planmodifier.String{
							stringplanmodifier.UseStateForUnknown(),
						},
						MarkdownDescription: `The description of the BGP EVPN Peering Profile object.`,
					},
					"name": schema.StringAttribute{
						Optional: true,
						Computed: true,
						PlanModifiers: []planmodifier.String{
							stringplanmodifier.UseStateForUnknown(),
						},
						MarkdownDescription: `The name of the BGP EVPN Peering Profile object.`,
					},
					"name_alias": schema.StringAttribute{
						Optional: true,
						Computed: true,
						PlanModifiers: []planmodifier.String{
							stringplanmodifier.UseStateForUnknown(),
						},
						MarkdownDescription: `The name alias of the BGP EVPN Peering Profile object.`,
					},
					"owner_key": schema.StringAttribute{
						Optional: true,
						Computed: true,
						PlanModifiers: []planmodifier.String{
							stringplanmodifier.UseStateForUnknown(),
						},
						MarkdownDescription: `The key for enabling clients to own their data for entity correlation.`,
					},
					"owner_tag": schema.StringAttribute{
						Optional: true,
						Computed: true,
						PlanModifiers: []planmodifier.String{
							stringplanmodifier.UseStateForUnknown(),
						},
						MarkdownDescription: `A tag for enabling clients to add their own data. For example, to indicate who created this object.`,
					},
					"password": schema.StringAttribute{
						Optional:  true,
						Sensitive: true,
						PlanModifiers: []planmodifier.String{
							stringplanmodifier.UseStateForUnknown(),
						},
						MarkdownDescription: `The password used for establishing automatic BGP peering sessions.`,
					},
					"type": schema.StringAttribute{
						Optional: true,
						Computed: true,
						PlanModifiers: []planmodifier.String{
							stringplanmodifier.UseStateForUnknown(),
						},
						Validators: []validator.String{
							stringvalidator.OneOf("automatic_with_full_mesh", "automatic_with_rr"),
						},
						MarkdownDescription: `The type of BGP EVPN Peering Profile object.`,
					},
					"annotations": schema.SetNestedAttribute{
						MarkdownDescription: ``,
						Optional:            true,
						Computed:            true,
						PlanModifiers: []planmodifier.Set{
							setplanmodifier.UseStateForUnknown(),
						},
						NestedObject: schema.NestedAttributeObject{
							Attributes: map[string]schema.Attribute{
								"key": schema.StringAttribute{
									Required: true,
									PlanModifiers: []planmodifier.String{
										stringplanmodifier.UseStateForUnknown(),
									},
									MarkdownDescription: `The key used to uniquely identify this configuration object.`,
								},
								"value": schema.StringAttribute{
									Required: true,
									PlanModifiers: []planmodifier.String{
										stringplanmodifier.UseStateForUnknown(),
									},
									MarkdownDescription: `The value of the property.`,
								},
							},
						},
					},
					"tags": schema.SetNestedAttribute{
						MarkdownDescription: ``,
						Optional:            true,
						Computed:            true,
						PlanModifiers: []planmodifier.Set{
							setplanmodifier.UseStateForUnknown(),
						},
						NestedObject: schema.NestedAttributeObject{
							Attributes: map[string]schema.Attribute{
								"key": schema.StringAttribute{
									Required: true,
									PlanModifiers: []planmodifier.String{
										stringplanmodifier.UseStateForUnknown(),
									},
									MarkdownDescription: `The key used to uniquely identify this configuration object.`,
								},
								"value": schema.StringAttribute{
									Required: true,
									PlanModifiers: []planmodifier.String{
										stringplanmodifier.UseStateForUnknown(),
									},
									MarkdownDescription: `The value of the property.`,
								},
							},
						},
					},
				},
			},
			"annotations": schema.SetNestedAttribute{
				MarkdownDescription: ``,
				Optional:            true,
				Computed:            true,
				PlanModifiers: []planmodifier.Set{
					setplanmodifier.UseStateForUnknown(),
				},
				NestedObject: schema.NestedAttributeObject{
					Attributes: map[string]schema.Attribute{
						"key": schema.StringAttribute{
							Required: true,
							PlanModifiers: []planmodifier.String{
								stringplanmodifier.UseStateForUnknown(),
							},
							MarkdownDescription: `The key used to uniquely identify this configuration object.`,
						},
						"value": schema.StringAttribute{
							Required: true,
							PlanModifiers: []planmodifier.String{
								stringplanmodifier.UseStateForUnknown(),
							},
							MarkdownDescription: `The value of the property.`,
						},
					},
				},
			},
			"tags": schema.SetNestedAttribute{
				MarkdownDescription: ``,
				Optional:            true,
				Computed:            true,
				PlanModifiers: []planmodifier.Set{
					setplanmodifier.UseStateForUnknown(),
				},
				NestedObject: schema.NestedAttributeObject{
					Attributes: map[string]schema.Attribute{
						"key": schema.StringAttribute{
							Required: true,
							PlanModifiers: []planmodifier.String{
								stringplanmodifier.UseStateForUnknown(),
							},
							MarkdownDescription: `The key used to uniquely identify this configuration object.`,
						},
						"value": schema.StringAttribute{
							Required: true,
							PlanModifiers: []planmodifier.String{
								stringplanmodifier.UseStateForUnknown(),
							},
							MarkdownDescription: `The value of the property.`,
						},
					},
				},
			},
		},
	}
	tflog.Debug(ctx, "End schema of resource: aci_fabric_external_connection_policy")
}

func (r *FvFabricExtConnPResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
	tflog.Debug(ctx, "Start configure of resource: aci_fabric_external_connection_policy")
	// Prevent panic if the provider has not been configured.
	if req.ProviderData == nil {
		return
	}

	client, ok := req.ProviderData.(*client.Client)

	if !ok {
		resp.Diagnostics.AddError(
			"Unexpected Resource Configure Type",
			fmt.Sprintf("Expected *client.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData),
		)

		return
	}

	r.client = client
	tflog.Debug(ctx, "End configure of resource: aci_fabric_external_connection_policy")
}

func (r *FvFabricExtConnPResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
	tflog.Debug(ctx, "Start create of resource: aci_fabric_external_connection_policy")
	// On create retrieve information on current state prior to making any changes in order to determine child delete operations
	var stateData *FvFabricExtConnPResourceModel
	resp.Diagnostics.Append(req.Plan.Get(ctx, &stateData)...)
	if stateData.Id.IsUnknown() || stateData.Id.IsNull() {
		setFvFabricExtConnPId(ctx, stateData)
	}
	getAndSetFvFabricExtConnPAttributes(ctx, &resp.Diagnostics, r.client, stateData)
	if !globalAllowExistingOnCreate && !stateData.Id.IsNull() {
		resp.Diagnostics.AddError(
			"Object Already Exists",
			fmt.Sprintf("The fvFabricExtConnP object with DN '%s' already exists.", stateData.Id.ValueString()),
		)
		return
	}

	var data *FvFabricExtConnPResourceModel

	// Read Terraform plan data into the model
	resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)

	if resp.Diagnostics.HasError() {
		return
	}

	if data.Id.IsUnknown() || data.Id.IsNull() {
		setFvFabricExtConnPId(ctx, data)
	}

	tflog.Debug(ctx, fmt.Sprintf("Create of resource aci_fabric_external_connection_policy with id '%s'", data.Id.ValueString()))

	var fvPeeringPPlan, fvPeeringPState FvPeeringPFvFabricExtConnPResourceModel
	data.FvPeeringP.As(ctx, &fvPeeringPPlan, basetypes.ObjectAsOptions{})
	stateData.FvPeeringP.As(ctx, &fvPeeringPState, basetypes.ObjectAsOptions{})
	var tagAnnotationPlan, tagAnnotationState []TagAnnotationFvFabricExtConnPResourceModel
	data.TagAnnotation.ElementsAs(ctx, &tagAnnotationPlan, false)
	stateData.TagAnnotation.ElementsAs(ctx, &tagAnnotationState, false)
	var tagTagPlan, tagTagState []TagTagFvFabricExtConnPResourceModel
	data.TagTag.ElementsAs(ctx, &tagTagPlan, false)
	stateData.TagTag.ElementsAs(ctx, &tagTagState, false)
	jsonPayload := getFvFabricExtConnPCreateJsonPayload(ctx, &resp.Diagnostics, true, data, fvPeeringPPlan, fvPeeringPState, tagAnnotationPlan, tagAnnotationState, tagTagPlan, tagTagState)

	if resp.Diagnostics.HasError() {
		return
	}

	DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload)

	if resp.Diagnostics.HasError() {
		return
	}

	getAndSetFvFabricExtConnPAttributes(ctx, &resp.Diagnostics, r.client, data)

	// Save data into Terraform state
	resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
	tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_fabric_external_connection_policy with id '%s'", data.Id.ValueString()))
}

func (r *FvFabricExtConnPResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
	tflog.Debug(ctx, "Start read of resource: aci_fabric_external_connection_policy")
	var data *FvFabricExtConnPResourceModel

	// Read Terraform prior state data into the model
	resp.Diagnostics.Append(req.State.Get(ctx, &data)...)

	if resp.Diagnostics.HasError() {
		return
	}

	tflog.Debug(ctx, fmt.Sprintf("Read of resource aci_fabric_external_connection_policy with id '%s'", data.Id.ValueString()))

	getAndSetFvFabricExtConnPAttributes(ctx, &resp.Diagnostics, r.client, data)

	// Save updated data into Terraform state
	if data.Id.IsNull() {
		var emptyData *FvFabricExtConnPResourceModel
		resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...)
	} else {
		resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
	}

	tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_fabric_external_connection_policy with id '%s'", data.Id.ValueString()))
}

func (r *FvFabricExtConnPResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
	tflog.Debug(ctx, "Start update of resource: aci_fabric_external_connection_policy")
	var data *FvFabricExtConnPResourceModel
	var stateData *FvFabricExtConnPResourceModel

	// Read Terraform plan data into the model
	resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
	resp.Diagnostics.Append(req.State.Get(ctx, &stateData)...)
	// Error out when child object fvPeeringP is being deleted
	if IsEmptySingleNestedAttribute(data.FvPeeringP.Attributes()) && !IsEmptySingleNestedAttribute(stateData.FvPeeringP.Attributes()) {
		resp.Diagnostics.AddError(
			"FvPeeringP object cannot be deleted",
			"deletion of child is only possible upon deletion of the parent",
		)
	}

	if resp.Diagnostics.HasError() {
		return
	}

	tflog.Debug(ctx, fmt.Sprintf("Update of resource aci_fabric_external_connection_policy with id '%s'", data.Id.ValueString()))

	var fvPeeringPPlan, fvPeeringPState FvPeeringPFvFabricExtConnPResourceModel
	data.FvPeeringP.As(ctx, &fvPeeringPPlan, basetypes.ObjectAsOptions{})
	stateData.FvPeeringP.As(ctx, &fvPeeringPState, basetypes.ObjectAsOptions{})
	var tagAnnotationPlan, tagAnnotationState []TagAnnotationFvFabricExtConnPResourceModel
	data.TagAnnotation.ElementsAs(ctx, &tagAnnotationPlan, false)
	stateData.TagAnnotation.ElementsAs(ctx, &tagAnnotationState, false)
	var tagTagPlan, tagTagState []TagTagFvFabricExtConnPResourceModel
	data.TagTag.ElementsAs(ctx, &tagTagPlan, false)
	stateData.TagTag.ElementsAs(ctx, &tagTagState, false)
	jsonPayload := getFvFabricExtConnPCreateJsonPayload(ctx, &resp.Diagnostics, false, data, fvPeeringPPlan, fvPeeringPState, tagAnnotationPlan, tagAnnotationState, tagTagPlan, tagTagState)

	if resp.Diagnostics.HasError() {
		return
	}

	DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload)

	if resp.Diagnostics.HasError() {
		return
	}

	getAndSetFvFabricExtConnPAttributes(ctx, &resp.Diagnostics, r.client, data)

	// Save updated data into Terraform state
	resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
	tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_fabric_external_connection_policy with id '%s'", data.Id.ValueString()))
}

func (r *FvFabricExtConnPResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
	tflog.Debug(ctx, "Start delete of resource: aci_fabric_external_connection_policy")
	var data *FvFabricExtConnPResourceModel

	// Read Terraform prior state data into the model
	resp.Diagnostics.Append(req.State.Get(ctx, &data)...)

	if resp.Diagnostics.HasError() {
		return
	}

	tflog.Debug(ctx, fmt.Sprintf("Delete of resource aci_fabric_external_connection_policy with id '%s'", data.Id.ValueString()))
	jsonPayload := GetDeleteJsonPayload(ctx, &resp.Diagnostics, "fvFabricExtConnP", data.Id.ValueString())
	if resp.Diagnostics.HasError() {
		return
	}
	DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload)
	if resp.Diagnostics.HasError() {
		return
	}
	tflog.Debug(ctx, fmt.Sprintf("End delete of resource aci_fabric_external_connection_policy with id '%s'", data.Id.ValueString()))
}

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)

	var stateData *FvFabricExtConnPResourceModel
	resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...)
	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")
}

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
	}
	if requestData.Search("imdata").Search("fvFabricExtConnP").Data() != nil {
		classReadInfo := requestData.Search("imdata").Search("fvFabricExtConnP").Data().([]interface{})
		if len(classReadInfo) == 1 {
			attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{})
			for attributeName, attributeValue := range attributes {
				if attributeName == "dn" {
					readData.Id = basetypes.NewStringValue(attributeValue.(string))
					setFvFabricExtConnPParentDn(ctx, attributeValue.(string), readData)
				}
				if attributeName == "annotation" {
					readData.Annotation = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "descr" {
					readData.Descr = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "id" {
					readData.FvFabricExtConnPId = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "name" {
					readData.Name = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "nameAlias" {
					readData.NameAlias = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "ownerKey" {
					readData.OwnerKey = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "ownerTag" {
					readData.OwnerTag = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "rt" {
					readData.Rt = basetypes.NewStringValue(attributeValue.(string))
				}
				if attributeName == "siteId" {
					readData.SiteId = basetypes.NewStringValue(attributeValue.(string))
				}
			}
			FvPeeringPFvFabricExtConnPList := make([]FvPeeringPFvFabricExtConnPResourceModel, 0)
			TagAnnotationFvFabricExtConnPList := make([]TagAnnotationFvFabricExtConnPResourceModel, 0)
			TagTagFvFabricExtConnPList := make([]TagTagFvFabricExtConnPResourceModel, 0)
			_, ok := classReadInfo[0].(map[string]interface{})["children"]
			if ok {
				children := classReadInfo[0].(map[string]interface{})["children"].([]interface{})
				for _, child := range children {
					for childClassName, childClassDetails := range child.(map[string]interface{}) {
						childAttributes := childClassDetails.(map[string]interface{})["attributes"].(map[string]interface{})
						if childClassName == "fvPeeringP" {
							FvPeeringPFvFabricExtConnP := getEmptyFvPeeringPFvFabricExtConnPResourceModel()
							for childAttributeName, childAttributeValue := range childAttributes {
								if childAttributeName == "annotation" {
									FvPeeringPFvFabricExtConnP.Annotation = basetypes.NewStringValue(childAttributeValue.(string))
								}
								if childAttributeName == "descr" {
									FvPeeringPFvFabricExtConnP.Descr = basetypes.NewStringValue(childAttributeValue.(string))
								}
								if childAttributeName == "name" {
									FvPeeringPFvFabricExtConnP.Name = basetypes.NewStringValue(childAttributeValue.(string))
								}
								if childAttributeName == "nameAlias" {
									FvPeeringPFvFabricExtConnP.NameAlias = basetypes.NewStringValue(childAttributeValue.(string))
								}
								if childAttributeName == "ownerKey" {
									FvPeeringPFvFabricExtConnP.OwnerKey = basetypes.NewStringValue(childAttributeValue.(string))
								}
								if childAttributeName == "ownerTag" {
									FvPeeringPFvFabricExtConnP.OwnerTag = basetypes.NewStringValue(childAttributeValue.(string))
								}
								// Sensitive attributes are not returned by the APIC, so they are explicitly set to their current state values.
								var FvPeeringPData FvPeeringPFvFabricExtConnPResourceModel
								data.FvPeeringP.As(ctx, &FvPeeringPData, basetypes.ObjectAsOptions{})
								FvPeeringPFvFabricExtConnP.Password = FvPeeringPData.Password
								if childAttributeName == "type" {
									FvPeeringPFvFabricExtConnP.Type = basetypes.NewStringValue(childAttributeValue.(string))
								}

							}
							TagAnnotationFvPeeringPFvFabricExtConnPList := make([]TagAnnotationFvPeeringPFvFabricExtConnPResourceModel, 0)
							TagTagFvPeeringPFvFabricExtConnPList := make([]TagTagFvPeeringPFvFabricExtConnPResourceModel, 0)
							childrenOfFvPeeringPFvFabricExtConnP, childrenOfFvPeeringPFvFabricExtConnPExist := childClassDetails.(map[string]interface{})["children"]
							if childrenOfFvPeeringPFvFabricExtConnPExist {
								for _, childFvPeeringPFvFabricExtConnP := range childrenOfFvPeeringPFvFabricExtConnP.([]interface{}) {
									for childClassNameFvPeeringPFvFabricExtConnP, childClassDetailsFvPeeringPFvFabricExtConnP := range childFvPeeringPFvFabricExtConnP.(map[string]interface{}) {
										if childClassNameFvPeeringPFvFabricExtConnP == "tagAnnotation" {
											TagAnnotationFvPeeringPFvFabricExtConnP := getEmptyTagAnnotationFvPeeringPFvFabricExtConnPResourceModel()
											tagAnnotationchildAttributeValue := childClassDetailsFvPeeringPFvFabricExtConnP.(map[string]interface{})["attributes"].(map[string]interface{})
											for childAttributeName, childAttributeValue := range tagAnnotationchildAttributeValue {
												if childAttributeName == "key" {
													TagAnnotationFvPeeringPFvFabricExtConnP.Key = basetypes.NewStringValue(childAttributeValue.(string))
												}
												if childAttributeName == "value" {
													TagAnnotationFvPeeringPFvFabricExtConnP.Value = basetypes.NewStringValue(childAttributeValue.(string))
												}
											}
											TagAnnotationFvPeeringPFvFabricExtConnPList = append(TagAnnotationFvPeeringPFvFabricExtConnPList, TagAnnotationFvPeeringPFvFabricExtConnP)
										}
										if childClassNameFvPeeringPFvFabricExtConnP == "tagTag" {
											TagTagFvPeeringPFvFabricExtConnP := getEmptyTagTagFvPeeringPFvFabricExtConnPResourceModel()
											tagTagchildAttributeValue := childClassDetailsFvPeeringPFvFabricExtConnP.(map[string]interface{})["attributes"].(map[string]interface{})
											for childAttributeName, childAttributeValue := range tagTagchildAttributeValue {
												if childAttributeName == "key" {
													TagTagFvPeeringPFvFabricExtConnP.Key = basetypes.NewStringValue(childAttributeValue.(string))
												}
												if childAttributeName == "value" {
													TagTagFvPeeringPFvFabricExtConnP.Value = basetypes.NewStringValue(childAttributeValue.(string))
												}
											}
											TagTagFvPeeringPFvFabricExtConnPList = append(TagTagFvPeeringPFvFabricExtConnPList, TagTagFvPeeringPFvFabricExtConnP)
										}
									}
								}
							}
							TagAnnotationFvPeeringPFvFabricExtConnPSet, _ := types.SetValueFrom(ctx, TagAnnotationFvPeeringPFvFabricExtConnPType, TagAnnotationFvPeeringPFvFabricExtConnPList)
							FvPeeringPFvFabricExtConnP.TagAnnotation = TagAnnotationFvPeeringPFvFabricExtConnPSet
							TagTagFvPeeringPFvFabricExtConnPSet, _ := types.SetValueFrom(ctx, TagTagFvPeeringPFvFabricExtConnPType, TagTagFvPeeringPFvFabricExtConnPList)
							FvPeeringPFvFabricExtConnP.TagTag = TagTagFvPeeringPFvFabricExtConnPSet
							FvPeeringPFvFabricExtConnPList = append(FvPeeringPFvFabricExtConnPList, FvPeeringPFvFabricExtConnP)
						}
						if childClassName == "tagAnnotation" {
							TagAnnotationFvFabricExtConnP := getEmptyTagAnnotationFvFabricExtConnPResourceModel()
							for childAttributeName, childAttributeValue := range childAttributes {
								if childAttributeName == "key" {
									TagAnnotationFvFabricExtConnP.Key = basetypes.NewStringValue(childAttributeValue.(string))
								}
								if childAttributeName == "value" {
									TagAnnotationFvFabricExtConnP.Value = basetypes.NewStringValue(childAttributeValue.(string))
								}

							}
							TagAnnotationFvFabricExtConnPList = append(TagAnnotationFvFabricExtConnPList, TagAnnotationFvFabricExtConnP)
						}
						if childClassName == "tagTag" {
							TagTagFvFabricExtConnP := getEmptyTagTagFvFabricExtConnPResourceModel()
							for childAttributeName, childAttributeValue := range childAttributes {
								if childAttributeName == "key" {
									TagTagFvFabricExtConnP.Key = basetypes.NewStringValue(childAttributeValue.(string))
								}
								if childAttributeName == "value" {
									TagTagFvFabricExtConnP.Value = basetypes.NewStringValue(childAttributeValue.(string))
								}

							}
							TagTagFvFabricExtConnPList = append(TagTagFvFabricExtConnPList, TagTagFvFabricExtConnP)
						}
					}
				}
			}
			if len(FvPeeringPFvFabricExtConnPList) == 1 {
				fvPeeringPObject, _ := types.ObjectValueFrom(ctx, FvPeeringPFvFabricExtConnPType, FvPeeringPFvFabricExtConnPList[0])
				readData.FvPeeringP = fvPeeringPObject
			} else {
				fvPeeringPObject, _ := types.ObjectValueFrom(ctx, FvPeeringPFvFabricExtConnPType, getEmptyFvPeeringPFvFabricExtConnPResourceModel())
				readData.FvPeeringP = fvPeeringPObject
			}
			tagAnnotationSet, _ := types.SetValueFrom(ctx, readData.TagAnnotation.ElementType(ctx), TagAnnotationFvFabricExtConnPList)
			readData.TagAnnotation = tagAnnotationSet
			tagTagSet, _ := types.SetValueFrom(ctx, readData.TagTag.ElementType(ctx), TagTagFvFabricExtConnPList)
			readData.TagTag = tagTagSet
		} else {
			diags.AddError(
				"too many results in response",
				fmt.Sprintf("%v matches returned for class 'fvFabricExtConnP'. Please report this issue to the provider developers.", len(classReadInfo)),
			)
		}
	} else {
		readData.Id = basetypes.NewStringNull()
	}
	*data = *readData
}

func getFvFabricExtConnPRn(ctx context.Context, data *FvFabricExtConnPResourceModel) string {
	return fmt.Sprintf("fabricExtConnP-%s", data.FvFabricExtConnPId.ValueString())
}

func setFvFabricExtConnPParentDn(ctx context.Context, dn string, data *FvFabricExtConnPResourceModel) {
	bracketIndex := 0
	rnIndex := 0
	for i := len(dn) - 1; i >= 0; i-- {
		if string(dn[i]) == "]" {
			bracketIndex = bracketIndex + 1
		} else if string(dn[i]) == "[" {
			bracketIndex = bracketIndex - 1
		} else if string(dn[i]) == "/" && bracketIndex == 0 {
			rnIndex = i
			break
		}
	}
	data.ParentDn = basetypes.NewStringValue(dn[:rnIndex])
}

func setFvFabricExtConnPId(ctx context.Context, data *FvFabricExtConnPResourceModel) {
	rn := getFvFabricExtConnPRn(ctx, data)
	data.Id = types.StringValue(fmt.Sprintf("%s/%s", data.ParentDn.ValueString(), rn))
}

func getFvFabricExtConnPFvPeeringPChildPayloads(ctx context.Context, diags *diag.Diagnostics, data *FvFabricExtConnPResourceModel, fvPeeringPFvFabricExtConnPPlan, fvPeeringPFvFabricExtConnPState FvPeeringPFvFabricExtConnPResourceModel) []map[string]interface{} {
	childPayloads := []map[string]interface{}{}
	if !data.FvPeeringP.IsNull() && !data.FvPeeringP.IsUnknown() {
		FvPeeringPFvFabricExtConnPChildren := make([]map[string]interface{}, 0)
		childMap := NewAciObject()
		if !IsEmptySingleNestedAttribute(data.FvPeeringP.Attributes()) {
			if !fvPeeringPFvFabricExtConnPPlan.Annotation.IsUnknown() && !fvPeeringPFvFabricExtConnPPlan.Annotation.IsNull() {
				childMap.Attributes["annotation"] = fvPeeringPFvFabricExtConnPPlan.Annotation.ValueString()
			} else {
				childMap.Attributes["annotation"] = globalAnnotation
			}
			if !fvPeeringPFvFabricExtConnPPlan.Descr.IsUnknown() && !fvPeeringPFvFabricExtConnPPlan.Descr.IsNull() {
				childMap.Attributes["descr"] = fvPeeringPFvFabricExtConnPPlan.Descr.ValueString()
			}
			if !fvPeeringPFvFabricExtConnPPlan.Name.IsUnknown() && !fvPeeringPFvFabricExtConnPPlan.Name.IsNull() {
				childMap.Attributes["name"] = fvPeeringPFvFabricExtConnPPlan.Name.ValueString()
			}
			if !fvPeeringPFvFabricExtConnPPlan.NameAlias.IsUnknown() && !fvPeeringPFvFabricExtConnPPlan.NameAlias.IsNull() {
				childMap.Attributes["nameAlias"] = fvPeeringPFvFabricExtConnPPlan.NameAlias.ValueString()
			}
			if !fvPeeringPFvFabricExtConnPPlan.OwnerKey.IsUnknown() && !fvPeeringPFvFabricExtConnPPlan.OwnerKey.IsNull() {
				childMap.Attributes["ownerKey"] = fvPeeringPFvFabricExtConnPPlan.OwnerKey.ValueString()
			}
			if !fvPeeringPFvFabricExtConnPPlan.OwnerTag.IsUnknown() && !fvPeeringPFvFabricExtConnPPlan.OwnerTag.IsNull() {
				childMap.Attributes["ownerTag"] = fvPeeringPFvFabricExtConnPPlan.OwnerTag.ValueString()
			}
			if !fvPeeringPFvFabricExtConnPPlan.Password.IsUnknown() && !fvPeeringPFvFabricExtConnPPlan.Password.IsNull() {
				childMap.Attributes["password"] = fvPeeringPFvFabricExtConnPPlan.Password.ValueString()
			}
			if !fvPeeringPFvFabricExtConnPPlan.Type.IsUnknown() && !fvPeeringPFvFabricExtConnPPlan.Type.IsNull() {
				childMap.Attributes["type"] = fvPeeringPFvFabricExtConnPPlan.Type.ValueString()
			}

			var tagAnnotationFvPeeringPFvFabricExtConnPPlan, tagAnnotationFvPeeringPFvFabricExtConnPState []TagAnnotationFvPeeringPFvFabricExtConnPResourceModel
			fvPeeringPFvFabricExtConnPPlan.TagAnnotation.ElementsAs(ctx, &tagAnnotationFvPeeringPFvFabricExtConnPPlan, false)
			if !fvPeeringPFvFabricExtConnPState.TagAnnotation.IsNull() {
				fvPeeringPFvFabricExtConnPState.TagAnnotation.ElementsAs(ctx, &tagAnnotationFvPeeringPFvFabricExtConnPState, false)
			}
			if !fvPeeringPFvFabricExtConnPPlan.TagAnnotation.IsNull() && !fvPeeringPFvFabricExtConnPPlan.TagAnnotation.IsUnknown() {
				tagAnnotationIdentifiers := []TagAnnotationIdentifier{}
				for _, tagAnnotationFvPeeringPFvFabricExtConnP := range tagAnnotationFvPeeringPFvFabricExtConnPPlan {
					tagAnnotationFvPeeringPFvFabricExtConnPChildMap := NewAciObject()
					if !tagAnnotationFvPeeringPFvFabricExtConnP.Key.IsNull() && !tagAnnotationFvPeeringPFvFabricExtConnP.Key.IsUnknown() {
						tagAnnotationFvPeeringPFvFabricExtConnPChildMap.Attributes["key"] = tagAnnotationFvPeeringPFvFabricExtConnP.Key.ValueString()
					}
					if !tagAnnotationFvPeeringPFvFabricExtConnP.Value.IsNull() && !tagAnnotationFvPeeringPFvFabricExtConnP.Value.IsUnknown() {
						tagAnnotationFvPeeringPFvFabricExtConnPChildMap.Attributes["value"] = tagAnnotationFvPeeringPFvFabricExtConnP.Value.ValueString()
					}
					FvPeeringPFvFabricExtConnPChildren = append(FvPeeringPFvFabricExtConnPChildren, map[string]interface{}{"tagAnnotation": tagAnnotationFvPeeringPFvFabricExtConnPChildMap})
					tagAnnotationIdentifier := TagAnnotationIdentifier{}
					tagAnnotationIdentifier.Key = tagAnnotationFvPeeringPFvFabricExtConnP.Key
					tagAnnotationIdentifiers = append(tagAnnotationIdentifiers, tagAnnotationIdentifier)
				}
				for _, tagAnnotationFvPeeringPFvFabricExtConnP := range tagAnnotationFvPeeringPFvFabricExtConnPState {
					delete := true
					for _, tagAnnotationIdentifier := range tagAnnotationIdentifiers {
						if tagAnnotationIdentifier.Key == tagAnnotationFvPeeringPFvFabricExtConnP.Key {
							delete = false
							break
						}
					}
					if delete {
						tagAnnotationFvPeeringPFvFabricExtConnPChildMapForDelete := NewAciObject()
						tagAnnotationFvPeeringPFvFabricExtConnPChildMapForDelete.Attributes["status"] = "deleted"
						tagAnnotationFvPeeringPFvFabricExtConnPChildMapForDelete.Attributes["key"] = tagAnnotationFvPeeringPFvFabricExtConnP.Key.ValueString()
						FvPeeringPFvFabricExtConnPChildren = append(FvPeeringPFvFabricExtConnPChildren, map[string]interface{}{"tagAnnotation": tagAnnotationFvPeeringPFvFabricExtConnPChildMapForDelete})
					}
				}
			}

			var tagTagFvPeeringPFvFabricExtConnPPlan, tagTagFvPeeringPFvFabricExtConnPState []TagTagFvPeeringPFvFabricExtConnPResourceModel
			fvPeeringPFvFabricExtConnPPlan.TagTag.ElementsAs(ctx, &tagTagFvPeeringPFvFabricExtConnPPlan, false)
			if !fvPeeringPFvFabricExtConnPState.TagTag.IsNull() {
				fvPeeringPFvFabricExtConnPState.TagTag.ElementsAs(ctx, &tagTagFvPeeringPFvFabricExtConnPState, false)
			}
			if !fvPeeringPFvFabricExtConnPPlan.TagTag.IsNull() && !fvPeeringPFvFabricExtConnPPlan.TagTag.IsUnknown() {
				tagTagIdentifiers := []TagTagIdentifier{}
				for _, tagTagFvPeeringPFvFabricExtConnP := range tagTagFvPeeringPFvFabricExtConnPPlan {
					tagTagFvPeeringPFvFabricExtConnPChildMap := NewAciObject()
					if !tagTagFvPeeringPFvFabricExtConnP.Key.IsNull() && !tagTagFvPeeringPFvFabricExtConnP.Key.IsUnknown() {
						tagTagFvPeeringPFvFabricExtConnPChildMap.Attributes["key"] = tagTagFvPeeringPFvFabricExtConnP.Key.ValueString()
					}
					if !tagTagFvPeeringPFvFabricExtConnP.Value.IsNull() && !tagTagFvPeeringPFvFabricExtConnP.Value.IsUnknown() {
						tagTagFvPeeringPFvFabricExtConnPChildMap.Attributes["value"] = tagTagFvPeeringPFvFabricExtConnP.Value.ValueString()
					}
					FvPeeringPFvFabricExtConnPChildren = append(FvPeeringPFvFabricExtConnPChildren, map[string]interface{}{"tagTag": tagTagFvPeeringPFvFabricExtConnPChildMap})
					tagTagIdentifier := TagTagIdentifier{}
					tagTagIdentifier.Key = tagTagFvPeeringPFvFabricExtConnP.Key
					tagTagIdentifiers = append(tagTagIdentifiers, tagTagIdentifier)
				}
				for _, tagTagFvPeeringPFvFabricExtConnP := range tagTagFvPeeringPFvFabricExtConnPState {
					delete := true
					for _, tagTagIdentifier := range tagTagIdentifiers {
						if tagTagIdentifier.Key == tagTagFvPeeringPFvFabricExtConnP.Key {
							delete = false
							break
						}
					}
					if delete {
						tagTagFvPeeringPFvFabricExtConnPChildMapForDelete := NewAciObject()
						tagTagFvPeeringPFvFabricExtConnPChildMapForDelete.Attributes["status"] = "deleted"
						tagTagFvPeeringPFvFabricExtConnPChildMapForDelete.Attributes["key"] = tagTagFvPeeringPFvFabricExtConnP.Key.ValueString()
						FvPeeringPFvFabricExtConnPChildren = append(FvPeeringPFvFabricExtConnPChildren, map[string]interface{}{"tagTag": tagTagFvPeeringPFvFabricExtConnPChildMapForDelete})
					}
				}
			}
			childMap.Children = FvPeeringPFvFabricExtConnPChildren
			childPayloads = append(childPayloads, map[string]interface{}{"fvPeeringP": childMap})
		}
	} else {
		FvPeeringPObject, _ := types.ObjectValueFrom(ctx, FvPeeringPFvFabricExtConnPType, getEmptyFvPeeringPFvFabricExtConnPResourceModel())
		data.FvPeeringP = FvPeeringPObject
	}

	return childPayloads
}

func getFvFabricExtConnPTagAnnotationChildPayloads(ctx context.Context, diags *diag.Diagnostics, data *FvFabricExtConnPResourceModel, tagAnnotationFvFabricExtConnPPlan, tagAnnotationFvFabricExtConnPState []TagAnnotationFvFabricExtConnPResourceModel) []map[string]interface{} {
	childPayloads := []map[string]interface{}{}
	if !data.TagAnnotation.IsNull() && !data.TagAnnotation.IsUnknown() {
		tagAnnotationIdentifiers := []TagAnnotationIdentifier{}
		for _, tagAnnotationFvFabricExtConnP := range tagAnnotationFvFabricExtConnPPlan {
			childMap := NewAciObject()
			if !tagAnnotationFvFabricExtConnP.Key.IsNull() && !tagAnnotationFvFabricExtConnP.Key.IsUnknown() {
				childMap.Attributes["key"] = tagAnnotationFvFabricExtConnP.Key.ValueString()
			}
			if !tagAnnotationFvFabricExtConnP.Value.IsNull() && !tagAnnotationFvFabricExtConnP.Value.IsUnknown() {
				childMap.Attributes["value"] = tagAnnotationFvFabricExtConnP.Value.ValueString()
			}
			childPayloads = append(childPayloads, map[string]interface{}{"tagAnnotation": childMap})
			tagAnnotationIdentifier := TagAnnotationIdentifier{}
			tagAnnotationIdentifier.Key = tagAnnotationFvFabricExtConnP.Key
			tagAnnotationIdentifiers = append(tagAnnotationIdentifiers, tagAnnotationIdentifier)
		}
		for _, tagAnnotation := range tagAnnotationFvFabricExtConnPState {
			delete := true
			for _, tagAnnotationIdentifier := range tagAnnotationIdentifiers {
				if tagAnnotationIdentifier.Key == tagAnnotation.Key {
					delete = false
					break
				}
			}
			if delete {
				tagAnnotationChildMapForDelete := NewAciObject()
				tagAnnotationChildMapForDelete.Attributes["status"] = "deleted"
				tagAnnotationChildMapForDelete.Attributes["key"] = tagAnnotation.Key.ValueString()
				childPayloads = append(childPayloads, map[string]interface{}{"tagAnnotation": tagAnnotationChildMapForDelete})
			}
		}
	} else {
		data.TagAnnotation = types.SetNull(data.TagAnnotation.ElementType(ctx))
	}

	return childPayloads
}

func getFvFabricExtConnPTagTagChildPayloads(ctx context.Context, diags *diag.Diagnostics, data *FvFabricExtConnPResourceModel, tagTagFvFabricExtConnPPlan, tagTagFvFabricExtConnPState []TagTagFvFabricExtConnPResourceModel) []map[string]interface{} {
	childPayloads := []map[string]interface{}{}
	if !data.TagTag.IsNull() && !data.TagTag.IsUnknown() {
		tagTagIdentifiers := []TagTagIdentifier{}
		for _, tagTagFvFabricExtConnP := range tagTagFvFabricExtConnPPlan {
			childMap := NewAciObject()
			if !tagTagFvFabricExtConnP.Key.IsNull() && !tagTagFvFabricExtConnP.Key.IsUnknown() {
				childMap.Attributes["key"] = tagTagFvFabricExtConnP.Key.ValueString()
			}
			if !tagTagFvFabricExtConnP.Value.IsNull() && !tagTagFvFabricExtConnP.Value.IsUnknown() {
				childMap.Attributes["value"] = tagTagFvFabricExtConnP.Value.ValueString()
			}
			childPayloads = append(childPayloads, map[string]interface{}{"tagTag": childMap})
			tagTagIdentifier := TagTagIdentifier{}
			tagTagIdentifier.Key = tagTagFvFabricExtConnP.Key
			tagTagIdentifiers = append(tagTagIdentifiers, tagTagIdentifier)
		}
		for _, tagTag := range tagTagFvFabricExtConnPState {
			delete := true
			for _, tagTagIdentifier := range tagTagIdentifiers {
				if tagTagIdentifier.Key == tagTag.Key {
					delete = false
					break
				}
			}
			if delete {
				tagTagChildMapForDelete := NewAciObject()
				tagTagChildMapForDelete.Attributes["status"] = "deleted"
				tagTagChildMapForDelete.Attributes["key"] = tagTag.Key.ValueString()
				childPayloads = append(childPayloads, map[string]interface{}{"tagTag": tagTagChildMapForDelete})
			}
		}
	} else {
		data.TagTag = types.SetNull(data.TagTag.ElementType(ctx))
	}

	return childPayloads
}

func getFvFabricExtConnPCreateJsonPayload(ctx context.Context, diags *diag.Diagnostics, createType bool, data *FvFabricExtConnPResourceModel, fvPeeringPPlan, fvPeeringPState FvPeeringPFvFabricExtConnPResourceModel, tagAnnotationPlan, tagAnnotationState []TagAnnotationFvFabricExtConnPResourceModel, tagTagPlan, tagTagState []TagTagFvFabricExtConnPResourceModel) *container.Container {
	payloadMap := map[string]interface{}{}
	payloadMap["attributes"] = map[string]string{}

	if createType && !globalAllowExistingOnCreate {
		payloadMap["attributes"].(map[string]string)["status"] = "created"
	}
	childPayloads := []map[string]interface{}{}

	FvPeeringPchildPayloads := getFvFabricExtConnPFvPeeringPChildPayloads(ctx, diags, data, fvPeeringPPlan, fvPeeringPState)
	if FvPeeringPchildPayloads == nil {
		return nil
	}
	childPayloads = append(childPayloads, FvPeeringPchildPayloads...)

	TagAnnotationchildPayloads := getFvFabricExtConnPTagAnnotationChildPayloads(ctx, diags, data, tagAnnotationPlan, tagAnnotationState)
	if TagAnnotationchildPayloads == nil {
		return nil
	}
	childPayloads = append(childPayloads, TagAnnotationchildPayloads...)

	TagTagchildPayloads := getFvFabricExtConnPTagTagChildPayloads(ctx, diags, data, tagTagPlan, tagTagState)
	if TagTagchildPayloads == nil {
		return nil
	}
	childPayloads = append(childPayloads, TagTagchildPayloads...)

	payloadMap["children"] = childPayloads
	if !data.Annotation.IsNull() && !data.Annotation.IsUnknown() {
		payloadMap["attributes"].(map[string]string)["annotation"] = data.Annotation.ValueString()
	}
	if !data.Descr.IsNull() && !data.Descr.IsUnknown() {
		payloadMap["attributes"].(map[string]string)["descr"] = data.Descr.ValueString()
	}
	if !data.FvFabricExtConnPId.IsNull() && !data.FvFabricExtConnPId.IsUnknown() {
		payloadMap["attributes"].(map[string]string)["id"] = data.FvFabricExtConnPId.ValueString()
	}
	if !data.Name.IsNull() && !data.Name.IsUnknown() {
		payloadMap["attributes"].(map[string]string)["name"] = data.Name.ValueString()
	}
	if !data.NameAlias.IsNull() && !data.NameAlias.IsUnknown() {
		payloadMap["attributes"].(map[string]string)["nameAlias"] = data.NameAlias.ValueString()
	}
	if !data.OwnerKey.IsNull() && !data.OwnerKey.IsUnknown() {
		payloadMap["attributes"].(map[string]string)["ownerKey"] = data.OwnerKey.ValueString()
	}
	if !data.OwnerTag.IsNull() && !data.OwnerTag.IsUnknown() {
		payloadMap["attributes"].(map[string]string)["ownerTag"] = data.OwnerTag.ValueString()
	}
	if !data.Rt.IsNull() && !data.Rt.IsUnknown() {
		payloadMap["attributes"].(map[string]string)["rt"] = data.Rt.ValueString()
	}
	if !data.SiteId.IsNull() && !data.SiteId.IsUnknown() {
		payloadMap["attributes"].(map[string]string)["siteId"] = data.SiteId.ValueString()
	}
	payload, err := json.Marshal(map[string]interface{}{"fvFabricExtConnP": payloadMap})
	if err != nil {
		diags.AddError(
			"Marshalling of json payload failed",
			fmt.Sprintf("Err: %s. Please report this issue to the provider developers.", err),
		)
		return nil
	}

	jsonPayload, err := container.ParseJSON(payload)

	if err != nil {
		diags.AddError(
			"Construction of json payload failed",
			fmt.Sprintf("Err: %s. Please report this issue to the provider developers.", err),
		)
		return nil
	}
	return jsonPayload
}
