terraform-provider-vcd
terraform-provider-vcd copied to clipboard
Add metadata_entry attribute to all current resources and data sources to support access levels, domain and types in VCD Metadata
Overview
This PR makes all resources and data sources that support metadata to handle all the attributes of a Metadata Entry (which are: key, value, type, access level and domain). Before, we lacked from the access level and the domain, and also the type (string, number, boolean, date) was restricted to string.
To do this, I've added the NEW attribute metadata_entry
to all current resources and data sources, which is a TypeSet with the mentioned attributes as children. metadata
is then deprecated, and either metadata
or a set of metadata_entry
is supported in a single resource (ConflictsWith).
Detailed description
The main changes are centralized in metadata.go and metadata_common_test.go. These two files provide some sort of "SDK" for Metadata in the provider, so adding the metadata support to a new resource should be quite simple:
- Use
getMetadataEntrySchema
to set the schema. - Use
createOrUpdateMetadataInVcd
on resource creation and update. - Use
updateMetadataInState
on resource/data source reads.
For tests, one can use just testMetadataEntry(t, hclTemplate, resourceAddress, extraParams)
like
testMetadataEntry(t, testAccCheckVcdCatalogMediaMetadata, "vcd_catalog_media.test-catalog-media", StringMap{
"Catalog": testConfig.VCD.Catalog.NsxtBackedCatalogName,
"MediaPath": testConfig.Media.MediaPath,
})
const testAccCheckVcdCatalogMediaMetadata = `
resource "vcd_catalog_media" "test-catalog-media" {
org = "{{.Org}}"
name = "{{.Name}}"
catalog = "{{.Catalog}}"
media_path = "{{.MediaPath}}"
{{.Metadata}}
}
`
To create a test that checks Create, Read, Update and Delete operations for metadata, with all possible types, access levels and domain options.
Nothing more should be needed.
The other changes in the remaining files are just usages of the above.