diff --git a/.changelog/538.txt b/.changelog/538.txt new file mode 100644 index 00000000..09629ca0 --- /dev/null +++ b/.changelog/538.txt @@ -0,0 +1,7 @@ +```release-note:breaking-change +`resource/cloudavenue_vapp_org_network` - `is_fenced` and `retain_ip_mac_enabled` are now removed from the schema. +``` + +```release-note:breaking-change +`datasource/cloudavenue_vapp_org_network` - `is_fenced` and `retain_ip_mac_enabled` are now removed from the schema. +``` diff --git a/docs/data-sources/vapp_org_network.md b/docs/data-sources/vapp_org_network.md index d5da90f8..aedeca72 100644 --- a/docs/data-sources/vapp_org_network.md +++ b/docs/data-sources/vapp_org_network.md @@ -77,6 +77,4 @@ data "cloudavenue_vapp_org_network" "example" { ### Read-Only - `id` (String) The ID of the network. -- `is_fenced` (Boolean) Defines if the network is fenced. Fencing allows identical virtual machines in different vApp networks connect to organization VDC networks that are accessed in this vApp. -- `retain_ip_mac_enabled` (Boolean) Specifies whether the network resources such as IP/MAC of router will be retained across deployments. diff --git a/docs/resources/vapp_org_network.md b/docs/resources/vapp_org_network.md index f7423663..20d75e2d 100644 --- a/docs/resources/vapp_org_network.md +++ b/docs/resources/vapp_org_network.md @@ -68,8 +68,6 @@ resource "cloudavenue_vapp_org_network" "example" { ### Optional -- `is_fenced` (Boolean) Defines if the network is fenced. Fencing allows identical virtual machines in different vApp networks connect to organization VDC networks that are accessed in this vApp. Value defaults to `false`. -- `retain_ip_mac_enabled` (Boolean) Specifies whether the network resources such as IP/MAC of router will be retained across deployments. Value defaults to `false`. - `vapp_id` (String) (ForceNew) ID of the vApp. Ensure that one and only one attribute from this collection is set : `vapp_name`, `vapp_id`. - `vapp_name` (String) (ForceNew) Name of the vApp. Ensure that one and only one attribute from this collection is set : `vapp_id`, `vapp_name`. - `vdc` (String) (ForceNew) The name of vDC to use, optional if defined at provider level. diff --git a/internal/provider/common/network/schema.go b/internal/provider/common/network/schema.go index 7e6bcc5d..53667d66 100644 --- a/internal/provider/common/network/schema.go +++ b/internal/provider/common/network/schema.go @@ -7,7 +7,6 @@ import ( schemaD "github.com/hashicorp/terraform-plugin-framework/datasource/schema" schemaR "github.com/hashicorp/terraform-plugin-framework/resource/schema" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" @@ -356,26 +355,6 @@ func GetSchema(opts ...networkSchemaOpts) superschema.Schema { }, }, } - _schema.Attributes["is_fenced"] = superschema.BoolAttribute{ - Common: &schemaR.BoolAttribute{ - MarkdownDescription: "Defines if the network is fenced. Fencing allows identical virtual machines in different vApp networks connect to organization VDC networks that are accessed in this vApp.", - Computed: true, - }, - Resource: &schemaR.BoolAttribute{ - Optional: true, - Default: booldefault.StaticBool(false), - }, - } - _schema.Attributes["retain_ip_mac_enabled"] = superschema.BoolAttribute{ - Common: &schemaR.BoolAttribute{ - MarkdownDescription: "Specifies whether the network resources such as IP/MAC of router will be retained across deployments.", - Computed: true, - }, - Resource: &schemaR.BoolAttribute{ - Optional: true, - Default: booldefault.StaticBool(false), - }, - } } return _schema } diff --git a/internal/provider/vapp/org_network_datasource.go b/internal/provider/vapp/org_network_datasource.go index 70ef2245..609ede6b 100644 --- a/internal/provider/vapp/org_network_datasource.go +++ b/internal/provider/vapp/org_network_datasource.go @@ -121,24 +121,13 @@ func (d *orgNetworkDataSource) Read(ctx context.Context, req datasource.ReadRequ return } - // Set Attributes - var isFenced, retainIPMacEnabled bool - if vAppNetwork.Configuration == nil { - // Set default value if configuration return is nil - vAppNetwork.Configuration = &govcdtypes.NetworkConfiguration{} - } else { - isFenced = vAppNetwork.Configuration.FenceMode == govcdtypes.FenceModeNAT - retainIPMacEnabled = *vAppNetwork.Configuration.RetainNetInfoAcrossDeployments - } // Set data plan := &orgNetworkModel{ - ID: types.StringValue(uuid.Normalize(uuid.Network, *networkID).String()), - VAppName: utils.StringValueOrNull(d.vapp.GetName()), - VAppID: utils.StringValueOrNull(d.vapp.GetID()), - VDC: types.StringValue(d.vdc.GetName()), - NetworkName: data.NetworkName, - IsFenced: types.BoolValue(isFenced), - RetainIPMacEnabled: types.BoolValue(retainIPMacEnabled), + ID: types.StringValue(uuid.Normalize(uuid.Network, *networkID).String()), + VAppName: utils.StringValueOrNull(d.vapp.GetName()), + VAppID: utils.StringValueOrNull(d.vapp.GetID()), + VDC: types.StringValue(d.vdc.GetName()), + NetworkName: data.NetworkName, } // Save data into Terraform state diff --git a/internal/provider/vapp/org_network_resource.go b/internal/provider/vapp/org_network_resource.go index a7436042..3128afae 100644 --- a/internal/provider/vapp/org_network_resource.go +++ b/internal/provider/vapp/org_network_resource.go @@ -16,13 +16,12 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource" - "github.com/hashicorp/terraform-plugin-log/tflog" - "github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/client" "github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/metrics" "github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/common/network" "github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/common/vapp" "github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/common/vdc" + "github.com/orange-cloudavenue/terraform-provider-cloudavenue/pkg/utils" "github.com/orange-cloudavenue/terraform-provider-cloudavenue/pkg/uuid" ) @@ -120,12 +119,10 @@ func (r *orgNetworkResource) Create(ctx context.Context, req resource.CreateRequ return } - retainIPMac := plan.RetainIPMacEnabled.ValueBool() - isFenced := plan.IsFenced.ValueBool() - - vappNetworkSettings := &govcd.VappNetworkSettings{RetainIpMacEnabled: &retainIPMac} + // RetainIpMacEnabled and IsFenced are always false in CloudAvenue - vAppNetworkConfig, err := r.vapp.AddOrgNetwork(vappNetworkSettings, orgNetwork.OrgVDCNetwork, isFenced) + vappNetworkSettings := &govcd.VappNetworkSettings{RetainIpMacEnabled: utils.TakeBoolPointer(false)} + vAppNetworkConfig, err := r.vapp.AddOrgNetwork(vappNetworkSettings, orgNetwork.OrgVDCNetwork, false) if err != nil { resp.Diagnostics.AddError("Error creating vApp network", err.Error()) return @@ -150,20 +147,15 @@ func (r *orgNetworkResource) Create(ctx context.Context, req resource.CreateRequ } state := &orgNetworkModel{ - ID: types.StringValue(uuid.Normalize(uuid.Network, networkID).String()), - VAppName: plan.VAppName, - VAppID: plan.VAppID, - VDC: types.StringValue(r.vdc.GetName()), - NetworkName: plan.NetworkName, - IsFenced: plan.IsFenced, - RetainIPMacEnabled: plan.RetainIPMacEnabled, + ID: types.StringValue(uuid.Normalize(uuid.Network, networkID).String()), + VAppName: plan.VAppName, + VAppID: plan.VAppID, + VDC: types.StringValue(r.vdc.GetName()), + NetworkName: plan.NetworkName, } // Set state to fully populated data resp.Diagnostics.Append(resp.State.Set(ctx, &state)...) - if resp.Diagnostics.HasError() { - return - } } // Read refreshes the Terraform state with the latest data. @@ -184,7 +176,6 @@ func (r *orgNetworkResource) Read(ctx context.Context, req resource.ReadRequest, return } - // Delete resource require vApp is Powered Off // Lock resp.Diagnostics.Append(r.vapp.LockVAPP(ctx)...) if resp.Diagnostics.HasError() { @@ -199,8 +190,8 @@ func (r *orgNetworkResource) Read(ctx context.Context, req resource.ReadRequest, return } - vAppNetwork, networkID, errFindNetwork := state.findOrgNetwork(vAppNetworkConfig) - resp.Diagnostics.Append(errFindNetwork...) + vAppNetwork, networkID, d := state.findOrgNetwork(vAppNetworkConfig) + resp.Diagnostics.Append(d...) if resp.Diagnostics.HasError() { return } @@ -210,99 +201,22 @@ func (r *orgNetworkResource) Read(ctx context.Context, req resource.ReadRequest, return } - isFenced := vAppNetwork.Configuration.FenceMode == govcdtypes.FenceModeNAT - plan := &orgNetworkModel{ - ID: types.StringValue(uuid.Normalize(uuid.Network, *networkID).String()), - VAppName: state.VAppName, - VAppID: state.VAppID, - VDC: types.StringValue(r.vdc.GetName()), - NetworkName: state.NetworkName, - IsFenced: types.BoolValue(isFenced), - RetainIPMacEnabled: types.BoolValue(*vAppNetwork.Configuration.RetainNetInfoAcrossDeployments), + ID: types.StringValue(uuid.Normalize(uuid.Network, *networkID).String()), + VAppName: state.VAppName, + VAppID: state.VAppID, + VDC: types.StringValue(r.vdc.GetName()), + NetworkName: state.NetworkName, } // Set refreshed state resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...) - if resp.Diagnostics.HasError() { - return - } } // Update updates the resource and sets the updated Terraform state on success. func (r *orgNetworkResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { defer metrics.New("cloudavenue_vapp_org_network", r.client.GetOrgName(), metrics.Update)() - - var plan, state *orgNetworkModel - - // Get current state - resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) - resp.Diagnostics.Append(req.State.Get(ctx, &state)...) - if resp.Diagnostics.HasError() { - return - } - - // Init resource - resp.Diagnostics.Append(r.Init(ctx, plan)...) - if resp.Diagnostics.HasError() { - return - } - - // Lock vApp - resp.Diagnostics.Append(r.vapp.LockVAPP(ctx)...) - if resp.Diagnostics.HasError() { - return - } - defer r.vapp.UnlockVAPP(ctx) - - vAppNetworkConfig, err := r.vapp.GetNetworkConfig() - if err != nil { - resp.Diagnostics.AddError("Error retrieving vApp network config", err.Error()) - return - } - - vAppNetwork, _, errFindNetwork := plan.findOrgNetwork(vAppNetworkConfig) - resp.Diagnostics.Append(errFindNetwork...) - if resp.Diagnostics.HasError() { - return - } - - if vAppNetwork == (&govcdtypes.VAppNetworkConfiguration{}) { - resp.State.RemoveResource(ctx) - return - } - - isFenced := vAppNetwork.Configuration.FenceMode == govcdtypes.FenceModeNAT - - if plan.IsFenced.ValueBool() != isFenced || plan.RetainIPMacEnabled.ValueBool() != *vAppNetwork.Configuration.RetainNetInfoAcrossDeployments { - tflog.Debug(ctx, "updating vApp network") - retainIP := plan.RetainIPMacEnabled.ValueBool() - vappNetworkSettings := &govcd.VappNetworkSettings{ - ID: state.ID.ValueString(), - RetainIpMacEnabled: &retainIP, - } - _, err = r.vapp.UpdateOrgNetwork(vappNetworkSettings, plan.IsFenced.ValueBool()) - if err != nil { - resp.Diagnostics.AddError("Error updating vApp network", err.Error()) - return - } - } - - plan = &orgNetworkModel{ - ID: state.ID, - VAppName: state.VAppName, - VAppID: state.VAppID, - VDC: state.VDC, - NetworkName: state.NetworkName, - IsFenced: plan.IsFenced, - RetainIPMacEnabled: plan.RetainIPMacEnabled, - } - - // Set state to fully populated data - resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...) - if resp.Diagnostics.HasError() { - return - } + // No update for this resource } // Delete deletes the resource and removes the Terraform state on success. @@ -423,7 +337,4 @@ func (r *orgNetworkResource) ImportState(ctx context.Context, req resource.Impor // Set state to fully populated data resp.Diagnostics.Append(resp.State.Set(ctx, &state)...) - if resp.Diagnostics.HasError() { - return - } } diff --git a/internal/provider/vapp/vapp_types.go b/internal/provider/vapp/vapp_types.go index 8cf4a777..ced2bd34 100644 --- a/internal/provider/vapp/vapp_types.go +++ b/internal/provider/vapp/vapp_types.go @@ -16,11 +16,9 @@ var vappLeaseAttrTypes = map[string]attr.Type{ } type orgNetworkModel struct { - ID types.String `tfsdk:"id"` - VAppName types.String `tfsdk:"vapp_name"` - VAppID types.String `tfsdk:"vapp_id"` - VDC types.String `tfsdk:"vdc"` - NetworkName types.String `tfsdk:"network_name"` - IsFenced types.Bool `tfsdk:"is_fenced"` - RetainIPMacEnabled types.Bool `tfsdk:"retain_ip_mac_enabled"` + ID types.String `tfsdk:"id"` + VAppName types.String `tfsdk:"vapp_name"` + VAppID types.String `tfsdk:"vapp_id"` + VDC types.String `tfsdk:"vdc"` + NetworkName types.String `tfsdk:"network_name"` } diff --git a/internal/testsacc/acctest.go b/internal/testsacc/acctest.go index d60a1842..0961fd69 100644 --- a/internal/testsacc/acctest.go +++ b/internal/testsacc/acctest.go @@ -3,6 +3,7 @@ package testsacc import ( "context" + "log" "os" "testing" @@ -53,6 +54,7 @@ func TestAccPreCheck(t *testing.T) { // Not error checking here because it's not critical. x, _ := uuid.NewUUID() metrics.GlobalExecutionID = "testacc_" + x.String() + log.Default().Printf("TestACC: execution ID is %s", metrics.GlobalExecutionID) } // Deprecated: Use ContactConfigs instead. diff --git a/internal/testsacc/vapp_org_network_datasource_test.go b/internal/testsacc/vapp_org_network_datasource_test.go index e8494901..3c54ee8b 100644 --- a/internal/testsacc/vapp_org_network_datasource_test.go +++ b/internal/testsacc/vapp_org_network_datasource_test.go @@ -74,8 +74,6 @@ func TestAccOrgNetworkDataSource(t *testing.T) { Check: resource.ComposeAggregateTestCheckFunc( resource.TestMatchResourceAttr(resourceName, "id", regexp.MustCompile(uuid.Network.String()+`[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}`)), resource.TestCheckResourceAttrPair(dataSourceName, "network_name", resourceName, "network_name"), - resource.TestCheckResourceAttrPair(dataSourceName, "is_fenced", resourceName, "is_fenced"), - resource.TestCheckResourceAttrPair(dataSourceName, "retain_ip_mac_enabled", resourceName, "retain_ip_mac_enabled"), ), }, }, diff --git a/internal/testsacc/vapp_org_network_resource_test.go b/internal/testsacc/vapp_org_network_resource_test.go index ef459240..3e43c58c 100644 --- a/internal/testsacc/vapp_org_network_resource_test.go +++ b/internal/testsacc/vapp_org_network_resource_test.go @@ -40,11 +40,10 @@ func (r *VAppOrgNetworkResource) Tests(ctx context.Context) map[testsacc.TestNam return testsacc.Test{ CommonChecks: []resource.TestCheckFunc{ resource.TestCheckResourceAttrWith(resourceName, "id", uuid.TestIsType(uuid.Network)), - resource.TestCheckResourceAttrSet(resourceName, "vapp_name"), - resource.TestCheckResourceAttrSet(resourceName, "network_name"), resource.TestCheckResourceAttrSet(resourceName, "vdc"), - // TODO : https://github.com/orange-cloudavenue/terraform-provider-cloudavenue/issues/527 - // resource.TestCheckResourceAttrSet(resourceName, "vapp_id"), + resource.TestCheckResourceAttrSet(resourceName, "network_name"), + resource.TestCheckResourceAttrSet(resourceName, "vapp_name"), + resource.TestCheckNoResourceAttr(resourceName, "vapp_id"), }, // ! Create testing Create: testsacc.TFConfig{ @@ -54,28 +53,10 @@ func (r *VAppOrgNetworkResource) Tests(ctx context.Context) map[testsacc.TestNam network_name = cloudavenue_network_routed.example.name vdc = cloudavenue_vdc.example.name }`), - Checks: []resource.TestCheckFunc{ - resource.TestCheckResourceAttr(resourceName, "is_fenced", "false"), - resource.TestCheckResourceAttr(resourceName, "retain_ip_mac_enabled", "false"), - }, + Checks: []resource.TestCheckFunc{}, }, - // TODO : Impossible to update due to https://github.com/orange-cloudavenue/terraform-provider-cloudavenue/issues/531 and https://github.com/orange-cloudavenue/terraform-provider-cloudavenue/issues/529 - // // ! Updates testing - // Updates: []testsacc.TFConfig{ - // { - // TFConfig: testsacc.GenerateFromTemplate(resourceName, ` - // resource "cloudavenue_vapp_org_network" "example" { - // vapp_name = cloudavenue_vapp.example.name - // network_name = cloudavenue_network_routed.example.name - // vdc = cloudavenue_vdc.example.name - - // retain_ip_mac_enabled = true - // }`), - // Checks: []resource.TestCheckFunc{ - // resource.TestCheckResourceAttr(resourceName, "retain_ip_mac_enabled", "true"), - // }, - // }, - // }, + // ! Update testing + // * No update for this resource // ! Imports testing Imports: []testsacc.TFImport{ {