Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Dainius Serplis <[email protected]>
  • Loading branch information
Didainius committed Feb 25, 2022
1 parent 19fece5 commit 6136be6
Show file tree
Hide file tree
Showing 9 changed files with 341 additions and 383 deletions.
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ go 1.13

require (
github.com/aws/aws-sdk-go v1.30.12 // indirect
github.com/davecgh/go-spew v1.1.1
github.com/hashicorp/go-version v1.3.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.10.0
github.com/kr/pretty v0.2.1
github.com/vmware/go-vcloud-director/v2 v2.15.0-alpha.2
)

replace github.com/vmware/go-vcloud-director/v2 => github.com/Didainius/go-vcloud-director/v2 v2.14.0-rc.3.0.20220224105842-a5e8ff3d2bff
//replace github.com/vmware/go-vcloud-director/v2 => github.com/Didainius/go-vcloud-director/v2 v2.14.0-rc.3.0.20220224195422-2a5f827ef552

//replace github.com/vmware/go-vcloud-director/v2 => ../go-vcloud-director
//replace github.com/vmware/go-vcloud-director/v2 => github.com/Didainius/go-vcloud-director/v2 v2.12.1-0.20211018060826-c7f8ab32330e
replace github.com/vmware/go-vcloud-director/v2 => ../go-vcloud-director
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/Didainius/go-vcloud-director/v2 v2.14.0-rc.3.0.20220224105842-a5e8ff3d2bff h1:UTCMFS6+5HhgRqg3Ncm1Y53i7KiLWTMf71K9nPMt2CY=
github.com/Didainius/go-vcloud-director/v2 v2.14.0-rc.3.0.20220224105842-a5e8ff3d2bff/go.mod h1:2BS1yw61VN34WI0/nUYoInFvBc3Zcuf84d4ESiAAl68=
github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
github.com/Masterminds/sprig v2.22.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o=
Expand Down
10 changes: 0 additions & 10 deletions vcd/datasource_vcd_nsxt_edgegateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,3 @@ func datasourceVcdNsxtEdgeGatewayRead(ctx context.Context, d *schema.ResourceDat

return nil
}

//func getOwnerOrVdc(d *schema.ResourceData, vcdClient *VCDClient) {
// inheritedVdcField := vcdClient.Vdc
// vdcField := d.Get("vdc").(string)
// ownerIdField := d.Get("owner_id").(string)
// startingVdcId := d.Get("starting_vdc_id").(string)
//
//
//
//}
10 changes: 6 additions & 4 deletions vcd/datasource_vcd_nsxt_edgegateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestAccVcdNsxtEdgeGatewayMultipleSubnetsAndDS(t *testing.T) {
ProviderFactories: testAccProviders,
CheckDestroy: testAccCheckVcdNsxtEdgeGatewayDestroy(params["NsxtEdgeGatewayVcd"].(string)),
Steps: []resource.TestStep{
resource.TestStep{
{
Config: configText,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("vcd_nsxt_edgegateway.nsxt-edge", "name", params["NsxtEdgeGatewayVcd"].(string)),
Expand Down Expand Up @@ -96,20 +96,22 @@ func TestAccVcdNsxtEdgeGatewayMultipleSubnetsAndDS(t *testing.T) {
}),
),
},
resource.TestStep{
{
ResourceName: "vcd_nsxt_edgegateway.nsxt-edge",
ImportState: true,
ImportStateVerify: true,
ImportStateIdFunc: importStateIdOrgNsxtVdcObject(testConfig, params["NsxtEdgeGatewayVcd"].(string)),
},
resource.TestStep{
{
Config: configText1,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("vcd_nsxt_edgegateway.nsxt-edge", "name", params["NsxtEdgeGatewayVcd"].(string)),
resource.TestCheckResourceAttrPair("vcd_nsxt_edgegateway.nsxt-edge", "name", "data.vcd_nsxt_edgegateway.egw-ds", "name"),
resource.TestCheckResourceAttrPair("vcd_nsxt_edgegateway.nsxt-edge", "external_network_id", "data.vcd_nsxt_edgegateway.egw-ds", "external_network_id"),
resource.TestCheckResourceAttrPair("vcd_nsxt_edgegateway.nsxt-edge", "subnet", "data.vcd_nsxt_edgegateway.egw-ds", "subnet"),
// Ensure all attributes are available on data source as on the resource itself
// Field count is ignored because having `starting_vdc_id` in data source does
// not make sense
resourceFieldsEqual("vcd_nsxt_edgegateway.nsxt-edge", "data.vcd_nsxt_edgegateway.egw-ds", []string{"%"}),
),
},
Expand Down Expand Up @@ -282,7 +284,7 @@ func TestAccVcdNsxtEdgeGatewayDSDoesNotAcceptNsxv(t *testing.T) {
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviders,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: configText,
ExpectError: regexp.MustCompile("please use 'vcd_edgegateway' for NSX-V backed VDC"),
},
Expand Down
54 changes: 21 additions & 33 deletions vcd/resource_vcd_network_isolated_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,11 @@ func resourceVcdNetworkIsolatedV2() *schema.Resource {
Description: "The name of organization to use, optional if defined at provider " +
"level. Useful when connected as sysadmin working across different organizations",
},
//"vdc": {
// Type: schema.TypeString,
// Optional: true,
// ForceNew: true,
// Description: "The name of VDC to use, optional if defined at provider level",
//},
"owner_id": {
Type: schema.TypeString,
Optional: true,
//ForceNew: true,
"vdc": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: "The name of VDC to use, optional if defined at provider level",
//ExactlyOneOf: []string{"owner_id", "vdc"},
},
"name": &schema.Schema{
Type: schema.TypeString,
Expand Down Expand Up @@ -97,17 +90,17 @@ func resourceVcdNetworkIsolatedV2() *schema.Resource {
func resourceVcdNetworkIsolatedV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
vcdClient := meta.(*VCDClient)

org, err := vcdClient.GetOrgFromResource(d)
_, vdc, err := vcdClient.GetOrgAndVdcFromResource(d)
if err != nil {
return diag.Errorf(errorRetrievingOrg, err)
return diag.Errorf("[isolated network v2 create] error retrieving VDC: %s", err)
}

networkType, err := getOpenApiOrgVdcIsolatedNetworkType(d, nil)
networkType, err := getOpenApiOrgVdcIsolatedNetworkType(d, vdc)
if err != nil {
return diag.FromErr(err)
}

orgNetwork, err := org.CreateOpenApiOrgVdcNetwork(networkType)
orgNetwork, err := vdc.CreateOpenApiOrgVdcNetwork(networkType)
if err != nil {
return diag.Errorf("[isolated network v2 create] error creating Org VDC isolated network: %s", err)
}
Expand All @@ -121,12 +114,12 @@ func resourceVcdNetworkIsolatedV2Create(ctx context.Context, d *schema.ResourceD
func resourceVcdNetworkIsolatedV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
vcdClient := meta.(*VCDClient)

org, err := vcdClient.GetOrgFromResource(d)
_, vdc, err := vcdClient.GetOrgAndVdcFromResource(d)
if err != nil {
return diag.Errorf(errorRetrievingOrg, err)
return diag.Errorf("[isolated network v2 update] error retrieving VDC: %s", err)
}

orgNetwork, err := org.GetOpenApiOrgVdcNetworkById(d.Id())
orgNetwork, err := vdc.GetOpenApiOrgVdcNetworkById(d.Id())
// If object is not found -
if govcd.ContainsNotFound(err) {
d.SetId("")
Expand All @@ -136,7 +129,7 @@ func resourceVcdNetworkIsolatedV2Update(ctx context.Context, d *schema.ResourceD
return diag.Errorf("[isolated network v2 update] error getting Org VDC network: %s", err)
}

networkType, err := getOpenApiOrgVdcIsolatedNetworkType(d, nil)
networkType, err := getOpenApiOrgVdcIsolatedNetworkType(d, vdc)
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -156,12 +149,12 @@ func resourceVcdNetworkIsolatedV2Update(ctx context.Context, d *schema.ResourceD
func resourceVcdNetworkIsolatedV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
vcdClient := meta.(*VCDClient)

org, err := vcdClient.GetOrgFromResource(d)
_, vdc, err := vcdClient.GetOrgAndVdcFromResource(d)
if err != nil {
return diag.Errorf(errorRetrievingOrg, err)
return diag.Errorf("[isolated network v2 read] error retrieving VDC: %s", err)
}

orgNetwork, err := org.GetOpenApiOrgVdcNetworkById(d.Id())
orgNetwork, err := vdc.GetOpenApiOrgVdcNetworkById(d.Id())
// If object is not found - unset ID
if govcd.ContainsNotFound(err) {
d.SetId("")
Expand All @@ -185,12 +178,12 @@ func resourceVcdNetworkIsolatedV2Read(ctx context.Context, d *schema.ResourceDat
func resourceVcdNetworkIsolatedV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
vcdClient := meta.(*VCDClient)

org, err := vcdClient.GetOrgFromResource(d)
_, vdc, err := vcdClient.GetOrgAndVdcFromResource(d)
if err != nil {
return diag.Errorf(errorRetrievingOrg, err)
return diag.Errorf("[isolated network v2 delete] error retrieving VDC: %s", err)
}

orgNetwork, err := org.GetOpenApiOrgVdcNetworkById(d.Id())
orgNetwork, err := vdc.GetOpenApiOrgVdcNetworkById(d.Id())
if err != nil {
return diag.Errorf("[isolated network v2 delete] error getting Org VDC network: %s", err)
}
Expand Down Expand Up @@ -239,15 +232,13 @@ func setOpenApiOrgVdcIsolatedNetworkData(d *schema.ResourceData, orgVdcNetwork *
dSet(d, "name", orgVdcNetwork.Name)
dSet(d, "description", orgVdcNetwork.Description)

dSet(d, "owner_id", orgVdcNetwork.OwnerRef.ID)

// Only one subnet can be defined although the structure accepts slice
dSet(d, "gateway", orgVdcNetwork.Subnets.Values[0].Gateway)
dSet(d, "prefix_length", orgVdcNetwork.Subnets.Values[0].PrefixLength)
dSet(d, "dns1", orgVdcNetwork.Subnets.Values[0].DNSServer1)
dSet(d, "dns2", orgVdcNetwork.Subnets.Values[0].DNSServer2)
dSet(d, "dns_suffix", orgVdcNetwork.Subnets.Values[0].DNSSuffix)
//dSet(d, "is_shared", orgVdcNetwork.Shared)
dSet(d, "is_shared", orgVdcNetwork.Shared)

// If any IP sets are available
if len(orgVdcNetwork.Subnets.Values[0].IPRanges.Values) > 0 {
Expand All @@ -273,10 +264,10 @@ func getOpenApiOrgVdcIsolatedNetworkType(d *schema.ResourceData, vdc *govcd.Vdc)
orgVdcNetworkConfig := &types.OpenApiOrgVdcNetwork{
Name: d.Get("name").(string),
Description: d.Get("description").(string),
//OrgVdc: &types.OpenApiReference{ID: vdc.Vdc.ID},
OrgVdc: &types.OpenApiReference{ID: vdc.Vdc.ID},

NetworkType: types.OrgVdcNetworkTypeIsolated,
//Shared: takeBoolPointer(d.Get("is_shared").(bool)),
Shared: takeBoolPointer(d.Get("is_shared").(bool)),

Subnets: types.OrgVdcNetworkSubnets{
Values: []types.OrgVdcNetworkSubnetValues{
Expand All @@ -294,8 +285,5 @@ func getOpenApiOrgVdcIsolatedNetworkType(d *schema.ResourceData, vdc *govcd.Vdc)
},
}

ownerId := d.Get("owner_id").(string)
orgVdcNetworkConfig.OwnerRef = &types.OpenApiReference{ID: ownerId}

return orgVdcNetworkConfig, nil
}
Loading

0 comments on commit 6136be6

Please sign in to comment.