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
2 changes: 1 addition & 1 deletion .changes/v1.0.0/1-features.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- Add `vcfa_tm_version` data source to read version details from VCFA Tenant Manager [GH-1]
- Add `vcfa_version` data source to read version details from VCFA [GH-1, GH-66]
6 changes: 3 additions & 3 deletions .changes/v1.0.0/11-features.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
* **New Data Source:** `vcfa_edge_cluster` to read and sync Edge Clusters [GH-11]
* **New Resource:** `vcfa_edge_cluster_qos` to manage QoS settings for Edge Clusters [GH-11]
* **New Data Source:** `vcfa_edge_cluster_qos` to read QoS settings for Edge Clusters [GH-11]
* **New Data Source:** `vcfa_edge_cluster` to read and sync Edge Clusters [GH-11, GH-66]
* **New Resource:** `vcfa_edge_cluster_qos` to manage QoS settings for Edge Clusters [GH-11, GH-66]
* **New Data Source:** `vcfa_edge_cluster_qos` to read QoS settings for Edge Clusters [GH-11, GH-66]
4 changes: 2 additions & 2 deletions .changes/v1.0.0/13-features.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
* **New Resource:** `vcfa_content_library_item` to manage Content Library Items [GH-13, GH-46, GH-50, GH-53]
* **New Data Source:** `vcfa_content_library_item` to read Content Library Items [GH-13]
* **New Resource:** `vcfa_content_library_item` to manage Content Library Items [GH-13, GH-46, GH-50, GH-53, GH-66]
* **New Data Source:** `vcfa_content_library_item` to read Content Library Items [GH-13, GH-66]
4 changes: 2 additions & 2 deletions .changes/v1.0.0/17-features.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
* **New Resource:** `vcfa_rights_bundle` to manage Rights Bundles [GH-17]
* **New Data Source:** `vcfa_rights_bundle` to read existing Rights Bundles [GH-17]
* **New Resource:** `vcfa_rights_bundle` to manage Rights Bundles [GH-17, GH-66]
* **New Data Source:** `vcfa_rights_bundle` to read existing Rights Bundles [GH-17, GH-66]
4 changes: 2 additions & 2 deletions .changes/v1.0.0/21-features.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
* **New Resource:** `vcfa_global_role` to manage Global Roles [GH-21]
* **New Data Source:** `vcfa_global_role` to read existing Global Roles [GH-21]
* **New Resource:** `vcfa_global_role` to manage Global Roles [GH-21, GH-66]
* **New Data Source:** `vcfa_global_role` to read existing Global Roles [GH-21, GH-66]
18 changes: 9 additions & 9 deletions vcfa/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ type TestConfig struct {
ApiTokenFile string `json:"api_token_file,omitempty"`
ServiceAccountTokenFile string `json:"service_account_token_file,omitempty"`

// Tenant Manager version and API version, they allow tests to
// VCFA version and API version, they allow tests to
// check for compatibility without using an extra connection
TmVersion string `json:"tmVersion,omitempty"`
TmApiVersion string `json:"tmApiVersion,omitempty"`
VcfaVersion string `json:"version,omitempty"`
ApiVersion string `json:"apiVersion,omitempty"`

Url string `json:"url"`
SysOrg string `json:"sysOrg"`
Expand Down Expand Up @@ -245,8 +245,8 @@ const (
# comment {{.Comment}}
# date {{.Timestamp}}
# file {{.CallerFileName}}
# VCFA version {{.TmVersion}}
# API version {{.TmApiVersion}}
# VCFA version {{.VcfaVersion}}
# API version {{.ApiVersion}}

provider "vcfa" {
user = "{{.PrUser}}"
Expand Down Expand Up @@ -411,8 +411,8 @@ func templateFill(tmpl string, inputData StringMap) string {
data["CallerFileName"] = callerFileName
}
data["Timestamp"] = time.Now().Format("2006-01-02 15:04")
data["TmVersion"] = testConfig.Provider.TmVersion
data["TmApiVersion"] = testConfig.Provider.TmApiVersion
data["VcfaVersion"] = testConfig.Provider.VcfaVersion
data["ApiVersion"] = testConfig.Provider.ApiVersion

// Creates a template. The template gets the same name of the calling function, to generate a better
// error message in case of failure
Expand Down Expand Up @@ -776,7 +776,7 @@ func TestMain(m *testing.M) {
exitCode := m.Run()

if numberOfPartitions != 0 {
entTestFileName := getTestFileName("end", testConfig.Provider.TmVersion)
entTestFileName := getTestFileName("end", testConfig.Provider.VcfaVersion)
err := os.WriteFile(entTestFileName, []byte(fmt.Sprintf("%d", exitCode)), 0600)
if err != nil {
fmt.Printf("error writing to file '%s': %s\n", entTestFileName, err)
Expand Down Expand Up @@ -1136,7 +1136,7 @@ func preTestChecks(t *testing.T) {
}
}

handlePartitioning(testConfig.Provider.TmVersion, testConfig.Provider.Url, t)
handlePartitioning(testConfig.Provider.VcfaVersion, testConfig.Provider.Url, t)
// if the test runs without -vcfa-pre-post-checks, all post-checks will be skipped
if !vcfaPrePostChecks {
return
Expand Down
4 changes: 2 additions & 2 deletions vcfa/datasource_not_found_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ func testSpecificDataSourceNotFound(dataSourceName string, tmClient *VCDClient)

skipAlwaysSlice := []skipAlways{
{
dataSourceName: "vcfa_tm_version",
reason: "Data source vcfa_tm_version always returns data, it is not possible to get ENF",
dataSourceName: "vcfa_version",
reason: "Data source vcfa_version always returns data, it is not possible to get ENF",
},
{
dataSourceName: "vcfa_kubeconfig",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,29 @@ func datasourceVcfaTmVersion() *schema.Resource {
"condition": {
Type: schema.TypeString,
Optional: true,
Description: "A condition to check against the VCFA Tenant Manager version",
Description: "A condition to check against the VCFA version",
RequiredWith: []string{"fail_if_not_match"},
},
"fail_if_not_match": {
Type: schema.TypeBool,
Optional: true,
Description: "This data source fails if the VCFA Tenant Manager doesn't match the version constraint set in 'condition'",
Description: "This data source fails if the VCFA doesn't match the version constraint set in 'condition'",
RequiredWith: []string{"condition"},
},
"matches_condition": {
Type: schema.TypeBool,
Computed: true,
Description: "Whether VCFA Tenant Manager matches the condition or not",
Description: "Whether VCFA matches the condition or not",
},
"tm_version": {
"version": {
Type: schema.TypeString,
Computed: true,
Description: "The VCFA Tenant Manager version",
Description: "The VCFA version",
},
"tm_api_version": {
"api_version": {
Type: schema.TypeString,
Computed: true,
Description: "The maximum supported VCFA Tenant Manager API version",
Description: "The maximum supported VCFA API version",
},
},
}
Expand All @@ -48,15 +48,15 @@ func datasourceVcfaTmVersionRead(_ context.Context, d *schema.ResourceData, meta
tmClient := meta.(ClientContainer).tmClient
vcfaVersion, err := tmClient.VCDClient.Client.GetVcdShortVersion()
if err != nil {
return diag.Errorf("could not get VCFA Tenant Manager version: %s", err)
return diag.Errorf("could not get VCFA version: %s", err)
}
apiVersion, err := tmClient.VCDClient.Client.MaxSupportedVersion()
if err != nil {
return diag.Errorf("could not get VCFA Tenant Manager API version: %s", err)
return diag.Errorf("could not get VCFA API version: %s", err)
}

dSet(d, "tm_version", vcfaVersion)
dSet(d, "tm_api_version", apiVersion)
dSet(d, "version", vcfaVersion)
dSet(d, "api_version", apiVersion)

if condition, ok := d.GetOk("condition"); ok {
checkVer, err := semver.NewVersion(vcfaVersion)
Expand All @@ -70,11 +70,11 @@ func datasourceVcfaTmVersionRead(_ context.Context, d *schema.ResourceData, meta
matchesCondition := constraints.Check(checkVer)
dSet(d, "matches_condition", matchesCondition)
if !matchesCondition && d.Get("fail_if_not_match").(bool) {
return diag.Errorf("the VCFA Tenant Manager version '%s' doesn't match the version constraint '%s'", vcfaVersion, condition)
return diag.Errorf("the VCFA version '%s' doesn't match the version constraint '%s'", vcfaVersion, condition)
}
}

// The ID is artificial, and we try to identify each data source instance unequivocally through its parameters.
d.SetId(fmt.Sprintf("tm_version='%s',condition='%s',fail_if_not_match='%t'", vcfaVersion, d.Get("condition"), d.Get("fail_if_not_match")))
d.SetId(fmt.Sprintf("version='%s',condition='%s',fail_if_not_match='%t'", vcfaVersion, d.Get("condition"), d.Get("fail_if_not_match")))
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccVcfaTmVersion(t *testing.T) {
func TestAccVcfaVersion(t *testing.T) {
preTestChecks(t)
defer postTestChecks(t)
skipIfNotSysAdmin(t)
Expand Down Expand Up @@ -77,50 +77,50 @@ func TestAccVcfaTmVersion(t *testing.T) {
{
Config: step1,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.vcfa_tm_version.version", "id", fmt.Sprintf("tm_version='%s',condition='>= 99.99.99',fail_if_not_match='false'", currentVersion)),
resource.TestCheckResourceAttr("data.vcfa_tm_version.version", "tm_version", currentVersion),
resource.TestCheckResourceAttr("data.vcfa_tm_version.version", "tm_api_version", apiVersion),
resource.TestCheckResourceAttr("data.vcfa_tm_version.version", "matches_condition", "false"),
resource.TestCheckResourceAttr("data.vcfa_version.version", "id", fmt.Sprintf("version='%s',condition='>= 99.99.99',fail_if_not_match='false'", currentVersion)),
resource.TestCheckResourceAttr("data.vcfa_version.version", "version", currentVersion),
resource.TestCheckResourceAttr("data.vcfa_version.version", "api_version", apiVersion),
resource.TestCheckResourceAttr("data.vcfa_version.version", "matches_condition", "false"),
),
},
{
Config: step2,
ExpectError: regexp.MustCompile(fmt.Sprintf(`the VCFA Tenant Manager version '%s' doesn't match the version constraint '>= 99.99.99'`, currentVersion)),
ExpectError: regexp.MustCompile(fmt.Sprintf(`the VCFA version '%s' doesn't match the version constraint '>= 99.99.99'`, currentVersion)),
},
{
Config: step3,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.vcfa_tm_version.version", "id", fmt.Sprintf("tm_version='%s',condition='= %s',fail_if_not_match='true'", currentVersion, currentVersion)),
resource.TestCheckResourceAttr("data.vcfa_tm_version.version", "tm_version", currentVersion),
resource.TestCheckResourceAttr("data.vcfa_tm_version.version", "tm_api_version", apiVersion),
resource.TestCheckResourceAttr("data.vcfa_tm_version.version", "matches_condition", "true"),
resource.TestCheckResourceAttr("data.vcfa_version.version", "id", fmt.Sprintf("version='%s',condition='= %s',fail_if_not_match='true'", currentVersion, currentVersion)),
resource.TestCheckResourceAttr("data.vcfa_version.version", "version", currentVersion),
resource.TestCheckResourceAttr("data.vcfa_version.version", "api_version", apiVersion),
resource.TestCheckResourceAttr("data.vcfa_version.version", "matches_condition", "true"),
),
},
{
Config: step4,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.vcfa_tm_version.version", "id", fmt.Sprintf("tm_version='%s',condition='~> %s.%s',fail_if_not_match='true'", currentVersion, versionTokens[0], versionTokens[1])),
resource.TestCheckResourceAttr("data.vcfa_tm_version.version", "tm_version", currentVersion),
resource.TestCheckResourceAttr("data.vcfa_tm_version.version", "tm_api_version", apiVersion),
resource.TestCheckResourceAttr("data.vcfa_tm_version.version", "matches_condition", "true"),
resource.TestCheckResourceAttr("data.vcfa_version.version", "id", fmt.Sprintf("version='%s',condition='~> %s.%s',fail_if_not_match='true'", currentVersion, versionTokens[0], versionTokens[1])),
resource.TestCheckResourceAttr("data.vcfa_version.version", "version", currentVersion),
resource.TestCheckResourceAttr("data.vcfa_version.version", "api_version", apiVersion),
resource.TestCheckResourceAttr("data.vcfa_version.version", "matches_condition", "true"),
),
},
{
Config: step5,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.vcfa_tm_version.version", "id", fmt.Sprintf("tm_version='%s',condition='!= 10.3.0',fail_if_not_match='true'", currentVersion)),
resource.TestCheckResourceAttr("data.vcfa_tm_version.version", "tm_version", currentVersion),
resource.TestCheckResourceAttr("data.vcfa_tm_version.version", "tm_api_version", apiVersion),
resource.TestCheckResourceAttr("data.vcfa_tm_version.version", "matches_condition", "true"),
resource.TestCheckResourceAttr("data.vcfa_version.version", "id", fmt.Sprintf("version='%s',condition='!= 10.3.0',fail_if_not_match='true'", currentVersion)),
resource.TestCheckResourceAttr("data.vcfa_version.version", "version", currentVersion),
resource.TestCheckResourceAttr("data.vcfa_version.version", "api_version", apiVersion),
resource.TestCheckResourceAttr("data.vcfa_version.version", "matches_condition", "true"),
),
},
{
Config: step6,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.vcfa_tm_version.version", "id", fmt.Sprintf("tm_version='%s',condition='',fail_if_not_match='false'", currentVersion)),
resource.TestCheckResourceAttr("data.vcfa_tm_version.version", "tm_version", currentVersion),
resource.TestCheckResourceAttr("data.vcfa_tm_version.version", "tm_api_version", apiVersion),
resource.TestCheckNoResourceAttr("data.vcfa_tm_version.version", "matches_condition"),
resource.TestCheckResourceAttr("data.vcfa_version.version", "id", fmt.Sprintf("version='%s',condition='',fail_if_not_match='false'", currentVersion)),
resource.TestCheckResourceAttr("data.vcfa_version.version", "version", currentVersion),
resource.TestCheckResourceAttr("data.vcfa_version.version", "api_version", apiVersion),
resource.TestCheckNoResourceAttr("data.vcfa_version.version", "matches_condition"),
),
},
},
Expand All @@ -129,13 +129,13 @@ func TestAccVcfaTmVersion(t *testing.T) {

const testAccVcfaTmVersion = `
{{.SkipBinaryTest}}
data "vcfa_tm_version" "version" {
data "vcfa_version" "version" {
condition = "{{.Condition}}"
fail_if_not_match = {{.FailIfNotMatch}}
}
`

const testAccVcfaTmVersionWithoutArguments = `
data "vcfa_tm_version" "version" {
data "vcfa_version" "version" {
}
`
2 changes: 1 addition & 1 deletion vcfa/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func Resources(nameRegexp string, includeDeprecated bool) (map[string]*schema.Re
}

var globalDataSourceMap = map[string]*schema.Resource{
"vcfa_tm_version": datasourceVcfaTmVersion(), // 1.0
"vcfa_version": datasourceVcfaTmVersion(), // 1.0
"vcfa_vcenter": datasourceVcfaVcenter(), // 1.0
"vcfa_org": datasourceVcfaOrg(), // 1.0
"vcfa_nsx_manager": datasourceVcfaNsxManager(), // 1.0
Expand Down
2 changes: 1 addition & 1 deletion vcfa/provider_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func TestVcfaDataSources(t *testing.T) {
},
{
name: "MatchExactDataSourceName",
args: args{nameRegexp: "vcfa_tm_version", includeDeprecated: false},
args: args{nameRegexp: "vcfa_version", includeDeprecated: false},
wantLen: 1, // should return only one because exact name was given
lenOnly: true,
wantErr: false,
Expand Down
30 changes: 16 additions & 14 deletions vcfa/resource_vcfa_content_library_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func resourceVcfaContentLibraryItem() *schema.Resource {
"image_identifier": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("Virtual Machine Identifier (VMI) of the %s. This is a read only field", labelVcfaContentLibraryItem),
Description: fmt.Sprintf("Virtual Machine Identifier (VMI) of the %s. This is a read-only field", labelVcfaContentLibraryItem),
},
"is_published": {
Type: schema.TypeBool,
Expand Down Expand Up @@ -215,28 +215,30 @@ func resourceVcfaContentLibraryItemDelete(ctx context.Context, d *schema.Resourc
func resourceVcfaContentLibraryItemImport(_ context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
tmClient := meta.(ClientContainer).tmClient

id := strings.Split(d.Id(), ImportSeparator)
idSplit := strings.Split(d.Id(), ImportSeparator)
if len(idSplit) != 3 {
return nil, fmt.Errorf("ID syntax should be <%s name>%s<%s name>%s<%s name> for Tenant Content Library Items or System%s<%s name>%s<%s name> for "+
"Provider Content Library Items", labelVcfaOrg, ImportSeparator, labelVcfaContentLibrary, ImportSeparator, labelVcfaContentLibraryItem, ImportSeparator, labelVcfaContentLibrary, ImportSeparator, labelVcfaContentLibraryItem)
}

var tenantContext *govcd.TenantContext
clName, cliName := "", ""
switch len(id) {
case 3:
if strings.EqualFold(idSplit[0], "system") {
// Provider Content Library Item: No org needed
clName = idSplit[1]
cliName = idSplit[2]
} else {
// Tenant Content Library Item: Organization + Content Library + Content Library Item
org, err := tmClient.GetTmOrgByName(id[0])
org, err := tmClient.GetTmOrgByName(idSplit[0])
if err != nil {
return nil, fmt.Errorf("error getting %s with name '%s' for import: %s", labelVcfaOrg, id[0], err)
return nil, fmt.Errorf("error getting %s with name '%s' for import: %s", labelVcfaOrg, idSplit[0], err)
}
tenantContext = &govcd.TenantContext{
OrgId: org.TmOrg.ID,
OrgName: org.TmOrg.Name,
}
clName = id[1]
cliName = id[2]
case 2:
// Provider Content Library Item: Organization is not needed
clName = id[0]
cliName = id[1]
default:
return nil, fmt.Errorf("ID syntax should be <%s name>%s<%s name>%s<%s name> or <%s name>%s<%s name>", labelVcfaOrg, ImportSeparator, labelVcfaContentLibrary, ImportSeparator, labelVcfaContentLibraryItem, labelVcfaContentLibrary, ImportSeparator, labelVcfaContentLibraryItem)
clName = idSplit[1]
cliName = idSplit[2]
}

cl, err := tmClient.GetContentLibraryByName(clName, tenantContext)
Expand Down
2 changes: 1 addition & 1 deletion vcfa/resource_vcfa_content_library_item_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func TestAccVcfaContentLibraryItemProvider(t *testing.T) {
ResourceName: cli1,
ImportState: true,
ImportStateVerify: true,
ImportStateId: fmt.Sprintf("%s%s%s", testConfig.Tm.ContentLibrary, ImportSeparator, params["Name"].(string)+"1"),
ImportStateId: fmt.Sprintf("System%s%s%s%s", ImportSeparator, testConfig.Tm.ContentLibrary, ImportSeparator, params["Name"].(string)+"1"),
ImportStateVerifyIgnore: []string{"file_paths.#", "file_paths.0", "upload_piece_size", "%"}, // file_paths and upload_piece_size cannot be obtained during imports, that's why it's Optional
},
},
Expand Down
2 changes: 1 addition & 1 deletion vcfa/resource_vcfa_org_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ data "vcfa_org_settings" "allow_ds" {
}
`

// TestAccVcfaOrgClassicTenant tests a Tenant Manager Organization configured as "Classic Tenant"
// TestAccVcfaOrgClassicTenant tests an Organization configured as "Classic Tenant"
func TestAccVcfaOrgClassicTenant(t *testing.T) {
preTestChecks(t)
defer postTestChecks(t)
Expand Down
4 changes: 2 additions & 2 deletions vcfa/sample_vcfa_test_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"//" : "This section contains credentials related to the VCFA connection of Sys or Org user",
"user": "serviceadministrator",
"password": "somePassword",
"tmVersion": "10.7.0",
"tmApiVersion": "40.0",
"vcfaVersion": "9.0.0",
"apiVersion": "40.0",
"//": "Access token to be used instead of username/password",
"token": "",

Expand Down
Loading