diff --git a/apstra/provider.go b/apstra/provider.go index ca2f84b8..9159e308 100644 --- a/apstra/provider.go +++ b/apstra/provider.go @@ -605,7 +605,6 @@ func (p *Provider) Resources(_ context.Context) []func() resource.Resource { func() resource.Resource { return &resourceDatacenterBlueprint{} }, func() resource.Resource { return &resourceDatacenterConfiglet{} }, func() resource.Resource { return &resourceDatacenterConnectivityTemplateAssignments{} }, - func() resource.Resource { return &resourceDatacenterConnectivityTemplateAssignment{} }, func() resource.Resource { return &resourceDatacenterConnectivityTemplateInterface{} }, func() resource.Resource { return &resourceDatacenterConnectivityTemplateLoopback{} }, func() resource.Resource { return &resourceDatacenterConnectivityTemplateSvi{} }, diff --git a/apstra/resource_datacenter_connectivity_template_assignment.go b/apstra/resource_datacenter_connectivity_template_assignment.go deleted file mode 100644 index 606d9ab0..00000000 --- a/apstra/resource_datacenter_connectivity_template_assignment.go +++ /dev/null @@ -1,236 +0,0 @@ -package tfapstra - -import ( - "context" - "fmt" - - "github.com/Juniper/apstra-go-sdk/apstra" - "github.com/Juniper/terraform-provider-apstra/apstra/blueprint" - "github.com/Juniper/terraform-provider-apstra/apstra/utils" - "github.com/hashicorp/terraform-plugin-framework/resource" - "github.com/hashicorp/terraform-plugin-framework/resource/schema" - "github.com/hashicorp/terraform-plugin-framework/types" -) - -var ( - _ resource.ResourceWithConfigure = &resourceDatacenterConnectivityTemplateAssignment{} - _ resourceWithSetDcBpClientFunc = &resourceDatacenterConnectivityTemplateAssignment{} - _ resourceWithSetBpLockFunc = &resourceDatacenterConnectivityTemplateAssignment{} -) - -type resourceDatacenterConnectivityTemplateAssignment struct { - getBpClientFunc func(context.Context, string) (*apstra.TwoStageL3ClosClient, error) - lockFunc func(context.Context, string) error -} - -func (o *resourceDatacenterConnectivityTemplateAssignment) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { - resp.TypeName = req.ProviderTypeName + "_datacenter_connectivity_template_assignment" -} - -func (o *resourceDatacenterConnectivityTemplateAssignment) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { - configureResource(ctx, o, req, resp) -} - -func (o *resourceDatacenterConnectivityTemplateAssignment) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { - deprecationMessage := "This resource has been deprecated and will be removed in a future release. Please migrate " + - "your configuration to use the `apstra_datacenter_connectivity_templates_assignment` resource." - resp.Schema = schema.Schema{ - DeprecationMessage: deprecationMessage, - MarkdownDescription: docCategoryDatacenter + "**Deprecation Warning**\n\n" + deprecationMessage + - "\n\nThis resource assigns one or more Connectivity Templates to an " + - "Application Point. Application Points are graph nodes including interfaces at the " + - "fabric edge, and switches within the fabric.", - Attributes: blueprint.ConnectivityTemplatesAssignment{}.ResourceAttributes(), - } -} - -func (o *resourceDatacenterConnectivityTemplateAssignment) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { - // Retrieve values from plan. - var plan blueprint.ConnectivityTemplatesAssignment - resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) - if resp.Diagnostics.HasError() { - return - } - - // get a client for the datacenter reference design - bp, err := o.getBpClientFunc(ctx, plan.BlueprintId.ValueString()) - if err != nil { - if utils.IsApstra404(err) { - resp.Diagnostics.AddError(fmt.Sprintf("blueprint %s not found", plan.BlueprintId), err.Error()) - return - } - resp.Diagnostics.AddError("failed to create blueprint client", err.Error()) - return - } - - // Lock the blueprint mutex. - err = o.lockFunc(ctx, plan.BlueprintId.ValueString()) - if err != nil { - resp.Diagnostics.AddError( - fmt.Sprintf("failed locking blueprint %q mutex", plan.BlueprintId.ValueString()), - err.Error()) - return - } - - addIds, _ := plan.AddDelRequest(ctx, nil, &resp.Diagnostics) - err = bp.SetApplicationPointConnectivityTemplates(ctx, apstra.ObjectId(plan.ApplicationPointId.ValueString()), addIds) - if err != nil { - resp.Diagnostics.AddError("failed applying Connectivity Template", err.Error()) - return - } - - resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...) -} - -func (o *resourceDatacenterConnectivityTemplateAssignment) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { - // Retrieve values from state - var state blueprint.ConnectivityTemplatesAssignment - resp.Diagnostics.Append(req.State.Get(ctx, &state)...) - if resp.Diagnostics.HasError() { - return - } - - // get a client for the datacenter reference design - bp, err := o.getBpClientFunc(ctx, state.BlueprintId.ValueString()) - if err != nil { - if utils.IsApstra404(err) { - resp.State.RemoveResource(ctx) - return - } - resp.Diagnostics.AddError("failed to create blueprint client", err.Error()) - return - } - - // currentCtIds come from the API, may include CTs unrelated to this resource - currentCtIds, err := bp.GetInterfaceConnectivityTemplates(ctx, apstra.ObjectId(state.ApplicationPointId.ValueString())) - if err != nil { - if utils.IsApstra404(err) { - resp.State.RemoveResource(ctx) - return - } - resp.Diagnostics.AddError("failed reading Connectivity Template assignments", err.Error()) - return - } - - // stateCtIds come from the history of this resource. What CTs have been previously assigned? - var stateCtIds []apstra.ObjectId - resp.Diagnostics.Append(state.ConnectivityTemplateIds.ElementsAs(ctx, &stateCtIds, false)...) - if resp.Diagnostics.HasError() { - return - } - - // remainingCtIds are the previously assigned IDs (state) which are still assigned (current) - remainingCtIds := utils.SliceIntersectionOfAB(currentCtIds, stateCtIds) - state.ConnectivityTemplateIds = utils.SetValueOrNull(ctx, types.StringType, remainingCtIds, &resp.Diagnostics) - if resp.Diagnostics.HasError() { - return - } - - // Set state - resp.Diagnostics.Append(resp.State.Set(ctx, &state)...) -} - -func (o *resourceDatacenterConnectivityTemplateAssignment) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { - // Retrieve values from plan - var plan blueprint.ConnectivityTemplatesAssignment - resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) - if resp.Diagnostics.HasError() { - return - } - - // Retrieve values from state - var state blueprint.ConnectivityTemplatesAssignment - resp.Diagnostics.Append(req.State.Get(ctx, &state)...) - if resp.Diagnostics.HasError() { - return - } - - // get a client for the datacenter reference design - bp, err := o.getBpClientFunc(ctx, plan.BlueprintId.ValueString()) - if err != nil { - resp.Diagnostics.AddError("failed to create blueprint client", err.Error()) - return - } - - // Lock the blueprint mutex. - err = o.lockFunc(ctx, plan.BlueprintId.ValueString()) - if err != nil { - resp.Diagnostics.AddError( - fmt.Sprintf("failed locking blueprint %q mutex", plan.BlueprintId.ValueString()), - err.Error()) - return - } - - // calculate the add/del sets - addIds, delIds := plan.AddDelRequest(ctx, &state, &resp.Diagnostics) - if resp.Diagnostics.HasError() { - return - } - - // add any required CTs - err = bp.SetApplicationPointConnectivityTemplates(ctx, apstra.ObjectId(plan.ApplicationPointId.ValueString()), addIds) - if err != nil { - resp.Diagnostics.AddError("failed assigning connectivity templates", err.Error()) - return - } - - // clear any undesired CTs - err = bp.DelApplicationPointConnectivityTemplates(ctx, apstra.ObjectId(plan.ApplicationPointId.ValueString()), delIds) - if err != nil { - resp.Diagnostics.AddError("failed clearing connectivity template assignments", err.Error()) - return - } - - resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...) -} - -func (o *resourceDatacenterConnectivityTemplateAssignment) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { - // Retrieve values from state - var state blueprint.ConnectivityTemplatesAssignment - resp.Diagnostics.Append(req.State.Get(ctx, &state)...) - if resp.Diagnostics.HasError() { - return - } - - // get a client for the datacenter reference design - bp, err := o.getBpClientFunc(ctx, state.BlueprintId.ValueString()) - if err != nil { - if utils.IsApstra404(err) { - return // 404 is okay - } - resp.Diagnostics.AddError("failed to create blueprint client", err.Error()) - return - } - - // Lock the blueprint mutex. - err = o.lockFunc(ctx, state.BlueprintId.ValueString()) - if err != nil { - resp.Diagnostics.AddError( - fmt.Sprintf("failed locking blueprint %q mutex", state.BlueprintId.ValueString()), - err.Error()) - return - } - - var delIds []apstra.ObjectId - resp.Diagnostics.Append(state.ConnectivityTemplateIds.ElementsAs(ctx, &delIds, false)...) - if resp.Diagnostics.HasError() { - return - } - - err = bp.DelApplicationPointConnectivityTemplates(ctx, apstra.ObjectId(state.ApplicationPointId.ValueString()), delIds) - if err != nil { - if utils.IsApstra404(err) { - return // 404 is okay - } - resp.Diagnostics.AddError("failed clearing connectivity template assignments", err.Error()) - return - } -} - -func (o *resourceDatacenterConnectivityTemplateAssignment) setBpClientFunc(f func(context.Context, string) (*apstra.TwoStageL3ClosClient, error)) { - o.getBpClientFunc = f -} - -func (o *resourceDatacenterConnectivityTemplateAssignment) setBpLockFunc(f func(context.Context, string) error) { - o.lockFunc = f -} diff --git a/docs/resources/datacenter_connectivity_template_assignment.md b/docs/resources/datacenter_connectivity_template_assignment.md deleted file mode 100644 index 7275e0d6..00000000 --- a/docs/resources/datacenter_connectivity_template_assignment.md +++ /dev/null @@ -1,60 +0,0 @@ ---- -page_title: "apstra_datacenter_connectivity_template_assignment Resource - terraform-provider-apstra" -subcategory: "Reference Design: Datacenter" -description: |- - Deprecation Warning - This resource has been deprecated and will be removed in a future release. Please migrate your configuration to use the apstra_datacenter_connectivity_templates_assignment resource. - This resource assigns one or more Connectivity Templates to an Application Point. Application Points are graph nodes including interfaces at the fabric edge, and switches within the fabric. ---- - -# apstra_datacenter_connectivity_template_assignment (Resource) - -**Deprecation Warning** - -This resource has been deprecated and will be removed in a future release. Please migrate your configuration to use the `apstra_datacenter_connectivity_templates_assignment` resource. - -This resource assigns one or more Connectivity Templates to an Application Point. Application Points are graph nodes including interfaces at the fabric edge, and switches within the fabric. - - -## Example Usage - -```terraform -# This example assigns two connectivity templates to the switch port -# identified by the ID "FkYtMBdeoJ5urBaIEi8" -# -# Data sources like these can be used to find node IDs to use in -# the `application_point_id` attribute: -# - apstra_datacenter_svis_map -# - apstra_datacenter_interfaces_by_link_tag -# - apstra_datacenter_interfaces_by_system - -resource "apstra_datacenter_connectivity_template_assignment" "a" { - blueprint_id = "b726704d-f80e-4733-9103-abd6ccd8752c" - application_point_id = "FkYtMBdeoJ5urBaIEi8" - connectivity_template_ids = [ - "bcbcb35f-8f23-4bfb-916e-1b21d07d6904", - "1f8ac61f-6996-42bb-a34f-4f4a50a7111a", - ] -} -``` - - -## Schema - -### Required - -- `application_point_id` (String) Apstra node ID of the Interface or System where the Connectivity Templates should be applied. -- `blueprint_id` (String) Apstra Blueprint ID. -- `connectivity_template_ids` (Set of String) Set of Connectivity Template IDs which should be applied to the Application Point. - -### Optional - -- `fetch_ip_link_ids` (Boolean) When `true`, the read-only `ip_link_ids` attribute will be populated. Default behavior skips retrieving `ip_link_ids` to improve performance in scenarios where this information is not needed. - -### Read-Only - -- `ip_link_ids` (Map of Map of String) New Logical Links are created when Connectivity Templates containing *IP Link* primitives are attached to a switch interface. These logical links may or may not be VLAN-tagged. This attribute is a two-dimensional map. The outer map is keyed by Connectivity Template ID. The inner map is keyed by VLAN number. Untagged Logical Links are represented in the inner map by key `0`. -**Note:** requires `fetch_iplink_ids = true` - - - diff --git a/examples/resources/apstra_datacenter_connectivity_template_assignment/example.tf b/examples/resources/apstra_datacenter_connectivity_template_assignment/example.tf deleted file mode 100644 index 60e4fdc2..00000000 --- a/examples/resources/apstra_datacenter_connectivity_template_assignment/example.tf +++ /dev/null @@ -1,17 +0,0 @@ -# This example assigns two connectivity templates to the switch port -# identified by the ID "FkYtMBdeoJ5urBaIEi8" -# -# Data sources like these can be used to find node IDs to use in -# the `application_point_id` attribute: -# - apstra_datacenter_svis_map -# - apstra_datacenter_interfaces_by_link_tag -# - apstra_datacenter_interfaces_by_system - -resource "apstra_datacenter_connectivity_template_assignment" "a" { - blueprint_id = "b726704d-f80e-4733-9103-abd6ccd8752c" - application_point_id = "FkYtMBdeoJ5urBaIEi8" - connectivity_template_ids = [ - "bcbcb35f-8f23-4bfb-916e-1b21d07d6904", - "1f8ac61f-6996-42bb-a34f-4f4a50a7111a", - ] -}