Skip to content
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
1 change: 1 addition & 0 deletions .changes/v1.0.0/31-features.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- **New Data Source:** `vcfa_region_vm_class` to read Region VM Classes [GH-31]
4 changes: 2 additions & 2 deletions .changes/v1.0.0/9-features.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
- **New Resource:** `vcfa_org_vdc` to manage Organization VDCs (Region Quotas) [GH-9, GH-30]
- **New Data Source:** `vcfa_org_vdc` to read Organization VDCs (Region Quotas) [GH-9]
- **New Resource:** `vcfa_org_region_quota` to manage Organization Region Quotas [GH-9, GH-30, GH-31]
- **New Data Source:** `vcfa_org_region_quota` to read Organization Region Quotas [GH-9, GH-31]
- **New Data Source:** `vcfa_region_zone` to read Region Zones [GH-9]
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/go-version v1.7.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.35.0
github.com/vmware/go-vcloud-director/v3 v3.0.0-alpha.26
github.com/vmware/go-vcloud-director/v3 v3.0.0-alpha.27
)

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.26 h1:nX+q6+X4VHzM+tiXr2N9NKK+Nu99660dM6lXezsu4uo=
github.com/vmware/go-vcloud-director/v3 v3.0.0-alpha.26/go.mod h1:68KHsVns52dsq/w5JQYzauaU/+NAi1FmCxhBrFc/VoQ=
github.com/vmware/go-vcloud-director/v3 v3.0.0-alpha.27 h1:b7yWY0nHhz4v07cAd4grkS78v8wTkNvg0FBsXADA6nI=
github.com/vmware/go-vcloud-director/v3 v3.0.0-alpha.27/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
4 changes: 0 additions & 4 deletions vcfa/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ type Config struct {
AllowSATokenFile bool // Setting to suppress Service Account Token File security warnings
SysOrg string // Org used for authentication
Org string // Default Org used for API operations
Vdc string // Default (optional) VDC for API operations
Href string
InsecureFlag bool
}
Expand All @@ -45,7 +44,6 @@ type VCDClient struct {
*govcd.VCDClient
SysOrg string
Org string // name of default Org
Vdc string // name of default VDC
InsecureFlag bool
}

Expand Down Expand Up @@ -144,7 +142,6 @@ func (c *Config) Client() (*VCDClient, error) {
c.ApiTokenFile + "#" +
c.ServiceAccountTokenFile + "#" +
c.SysOrg + "#" +
c.Vdc + "#" +
c.Href
checksum := fmt.Sprintf("%x", sha256.Sum256([]byte(rawData)))

Expand Down Expand Up @@ -182,7 +179,6 @@ func (c *Config) Client() (*VCDClient, error) {
),
SysOrg: c.SysOrg,
Org: c.Org,
Vdc: c.Vdc,
InsecureFlag: c.InsecureFlag}

err = ProviderAuthenticate(tmClient.VCDClient, c.User, c.Password, c.Token, c.SysOrg, c.ApiToken, c.ApiTokenFile, c.ServiceAccountTokenFile)
Expand Down
38 changes: 18 additions & 20 deletions vcfa/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func init() {
setBoolFlag(&vcfaShortTest, "vcfa-short", "VCFA_SHORT_TEST", "runs short test")
setBoolFlag(&vcfaAddProvider, "vcfa-add-provider", envVcfaAddProvider, "add provider to test scripts")
setBoolFlag(&vcfaSkipTemplateWriting, "vcfa-skip-template-write", envVcfaSkipTemplateWriting, "Skip writing templates to file")
setBoolFlag(&vcfaRemoveOrgVdcFromTemplate, "vcfa-remove-org-vdc-from-template", envVcfaRemoveOrgVdcFromTemplate, "Remove org and VDC from template")
setBoolFlag(&vcfaRemoveOrgFromTemplate, "vcfa-remove-org-from-template", envVcfaRemoveOrgFromTemplate, "Remove org from template")
setBoolFlag(&vcfaTestOrgUser, "vcfa-test-org-user", envVcfaTestOrgUser, "Run tests with org user")
setStringFlag(&vcfaSkipPattern, "vcfa-skip-pattern", "VCFA_SKIP_PATTERN", "Skip tests that match the pattern (implies vcfa-pre-post-checks")
setBoolFlag(&skipLeftoversRemoval, "vcfa-skip-leftovers-removal", "VCFA_SKIP_LEFTOVERS_REMOVAL", "Do not attempt removal of leftovers at the end of the test suite")
Expand Down Expand Up @@ -85,12 +85,12 @@ type TestConfig struct {
UseConnectionCache bool `json:"useConnectionCache"`
} `json:"provider"`
Tm struct {
Org string `json:"org"` // temporary field to make skipIfNotTm work
CreateRegion bool `json:"createRegion"`
Region string `json:"region"`
StorageClass string `json:"storageClass"`
Vdc string `json:"vdc"`
ContentLibrary string `json:"contentLibrary"`
Org string `json:"org"`
CreateRegion bool `json:"createRegion"`
Region string `json:"region"`
StorageClass string `json:"storageClass"`
RegionVmClasses []string `json:"regionVmClasses"`
ContentLibrary string `json:"contentLibrary"`

CreateNsxManager bool `json:"createNsxManager"`
NsxManagerUsername string `json:"nsxManagerUsername"`
Expand Down Expand Up @@ -137,9 +137,9 @@ var (
// vcfaSkipTemplateWriting disable the writing of the template to a .tf file
vcfaSkipTemplateWriting = false

// vcfaRemoveOrgVdcFromTemplate removes org and vdc from template, thus tetsing with the
// vcfaRemoveOrgFromTemplate removes org from template, thus tetsing with the
// variables in provider section
vcfaRemoveOrgVdcFromTemplate = false
vcfaRemoveOrgFromTemplate = false

// vcfaTestOrgUser enables testing with the Org User
vcfaTestOrgUser = false
Expand Down Expand Up @@ -202,11 +202,11 @@ const (
providerVcfaSystem2 = "vcfasys2"
providerVcfaSys2Alias = "vcfa.sys2"

testArtifactsDirectory = "test-artifacts"
envVcfaAddProvider = "VCFA_ADD_PROVIDER"
envVcfaSkipTemplateWriting = "VCFA_SKIP_TEMPLATE_WRITING"
envVcfaRemoveOrgVdcFromTemplate = "REMOVE_ORG_VDC_FROM_TEMPLATE"
envVcfaTestOrgUser = "VCFA_TEST_ORG_USER"
testArtifactsDirectory = "test-artifacts"
envVcfaAddProvider = "VCFA_ADD_PROVIDER"
envVcfaSkipTemplateWriting = "VCFA_SKIP_TEMPLATE_WRITING"
envVcfaRemoveOrgFromTemplate = "REMOVE_ORG_FROM_TEMPLATE"
envVcfaTestOrgUser = "VCFA_TEST_ORG_USER"

// Warning message used for all tests
acceptanceTestsSkipped = "Acceptance tests skipped unless env 'TF_ACC' set"
Expand Down Expand Up @@ -399,15 +399,13 @@ func templateFill(tmpl string, inputData StringMap) string {
var populatedStr = buf.Bytes()

// This is a quick way of enabling an alternate testing mode:
// When REMOVE_ORG_VDC_FROM_TEMPLATE is set, the terraform
// When REMOVE_ORG_FROM_TEMPLATE is set, the terraform
// templates will be changed on-the-fly, to comment out the
// definitions of org and vdc. This will force the test to
// borrow org and vcfa from the provider.
if vcfaRemoveOrgVdcFromTemplate {
// definitions of org. This will force the test to
// borrow org from the provider.
if vcfaRemoveOrgFromTemplate {
reOrg := regexp.MustCompile(`\sorg\s*=`)
buf2 := reOrg.ReplaceAll(buf.Bytes(), []byte("# org = "))
reVdc := regexp.MustCompile(`\svdc\s*=`)
buf2 = reVdc.ReplaceAll(buf2, []byte("# vdc = "))
populatedStr = buf2
}
if TemplateWriting {
Expand Down
3 changes: 2 additions & 1 deletion vcfa/datasource_not_found_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ func testSpecificDataSourceNotFound(dataSourceName string, tmClient *VCDClient)
"vcfa_vcenter",
"vcfa_ip_space",
"vcfa_region_zone",
"vcfa_org_vdc",
"vcfa_org_region_quota",
"vcfa_region_vm_class",
"vcfa_tier0_gateway",
"vcfa_content_library",
"vcfa_content_library_item",
Expand Down
16 changes: 14 additions & 2 deletions vcfa/datasource_vcfa_nsx_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,22 @@ func datasourceVcfaNsxManager() *schema.Resource {
Computed: true,
Description: fmt.Sprintf("URL of %s", labelVcfaNsxManager),
},
"network_provider_scope": {
"active": {
Type: schema.TypeBool,
Computed: true,
Description: fmt.Sprintf("Indicates whether the %s can or cannot be used to manage networking constructs within VCFA", labelVcfaNsxManager),
},
"cluster_id": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("Network Provider Scope for %s", labelVcfaNsxManager),
Description: fmt.Sprintf("Cluster ID of the %s. Each NSX installation has a single cluster. This is not a VCFA URN", labelVcfaNsxManager),
},
"is_dedicated_for_classic_tenants": {
Type: schema.TypeBool,
Computed: true,
Description: fmt.Sprintf("Whether this %s is dedicated for legacy VRA-style tenants only and unable to "+
"participate in modern constructs such as Regions and Zones. Legacy VRA-style is deprecated and this field exists for "+
"the purpose of VRA backwards compatibility only", labelVcfaNsxManager),
},
"status": {
Type: schema.TypeString,
Expand Down
4 changes: 2 additions & 2 deletions vcfa/datasource_vcfa_org.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ func datasourceVcfaOrg() *schema.Resource {
Computed: true,
Description: fmt.Sprintf("%s owner Name", labelVcfaOrg),
},
"org_vdc_count": {
"org_region_quota_count": {
Type: schema.TypeInt,
Computed: true,
Description: fmt.Sprintf("Number of VDCs belonging to the %s", labelVcfaOrg),
Description: fmt.Sprintf("Number of %ss belonging to the %s", labelVcfaOrgRegionQuota, labelVcfaOrg),
},
"catalog_count": {
Type: schema.TypeInt,
Expand Down
165 changes: 165 additions & 0 deletions vcfa/datasource_vcfa_org_region_quota.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
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 datasourceVcfaOrgRegionQuota() *schema.Resource {
return &schema.Resource{
ReadContext: datasourceVcfaOrgRegionQuotaRead,

Schema: map[string]*schema.Schema{
"org_id": {
Type: schema.TypeString,
Required: true,
Description: "Parent Organization ID",
},
"region_id": {
Type: schema.TypeString,
Required: true,
Description: "Parent Region ID",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("Description of the %s", labelVcfaOrgRegionQuota),
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("Name of the %s", labelVcfaOrgRegionQuota),
},
"supervisor_ids": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: fmt.Sprintf("A set of Supervisor IDs that back this %s", labelVcfaOrgRegionQuota),
},
"zone_resource_allocations": {
Type: schema.TypeSet,
Computed: true,
Elem: orgRegionQuotaDsZoneResourceAllocation,
Description: "A set of Region Zones and their resource allocations",
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("%s status", labelVcfaOrgRegionQuota),
},
"region_vm_class_ids": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: fmt.Sprintf("A set of %s IDs assigned to this %s", labelVcfaRegionVmClass, labelVcfaOrgRegionQuota),
},
"region_storage_policy": {
Type: schema.TypeSet,
Computed: true,
Elem: orgRegionQuotaDsRegionStoragePolicy,
Description: fmt.Sprintf("A set of %s assigned to this %s", labelVcfaRegionStoragePolicy, labelVcfaOrgRegionQuota),
},
},
}
}

var orgRegionQuotaDsZoneResourceAllocation = &schema.Resource{
Schema: map[string]*schema.Schema{
"region_zone_name": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("%s Name", labelVcfaRegionZone),
},
"region_zone_id": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("%s ID", labelVcfaRegionZone),
},
"memory_limit_mib": {
Type: schema.TypeInt,
Computed: true,
Description: "Memory limit in MiB",
},
"memory_reservation_mib": {
Type: schema.TypeInt,
Computed: true,
Description: "Memory reservation in MiB",
},
"cpu_limit_mhz": {
Type: schema.TypeInt,
Computed: true,
Description: "CPU limit in MHz",
},
"cpu_reservation_mhz": {
Type: schema.TypeInt,
Computed: true,
Description: "CPU reservation in MHz",
},
},
}

var orgRegionQuotaDsRegionStoragePolicy = &schema.Resource{
Schema: map[string]*schema.Schema{
"region_storage_policy_id": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("The ID of the %s for this %s", labelVcfaRegionStoragePolicy, labelVcfaOrgRegionQuota),
},
"storage_limit_mib": {
Type: schema.TypeInt,
Computed: true,
Description: "Maximum allowed storage allocation in mebibytes",
},
"id": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("The ID of the %s Storage Policy", labelVcfaOrgRegionQuota),
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "The name of the Storage Policy. It follows RFC 1123 Label Names to conform with Kubernetes standards",
},
"storage_used_mib": {
Type: schema.TypeInt,
Computed: true,
Description: "Amount of storage used in mebibytes",
},
},
}

func datasourceVcfaOrgRegionQuotaRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
tmClient := meta.(ClientContainer).tmClient
getByNameAndOrgId := func(_ string) (*govcd.RegionQuota, error) {
region, err := tmClient.GetRegionById(d.Get("region_id").(string))
if err != nil {
return nil, err
}
org, err := tmClient.GetOrgById(d.Get("org_id").(string))
if err != nil {
return nil, err
}
return tmClient.GetRegionQuotaByName(fmt.Sprintf("%s_%s", org.Org.Name, region.Region.Name))
}

c := dsReadConfig[*govcd.RegionQuota, types.TmVdc]{
entityLabel: labelVcfaOrgRegionQuota,
getEntityFunc: getByNameAndOrgId,
stateStoreFunc: func(tmClient *VCDClient, d *schema.ResourceData, outerType *govcd.RegionQuota) error {
err := setOrgRegionQuotaData(tmClient, d, outerType)
if err != nil {
return err
}
err = saveVmClassesInState(tmClient, d, outerType.TmVdc.ID)
if err != nil {
return err
}
return saveRegionStoragePoliciesInState(d, outerType, "datasource")
},
}
return readDatasource(ctx, d, meta, c)
}
Loading