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

Add TM IP Space support #1360

Merged
merged 16 commits into from
Dec 11, 2024
2 changes: 2 additions & 0 deletions .changes/v4.0.0/1360-features.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* **New Resource:** `vcd_tm_ip_space` to manage IP Spaces [GH-1360]
* **New Data Source:** `vcd_tm_ip_space` to read IP Spaces [GH-1360]
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.10
github.com/vmware/go-vcloud-director/v3 v3.0.0-alpha.11
)

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.10 h1:V23RUaZwOdGSbKXeS9Vv6+15ymZlE3S5/AO4ks+Wgk0=
github.com/vmware/go-vcloud-director/v3 v3.0.0-alpha.10/go.mod h1:68KHsVns52dsq/w5JQYzauaU/+NAi1FmCxhBrFc/VoQ=
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/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
101 changes: 101 additions & 0 deletions vcd/datasource_vcd_tm_ip_space.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
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"
)

var dsTmIpSpaceInternalScopeSchema = &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("ID of internal scope within %s", labelTmIpSpace),
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("Name of internal scope within %s", labelTmIpSpace),
},
"cidr": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("The CIDR that represents this IP block within %s", labelTmIpSpace),
},
},
}

func datasourceVcdTmIpSpace() *schema.Resource {
return &schema.Resource{
ReadContext: datasourceVcdTmIpSpaceRead,

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: fmt.Sprintf("Name of %s", labelTmIpSpace),
},
"region_id": {
Type: schema.TypeString,
Required: true,
Description: fmt.Sprintf("Region ID for this %s", labelTmIpSpace),
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("Description of %s", labelTmIpSpace),
},
"external_scope": {
Type: schema.TypeString,
Computed: true,
Description: "External scope in CIDR format",
},
"default_quota_max_subnet_size": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("Maximum subnet size represented as a prefix length (e.g. 24, 28) in %s", labelTmIpSpace),
},
"default_quota_max_cidr_count": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("Maximum number of subnets that can be allocated from internal scope in this %s. ('-1' for unlimited)", labelTmIpSpace),
},
"default_quota_max_ip_count": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("Maximum number of single floating IP addresses that can be allocated from internal scope in this %s. ('-1' for unlimited)", labelTmIpSpace),
},
"internal_scope": {
Type: schema.TypeSet,
Computed: true,
Description: fmt.Sprintf("Internal scope of %s", labelTmIpSpace),
Elem: dsTmIpSpaceInternalScopeSchema,
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("Status of %s", labelTmIpSpace),
},
},
}
}

func datasourceVcdTmIpSpaceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
vcdClient := meta.(*VCDClient)

getTmIpSpaceByName := func(name string) (*govcd.TmIpSpace, error) {
return vcdClient.GetTmIpSpaceByNameAndRegionId(name, d.Get("region_id").(string))
}

c := dsReadConfig[*govcd.TmIpSpace, types.TmIpSpace]{
entityLabel: labelTmIpSpace,
getEntityFunc: getTmIpSpaceByName,
stateStoreFunc: setTmIpSpaceData,
}
return readDatasource(ctx, d, meta, c)
}
2 changes: 2 additions & 0 deletions vcd/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ var globalDataSourceMap = map[string]*schema.Resource{
"vcd_tm_nsxt_manager": datasourceVcdTmNsxtManager(), // 4.0
"vcd_tm_vcenter": datasourceVcdTmVcenter(), // 4.0
"vcd_tm_content_library_item": datasourceVcdTmContentLibraryItem(), // 4.0
"vcd_tm_ip_space": datasourceVcdTmIpSpace(), // 4.0
}

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

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