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 metadata support for Orgs and Disk resources/datasources #797

Merged
merged 23 commits into from
Mar 24, 2022
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
4 changes: 4 additions & 0 deletions .changes/v3.6.0/797-improvements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* `vcd_org` resource adds support for `metadata` so this field can be set when creating/updating organizations. [GH-797]
* `vcd_org` data source adds support for `metadata` so this field can be retrieved when reading from organizations. [GH-797]
* `vcd_independent_disk` resource adds support for `metadata` so this field can be set when creating/updating independent disks. [GH-797]
* `vcd_independent_disk` data source adds support for `metadata` so this field can be retrieved when reading from independent disks. [GH-797]
33 changes: 19 additions & 14 deletions vcd/datasource_vcd_independent_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ func datasourceVcIndependentDisk() *schema.Resource {
Optional: true,
Description: "The name of VDC to use, optional if defined at provider level",
},
"id": &schema.Schema{
"id": {
Type: schema.TypeString,
Optional: true,
},
"name": &schema.Schema{
"name": {
Type: schema.TypeString,
Optional: true,
},
"description": &schema.Schema{
"description": {
Type: schema.TypeString,
Computed: true,
Description: "independent disk description",
Expand All @@ -47,62 +47,67 @@ func datasourceVcIndependentDisk() *schema.Resource {
Computed: true,
Description: "size in MB",
},
"bus_type": &schema.Schema{
"bus_type": {
Type: schema.TypeString,
Computed: true,
},
"bus_sub_type": &schema.Schema{
"bus_sub_type": {
Type: schema.TypeString,
Computed: true,
},
"iops": &schema.Schema{
"iops": {
Type: schema.TypeInt,
Computed: true,
Description: "IOPS request for the created disk",
},
"owner_name": &schema.Schema{
"owner_name": {
Type: schema.TypeString,
Computed: true,
Description: "The owner name of the disk",
},
"datastore_name": &schema.Schema{
"datastore_name": {
Type: schema.TypeString,
Computed: true,
Description: "Datastore name",
},
"is_attached": &schema.Schema{
"is_attached": {
Type: schema.TypeBool,
Computed: true,
Description: "True if the disk is already attached",
},
"encrypted": &schema.Schema{
"encrypted": {
Type: schema.TypeBool,
Computed: true,
Description: "True if disk is encrypted",
},
"sharing_type": &schema.Schema{
"sharing_type": {
Type: schema.TypeString,
Computed: true,
Description: "This is the sharing type. This attribute can only have values defined one of: `DiskSharing`,`ControllerSharing`",
},
"uuid": &schema.Schema{
"uuid": {
Type: schema.TypeString,
Computed: true,
Description: "The UUID of this named disk's device backing",
},
"attached_vm_ids": &schema.Schema{
"attached_vm_ids": {
Type: schema.TypeSet,
Computed: true,
Description: "Set of VM IDs which are using the disk",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"metadata": {
Type: schema.TypeMap,
Computed: true,
Description: "Key and value pairs for disk metadata",
},
},
}
}

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

_, vdc, err := vcdClient.GetOrgAndVdc("", d.Get("vdc").(string))
Expand Down
24 changes: 22 additions & 2 deletions vcd/datasource_vcd_independent_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ func TestAccVcdDataSourceIndependentDisk(t *testing.T) {
"Tags": "disk",
"dataSourceName": datasourceName,
"datasourceNameWithId": datasourceNameWithId,
"metadataKey": "key1",
"metadataValue": "value1",
}

// regexp for empty value
Expand All @@ -49,7 +51,12 @@ func TestAccVcdDataSourceIndependentDisk(t *testing.T) {
sharingType = "None"
}

params["FuncName"] = t.Name() + "-Step1"
configText := templateFill(testAccCheckVcdDataSourceIndependentDisk, params)
params["metadataKey"] = "key3"
params["metadataValue"] = "value3"
params["FuncName"] = t.Name() + "-Step2"
configText2 := templateFill(testAccCheckVcdDataSourceIndependentDisk, params)
params["FuncName"] = t.Name() + "-withId"
configTextWithId := templateFill(testAccCheckVcdDataSourceIndependentDiskWithId, params)
if vcdShortTest {
Expand All @@ -63,7 +70,7 @@ func TestAccVcdDataSourceIndependentDisk(t *testing.T) {
ProviderFactories: testAccProviders,
CheckDestroy: testDiskResourcesDestroyed,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: configText,
Check: resource.ComposeTestCheckFunc(
testAccCheckDiskCreated("vcd_independent_disk."+resourceName),
Expand All @@ -73,6 +80,7 @@ func TestAccVcdDataSourceIndependentDisk(t *testing.T) {
resource.TestCheckResourceAttr("data.vcd_independent_disk."+datasourceName, "bus_type", "SCSI"),
resource.TestCheckResourceAttr("data.vcd_independent_disk."+datasourceName, "bus_sub_type", "lsilogicsas"),
resource.TestCheckResourceAttr("data.vcd_independent_disk."+datasourceName, "storage_profile", "*"),
resource.TestCheckResourceAttr("data.vcd_independent_disk."+datasourceName, "metadata.key1", params["metadataValue"].(string)),
resource.TestMatchOutput("owner_name", regexp.MustCompile(`^\S+`)),
resource.TestMatchOutput("datastore_name", regexp.MustCompile(`^\S+`)),
resource.TestMatchOutput("uuid", uuidMatchRegexp),
Expand All @@ -82,7 +90,15 @@ func TestAccVcdDataSourceIndependentDisk(t *testing.T) {
testCheckDiskNonStringOutputs(),
),
},
resource.TestStep{
{
Config: configText2,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckNoResourceAttr("data.vcd_independent_disk."+datasourceName, "metadata.key1"),
resource.TestCheckResourceAttr("data.vcd_independent_disk."+datasourceName, "metadata.key2", "value2"),
resource.TestCheckResourceAttr("data.vcd_independent_disk."+datasourceName, "metadata.key3", params["metadataValue"].(string)),
),
},
{
Config: configTextWithId,
Check: resource.ComposeTestCheckFunc(
testAccCheckDiskCreated("vcd_independent_disk."+resourceName),
Expand Down Expand Up @@ -132,6 +148,10 @@ resource "vcd_independent_disk" "{{.ResourceName}}" {
bus_type = "{{.busType}}"
bus_sub_type = "{{.busSubType}}"
storage_profile = "{{.storageProfileName}}"
metadata = {
{{.metadataKey}} = "{{.metadataValue}}"
key2 = "value2"
}
}

data "vcd_independent_disk" "{{.dataSourceName}}" {
Expand Down
36 changes: 18 additions & 18 deletions vcd/datasource_vcd_org.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,66 +16,66 @@ func datasourceVcdOrg() *schema.Resource {
Required: true,
Description: "Organization name for lookup",
},
"full_name": &schema.Schema{
"full_name": {
Type: schema.TypeString,
Computed: true,
},
"description": &schema.Schema{
"description": {
Type: schema.TypeString,
Computed: true,
},
"is_enabled": &schema.Schema{
"is_enabled": {
Type: schema.TypeBool,
Computed: true,
Description: "True if this organization is enabled (allows login and all other operations).",
},
"deployed_vm_quota": &schema.Schema{
"deployed_vm_quota": {
Type: schema.TypeInt,
Computed: true,
Description: "Maximum number of virtual machines that can be deployed simultaneously by a member of this organization. (0 = unlimited)",
},
"stored_vm_quota": &schema.Schema{
"stored_vm_quota": {
Type: schema.TypeInt,
Computed: true,
Description: "Maximum number of virtual machines in vApps or vApp templates that can be stored in an undeployed state by a member of this organization. (0 = unlimited)",
},
"can_publish_catalogs": &schema.Schema{
"can_publish_catalogs": {
Type: schema.TypeBool,
Computed: true,
Description: "True if this organization is allowed to share catalogs.",
},
"can_publish_external_catalogs": &schema.Schema{
"can_publish_external_catalogs": {
Type: schema.TypeBool,
Computed: true,
Description: "True if this organization is allowed to publish external catalogs.",
},
"can_subscribe_external_catalogs": &schema.Schema{
"can_subscribe_external_catalogs": {
Type: schema.TypeBool,
Computed: true,
Description: "True if this organization is allowed to subscribe to external catalogs.",
},
"vapp_lease": &schema.Schema{
"vapp_lease": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"maximum_runtime_lease_in_sec": &schema.Schema{
"maximum_runtime_lease_in_sec": {
Type: schema.TypeInt,
Computed: true,
Description: "How long vApps can run before they are automatically stopped (in seconds)",
},
"power_off_on_runtime_lease_expiration": &schema.Schema{
"power_off_on_runtime_lease_expiration": {
Type: schema.TypeBool,
Computed: true,
Description: "When true, vApps are powered off when the runtime lease expires. " +
"When false, vApps are suspended when the runtime lease expires",
},
"maximum_storage_lease_in_sec": &schema.Schema{
"maximum_storage_lease_in_sec": {
Type: schema.TypeInt,
Computed: true,
Description: "How long stopped vApps are available before being automatically cleaned up (in seconds)",
},
"delete_on_storage_lease_expiration": &schema.Schema{
"delete_on_storage_lease_expiration": {
Type: schema.TypeBool,
Computed: true,
Description: "If true, storage for a vApp is deleted when the vApp's lease expires. " +
Expand All @@ -84,17 +84,17 @@ func datasourceVcdOrg() *schema.Resource {
},
},
},
"vapp_template_lease": &schema.Schema{
"vapp_template_lease": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"maximum_storage_lease_in_sec": &schema.Schema{
"maximum_storage_lease_in_sec": {
Type: schema.TypeInt,
Computed: true,
Description: "How long vApp templates are available before being automatically cleaned up (in seconds)",
},
"delete_on_storage_lease_expiration": &schema.Schema{
"delete_on_storage_lease_expiration": {
Type: schema.TypeBool,
Computed: true,
Description: "If true, storage for a vAppTemplate is deleted when the vAppTemplate lease expires. " +
Expand All @@ -103,7 +103,7 @@ func datasourceVcdOrg() *schema.Resource {
},
},
},
"delay_after_power_on_seconds": &schema.Schema{
"delay_after_power_on_seconds": {
Type: schema.TypeInt,
Computed: true,
Description: "Specifies this organization's default for virtual machine boot delay after power on.",
Expand All @@ -112,7 +112,7 @@ func datasourceVcdOrg() *schema.Resource {
}
}

func datasourceVcdOrgRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
func datasourceVcdOrgRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics

vcdClient := meta.(*VCDClient)
Expand Down
2 changes: 1 addition & 1 deletion vcd/datasource_vcd_org_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ resource "vcd_org" "{{.OrgName2}}" {
delay_after_power_on_seconds = data.vcd_org.{{.OrgName1}}.delay_after_power_on_seconds
delete_force = "true"
delete_recursive = "true"
vapp_lease {
vapp_lease {
vbauzys marked this conversation as resolved.
Show resolved Hide resolved
maximum_runtime_lease_in_sec = data.vcd_org.{{.OrgName1}}.vapp_lease.0.maximum_runtime_lease_in_sec
power_off_on_runtime_lease_expiration = data.vcd_org.{{.OrgName1}}.vapp_lease.0.power_off_on_runtime_lease_expiration
maximum_storage_lease_in_sec = data.vcd_org.{{.OrgName1}}.vapp_lease.0.maximum_storage_lease_in_sec
Expand Down
Loading