Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 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
3 changes: 3 additions & 0 deletions .changes/v1.0.0/10-features.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* **New Resource:** `vcfa_provider_gateway` to manage TM Provider Gateways [GH-10]
* **New Data Source:** `vcfa_provider_gateway` to read IP Spaces [GH-10]
* **New Data Source:** `vcfa_tier0_gateway` to read available Tier 0 Gateways in NSX-T [GH-10]
2 changes: 1 addition & 1 deletion .github/workflows/check-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ jobs:
- name: No VCD references
run: |
set +e
grep -ERin "Director|VCD|ources/tm|labelTm|vcd_tm" . | grep -Eiv "VCDClient|.log|govcdClient|vcdClient|GOVCD_|govcd.|/director/|directory|github|go-vcloud-director|Directories|.git"
grep --exclude-dir=.git -ERin "Director|VCD|ources\/tm|labelTm|vcd_tm" . | grep -Eiv "VCDClient|.log|govcdClient|vcdClient|GOVCD_|govcd.|/director/|directory|github|go-vcloud-director|Directories"
if [ "$?" -eq 0 ]; then echo "ERROR: Found some VCD references"; exit 1; else exit 0; fi
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,5 @@ require (
google.golang.org/protobuf v1.35.1 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)

replace github.com/vmware/go-vcloud-director/v3 => github.com/Didainius/go-vcloud-director/v3 v3.0.0-alpha.4.0.20250123124919-40edd4787e14
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
github.com/Didainius/go-vcloud-director/v3 v3.0.0-alpha.4.0.20250123124919-40edd4787e14 h1:M2bFH/TfnjznYcnqH8gtUSU63Cxp9EDstuqJotuOHw4=
github.com/Didainius/go-vcloud-director/v3 v3.0.0-alpha.4.0.20250123124919-40edd4787e14/go.mod h1:68KHsVns52dsq/w5JQYzauaU/+NAi1FmCxhBrFc/VoQ=
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/ProtonMail/go-crypto v1.1.0-alpha.2 h1:bkyFVUP+ROOARdgCiJzNQo2V2kiB97LyUpzH9P6Hrlg=
Expand Down Expand Up @@ -149,8 +151,6 @@ 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.18 h1:0mqWqVNRXdAW3zsgP4rYQ1CfIIHIE58+dsdVISXblVY=
github.com/vmware/go-vcloud-director/v3 v3.0.0-alpha.18/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 vcfa/datasource_not_found_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func testSpecificDataSourceNotFound(dataSourceName string, vcdClient *VCDClient)
"vcfa_ip_space",
"vcfa_region_zone",
"vcfa_org_vdc",
"vcfa_tier0_gateway",
}

if contains(dataSourcesRequiringSysAdmin, dataSourceName) && !usingSysAdmin() {
Expand Down
66 changes: 66 additions & 0 deletions vcfa/datasource_vcfa_provider_gateway.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package vcfa

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 datasourceVcfaProviderGateway() *schema.Resource {
return &schema.Resource{
ReadContext: datasourceVcfaProviderGatewayRead,

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

func datasourceVcfaProviderGatewayRead(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: labelVcfaProviderGateway,
getEntityFunc: getProviderGateway,
stateStoreFunc: setProviderGatewayData,
}
return readDatasource(ctx, d, meta, c)
}
78 changes: 78 additions & 0 deletions vcfa/datasource_vcfa_tier0_gateway.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package vcfa

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 labelVcfaTier0Gateway = "Tier 0 Gateway"

func datasourceVcfaTier0Gateway() *schema.Resource {
return &schema.Resource{
ReadContext: datasourceVcfaTier0GatewayRead,

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

func datasourceVcfaTier0GatewayRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
vcdClient := meta.(*VCDClient)
// Fetching the region to conform to standard of returning 'ErrorEntityNotFound', because the API behind
// GetTmTier0GatewayWithContextByName does not handle it well
region, err := vcdClient.GetRegionById(d.Get("region_id").(string))
if err != nil {
return diag.Errorf("no region with ID '%s' found: %s", d.Get("region_id").(string), err)
}

getT0ByName := func(name string) (*govcd.TmTier0Gateway, error) {
return vcdClient.GetTmTier0GatewayWithContextByName(name, region.Region.ID, true)
}

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

func setTier0GatewayData(_ *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
}
35 changes: 19 additions & 16 deletions vcfa/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,28 @@ func Resources(nameRegexp string, includeDeprecated bool) (map[string]*schema.Re
}

var globalDataSourceMap = map[string]*schema.Resource{
"vcfa_tm_version": datasourceVcfaTmVersion(), // 1.0
"vcfa_vcenter": datasourceVcfaVcenter(), // 1.0
"vcfa_org": datasourceVcfaOrg(), // 1.0
"vcfa_nsx_manager": datasourceVcfaNsxManager(), // 1.0
"vcfa_supervisor": datasourceVcfaSupervisor(), // 1.0
"vcfa_supervisor_zone": datasourceVcfaSupervisorZone(), // 1.0
"vcfa_region": datasourceVcfaRegion(), // 1.0
"vcfa_ip_space": datasourceVcfaIpSpace(), // 1.0
"vcfa_region_zone": datasourceVcfaRegionZone(), // 1.0
"vcfa_org_vdc": datasourceVcfaOrgVdc(), // 1.0
"vcfa_tm_version": datasourceVcfaTmVersion(), // 1.0
"vcfa_vcenter": datasourceVcfaVcenter(), // 1.0
"vcfa_org": datasourceVcfaOrg(), // 1.0
"vcfa_nsx_manager": datasourceVcfaNsxManager(), // 1.0
"vcfa_supervisor": datasourceVcfaSupervisor(), // 1.0
"vcfa_supervisor_zone": datasourceVcfaSupervisorZone(), // 1.0
"vcfa_region": datasourceVcfaRegion(), // 1.0
"vcfa_ip_space": datasourceVcfaIpSpace(), // 1.0
"vcfa_region_zone": datasourceVcfaRegionZone(), // 1.0
"vcfa_org_vdc": datasourceVcfaOrgVdc(), // 1.0
"vcfa_tier0_gateway": datasourceVcfaTier0Gateway(), // 1.0
"vcfa_provider_gateway": datasourceVcfaProviderGateway(), // 1.0
}

var globalResourceMap = map[string]*schema.Resource{
"vcfa_vcenter": resourceVcfaVcenter(), // 1.0
"vcfa_org": resourceVcfaOrg(), // 1.0
"vcfa_nsx_manager": resourceVcfaNsxManager(), // 1.0
"vcfa_region": resourceVcfaRegion(), // 1.0
"vcfa_ip_space": resourceVcfaIpSpace(), // 1.0
"vcfa_org_vdc": resourceVcfaOrgVdc(), // 1.0
"vcfa_vcenter": resourceVcfaVcenter(), // 1.0
"vcfa_org": resourceVcfaOrg(), // 1.0
"vcfa_nsx_manager": resourceVcfaNsxManager(), // 1.0
"vcfa_region": resourceVcfaRegion(), // 1.0
"vcfa_ip_space": resourceVcfaIpSpace(), // 1.0
"vcfa_org_vdc": resourceVcfaOrgVdc(), // 1.0
"vcfa_provider_gateway": resourceVcfaProviderGateway(), // 1.0
}

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