Skip to content

Commit

Permalink
TM Provider Gateway (#1361)
Browse files Browse the repository at this point in the history
  • Loading branch information
Didainius authored Dec 20, 2024
1 parent d7eebcf commit 6be0b67
Show file tree
Hide file tree
Showing 15 changed files with 785 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .changes/v4.0.0/1361-features.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* **New Resource:** `vcd_tm_provider_gateway` to manage TM Provider Gateways [GH-1361]
* **New Data Source:** `vcd_tm_provider_gateway` to read IP Spaces [GH-1361]
* **New Data Source:** `vcd_tm_tier0_gateway` to read available Tier 0 Gateways in NSX-T [GH-1361]
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/hashicorp/go-version v1.6.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0
github.com/kr/pretty v0.3.1
github.com/vmware/go-vcloud-director/v3 v3.0.0-alpha.11
github.com/vmware/go-vcloud-director/v3 v3.0.0-alpha.12
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IU
github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok=
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
github.com/vmware/go-vcloud-director/v3 v3.0.0-alpha.11 h1:jdOEeoS8t/9bEe6ahZTRhvxg3o88IthDVtz5zMeoKjQ=
github.com/vmware/go-vcloud-director/v3 v3.0.0-alpha.11/go.mod h1:68KHsVns52dsq/w5JQYzauaU/+NAi1FmCxhBrFc/VoQ=
github.com/vmware/go-vcloud-director/v3 v3.0.0-alpha.12 h1:WLMb6TygvaQasOcw32yomqb0FODvqjlAtpA1QONec4k=
github.com/vmware/go-vcloud-director/v3 v3.0.0-alpha.12/go.mod h1:68KHsVns52dsq/w5JQYzauaU/+NAi1FmCxhBrFc/VoQ=
github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=
github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
Expand Down
1 change: 1 addition & 0 deletions vcd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ type TestConfig struct {
NsxtManagerUsername string `json:"nsxtManagerUsername"`
NsxtManagerPassword string `json:"nsxtManagerPassword"`
NsxtManagerUrl string `json:"nsxtManagerUrl"`
NsxtTier0Gateway string `json:"nsxtTier0Gateway"`

CreateVcenter bool `json:"createVcenter"`
VcenterUsername string `json:"vcenterUsername"`
Expand Down
66 changes: 66 additions & 0 deletions vcd/datasource_vcd_tm_provider_gateway.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package vcd

import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/vmware/go-vcloud-director/v3/govcd"
"github.com/vmware/go-vcloud-director/v3/types/v56"
)

func datasourceVcdTmProviderGateway() *schema.Resource {
return &schema.Resource{
ReadContext: datasourceVcdTmProviderGatewayRead,

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: fmt.Sprintf("Name of %s", labelTmProviderGateway),
},
"region_id": {
Type: schema.TypeString,
Required: true,
Description: fmt.Sprintf("Parent %s of %s", labelTmRegion, labelTmProviderGateway),
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("Description of %s", labelTmProviderGateway),
},
"nsxt_tier0_gateway_id": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("Parent %s of %s", labelTmTier0Gateway, labelTmProviderGateway),
},
"ip_space_ids": {
Type: schema.TypeSet,
Computed: true,
Description: fmt.Sprintf("A set of supervisor IDs used in this %s", labelTmRegion),
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("Status of %s", labelTmProviderGateway),
},
},
}
}

func datasourceVcdTmProviderGatewayRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
vcdClient := meta.(*VCDClient)
getProviderGateway := func(name string) (*govcd.TmProviderGateway, error) {
return vcdClient.GetTmProviderGatewayByNameAndRegionId(name, d.Get("region_id").(string))
}
c := dsReadConfig[*govcd.TmProviderGateway, types.TmProviderGateway]{
entityLabel: labelTmProviderGateway,
getEntityFunc: getProviderGateway,
stateStoreFunc: setTmProviderGatewayData,
}
return readDatasource(ctx, d, meta, c)
}
71 changes: 71 additions & 0 deletions vcd/datasource_vcd_tm_tier0_gateway.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package vcd

import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/vmware/go-vcloud-director/v3/govcd"
"github.com/vmware/go-vcloud-director/v3/types/v56"
)

const labelTmTier0Gateway = "TM Tier 0 Gateway"

func datasourceVcdTmTier0Gateway() *schema.Resource {
return &schema.Resource{
ReadContext: datasourceVcdTmTier0GatewayRead,

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: fmt.Sprintf("Display Name of %s", labelTmTier0Gateway),
},
"region_id": {
Type: schema.TypeString,
Required: true,
Description: fmt.Sprintf("Parent %s ID", labelTmRegion),
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("Description of %s", labelTmTier0Gateway),
},
"parent_tier_0_id": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("Parent Tier 0 Gateway of %s", labelTmTier0Gateway),
},
"already_imported": {
Type: schema.TypeBool,
Computed: true,
Description: fmt.Sprintf("Defines if the T0 is already imported of %s", labelTmTier0Gateway),
},
},
}
}

func datasourceVcdTmTier0GatewayRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
vcdClient := meta.(*VCDClient)
getT0ByName := func(name string) (*govcd.TmTier0Gateway, error) {
return vcdClient.GetTmTier0GatewayWithContextByName(name, d.Get("region_id").(string), true)
}

c := dsReadConfig[*govcd.TmTier0Gateway, types.TmTier0Gateway]{
entityLabel: labelTmTier0Gateway,
getEntityFunc: getT0ByName,
stateStoreFunc: setTmTier0GatewayData,
}
return readDatasource(ctx, d, meta, c)
}

func setTmTier0GatewayData(_ *VCDClient, d *schema.ResourceData, t *govcd.TmTier0Gateway) error {
d.SetId(t.TmTier0Gateway.ID) // So far the API returns plain UUID (not URN)
dSet(d, "name", t.TmTier0Gateway.DisplayName)
dSet(d, "description", t.TmTier0Gateway.Description)
dSet(d, "parent_tier_0_id", t.TmTier0Gateway.ParentTier0ID)
dSet(d, "already_imported", t.TmTier0Gateway.AlreadyImported)

return nil
}
3 changes: 3 additions & 0 deletions vcd/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ var globalDataSourceMap = map[string]*schema.Resource{
"vcd_tm_vcenter": datasourceVcdTmVcenter(), // 4.0
"vcd_tm_content_library_item": datasourceVcdTmContentLibraryItem(), // 4.0
"vcd_tm_ip_space": datasourceVcdTmIpSpace(), // 4.0
"vcd_tm_tier0_gateway": datasourceVcdTmTier0Gateway(), // 4.0
"vcd_tm_provider_gateway": datasourceVcdTmProviderGateway(), // 4.0
}

var globalResourceMap = map[string]*schema.Resource{
Expand Down Expand Up @@ -321,6 +323,7 @@ var globalResourceMap = map[string]*schema.Resource{
"vcd_tm_region": resourceVcdTmRegion(), // 4.0
"vcd_tm_org_vdc": resourceTmOrgVdc(), // 4.0
"vcd_tm_ip_space": resourceVcdTmIpSpace(), // 4.0
"vcd_tm_provider_gateway": resourceVcdTmProviderGateway(), // 4.0
}

// Provider returns a terraform.ResourceProvider.
Expand Down
Loading

0 comments on commit 6be0b67

Please sign in to comment.