Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: remove attributs is_fenced and retain_ip_mac_enabled #540

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changelog/538.txt
Original file line number Diff line number Diff line change
@@ -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.
```
2 changes: 0 additions & 2 deletions docs/data-sources/vapp_org_network.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

2 changes: 0 additions & 2 deletions docs/resources/vapp_org_network.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 0 additions & 21 deletions internal/provider/common/network/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
21 changes: 5 additions & 16 deletions internal/provider/vapp/org_network_datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
123 changes: 17 additions & 106 deletions internal/provider/vapp/org_network_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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() {
Expand All @@ -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
}
Expand All @@ -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.
Expand Down Expand Up @@ -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
}
}
12 changes: 5 additions & 7 deletions internal/provider/vapp/vapp_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
2 changes: 2 additions & 0 deletions internal/testsacc/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package testsacc

import (
"context"
"log"
"os"
"testing"

Expand Down Expand Up @@ -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.
Expand Down
2 changes: 0 additions & 2 deletions internal/testsacc/vapp_org_network_datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
},
Expand Down
31 changes: 6 additions & 25 deletions internal/testsacc/vapp_org_network_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{
{
Expand Down