Skip to content

Commit

Permalink
Add metadata
Browse files Browse the repository at this point in the history
Signed-off-by: abarreiro <[email protected]>
  • Loading branch information
abarreiro committed Mar 14, 2023
1 parent bc6e3ba commit 669afdc
Show file tree
Hide file tree
Showing 37 changed files with 670 additions and 38 deletions.
2 changes: 1 addition & 1 deletion vcd/datasource_vcd_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func datasourceVcdCatalog() *schema.Resource {
Description: "Key and value pairs for catalog metadata",
Deprecated: "Use metadata_entry instead",
},
"metadata_entry": getMetadataEntrySchema("Catalog", true),
"metadata_entry": getMetadataEntrySchema("Catalog", true, true),
"catalog_version": {
Type: schema.TypeInt,
Computed: true,
Expand Down
2 changes: 1 addition & 1 deletion vcd/datasource_vcd_catalog_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func datasourceVcdCatalogItem() *schema.Resource {
Description: "Key and value pairs from the metadata of the vApp template associated to this catalog item",
Deprecated: "Use metadata_entry instead",
},
"metadata_entry": getMetadataEntrySchema("Catalog Item", true),
"metadata_entry": getMetadataEntrySchema("Catalog Item", true, true),
"catalog_item_metadata": {
Type: schema.TypeMap,
Computed: true,
Expand Down
2 changes: 1 addition & 1 deletion vcd/datasource_vcd_catalog_media.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func datasourceVcdCatalogMedia() *schema.Resource {
Description: "Key and value pairs for catalog item metadata",
Deprecated: "Use metadata_entry instead",
},
"metadata_entry": getMetadataEntrySchema("Media", true),
"metadata_entry": getMetadataEntrySchema("Media", true, true),
"is_iso": {
Type: schema.TypeBool,
Computed: true,
Expand Down
2 changes: 1 addition & 1 deletion vcd/datasource_vcd_catalog_vapp_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func datasourceVcdCatalogVappTemplate() *schema.Resource {
Description: "Key and value pairs from the metadata of the vApp template",
Deprecated: "Use metadata_entry instead",
},
"metadata_entry": getMetadataEntrySchema("vApp Template", true),
"metadata_entry": getMetadataEntrySchema("vApp Template", true, true),
"vm_names": {
Type: schema.TypeSet,
Elem: &schema.Schema{
Expand Down
2 changes: 1 addition & 1 deletion vcd/datasource_vcd_independent_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func datasourceVcIndependentDisk() *schema.Resource {
Description: "Key and value pairs for disk metadata",
Deprecated: "Use metadata_entry instead",
},
"metadata_entry": getMetadataEntrySchema("Disk", true),
"metadata_entry": getMetadataEntrySchema("Disk", true, true),
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion vcd/datasource_vcd_network_direct.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func datasourceVcdNetworkDirect() *schema.Resource {
Description: "Key value map of metadata assigned to this network. Key and value can be any string",
Deprecated: "Use metadata_entry instead",
},
"metadata_entry": getMetadataEntrySchema("Network", true),
"metadata_entry": getMetadataEntrySchema("Network", true, true),
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion vcd/datasource_vcd_network_isolated.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func datasourceVcdNetworkIsolated() *schema.Resource {
Description: "Key value map of metadata assigned to this network. Key and value can be any string",
Deprecated: "Use metadata_entry instead",
},
"metadata_entry": getMetadataEntrySchema("Network", true),
"metadata_entry": getMetadataEntrySchema("Network", true, true),
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion vcd/datasource_vcd_network_isolated_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func datasourceVcdNetworkIsolatedV2() *schema.Resource {
Description: "Key value map of metadata assigned to this network. Key and value can be any string",
Deprecated: "Use metadata_entry instead",
},
"metadata_entry": getMetadataEntrySchema("Network", true),
"metadata_entry": getMetadataEntrySchema("Network", true, true),
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion vcd/datasource_vcd_network_routed.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func datasourceVcdNetworkRouted() *schema.Resource {
Description: "Key value map of metadata assigned to this network. Key and value can be any string",
Deprecated: "Use metadata_entry instead",
},
"metadata_entry": getMetadataEntrySchema("Network", true),
"metadata_entry": getMetadataEntrySchema("Network", true, true),
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion vcd/datasource_vcd_network_routed_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func datasourceVcdNetworkRoutedV2() *schema.Resource {
Description: "Key value map of metadata assigned to this network. Key and value can be any string",
Deprecated: "Use metadata_entry instead",
},
"metadata_entry": getMetadataEntrySchema("Network", true),
"metadata_entry": getMetadataEntrySchema("Network", true, true),
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion vcd/datasource_vcd_org.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func datasourceVcdOrg() *schema.Resource {
Description: "Key and value pairs for organization metadata",
Deprecated: "Use metadata_entry instead",
},
"metadata_entry": getMetadataEntrySchema("Organization", true),
"metadata_entry": getMetadataEntrySchema("Organization", true, true),
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion vcd/datasource_vcd_org_vdc.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func datasourceVcdOrgVdc() *schema.Resource {
Description: "Key and value pairs for Org VDC metadata",
Deprecated: "Use metadata_entry instead",
},
"metadata_entry": getMetadataEntrySchema("VDC", false),
"metadata_entry": getMetadataEntrySchema("VDC", false, true),
"vm_sizing_policy_ids": {
Type: schema.TypeSet,
Computed: true,
Expand Down
2 changes: 1 addition & 1 deletion vcd/datasource_vcd_provider_vdc.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func datasourceVcdProviderVdc() *schema.Resource {
Description: "Key and value pairs for Provider VDC metadata",
Deprecated: "Use metadata_entry instead",
},
"metadata_entry": getMetadataEntrySchema("Provider VDC", true),
"metadata_entry": getMetadataEntrySchema("Provider VDC", true, true),
},
}
}
Expand Down
9 changes: 9 additions & 0 deletions vcd/datasource_vcd_rde.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func datasourceVcdRde() *schema.Resource {
Description: "One of PRE_CREATED, RESOLVED or RESOLUTION_ERROR",
Computed: true,
},
"metadata_entry": getOpenApiMetadataEntrySchema("Runtime Defined Entity", true),
},
}
}
Expand Down Expand Up @@ -83,6 +84,14 @@ func datasourceVcdRdeRead(_ context.Context, d *schema.ResourceData, meta interf
dSet(d, "owner_id", rde.DefinedEntity.Owner.ID)
}

// Metadata is only available since API v37.0
if vcdClient.Client.APIVCDMaxVersionIs(">= 37.0") {
err = updateOpenApiMetadataInState(d, rde)
if err != nil {
return diag.Errorf("could not set metadata for the Runtime Defined Entity: %s", err)
}
}

d.SetId(rde.DefinedEntity.ID)

return nil
Expand Down
2 changes: 1 addition & 1 deletion vcd/datasource_vcd_storage_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func datasourceVcdStorageProfile() *schema.Resource {
Description: "Key value map of metadata retrieved from this storage profile. Key and value can be any string.",
Deprecated: "Use metadata_entry instead",
},
"metadata_entry": getMetadataEntrySchema("Storage Profile", true),
"metadata_entry": getMetadataEntrySchema("Storage Profile", true, true),
"iops_settings": {
Type: schema.TypeList,
Computed: true,
Expand Down
2 changes: 1 addition & 1 deletion vcd/datasource_vcd_vapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func datasourceVcdVApp() *schema.Resource {
Description: "Key value map of metadata to assign to this vApp. Key and value can be any string.",
Deprecated: "Use metadata_entry instead",
},
"metadata_entry": getMetadataEntrySchema("vApp", true),
"metadata_entry": getMetadataEntrySchema("vApp", true, true),
"href": {
Type: schema.TypeString,
Computed: true,
Expand Down
2 changes: 1 addition & 1 deletion vcd/datasource_vcd_vapp_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func vcdVmDS(vmType typeOfVm) map[string]*schema.Schema {
Description: "Key value map of metadata to assign to this VM",
Deprecated: "Use metadata_entry instead",
},
"metadata_entry": getMetadataEntrySchema("VM", true),
"metadata_entry": getMetadataEntrySchema("VM", true, true),
"href": {
Type: schema.TypeString,
Computed: true,
Expand Down
12 changes: 8 additions & 4 deletions vcd/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,17 @@ func metadataEntryDatasourceSchema(objectNameInDescription string) *schema.Schem

// metadataEntryResourceSchema returns the schema associated to metadata_entry for a given resource.
// The description will refer to the object name given as input.
func metadataEntryResourceSchema(objectNameInDescription string) *schema.Schema {
func metadataEntryResourceSchema(objectNameInDescription string, hasOldMetadata bool) *schema.Schema {
var conflictsWith []string
if hasOldMetadata {
conflictsWith = []string{"metadata"}
}
return &schema.Schema{
Type: schema.TypeSet,
Optional: true,
Computed: true, // This is required for `metadata_entry` to live together with deprecated `metadata`.
Description: fmt.Sprintf("Metadata entries for the given %s", objectNameInDescription),
ConflictsWith: []string{"metadata"},
ConflictsWith: conflictsWith,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"key": {
Expand Down Expand Up @@ -95,11 +99,11 @@ func metadataEntryResourceSchema(objectNameInDescription string) *schema.Schema
// getMetadataEntrySchema returns a schema for the "metadata_entry" attribute, that can be used to
// build data sources (isDatasource=true) or resources (isDatasource=false). The description of the
// attribute will refer to the input resource name.
func getMetadataEntrySchema(resourceNameInDescription string, isDatasource bool) *schema.Schema {
func getMetadataEntrySchema(resourceNameInDescription string, isDatasource, hasOldMetadataAttribute bool) *schema.Schema {
if isDatasource {
return metadataEntryDatasourceSchema(resourceNameInDescription)
}
return metadataEntryResourceSchema(resourceNameInDescription)
return metadataEntryResourceSchema(resourceNameInDescription, hasOldMetadataAttribute)
}

// metadataCompatible allows to consider all structs that implement metadata handling to be the same type
Expand Down
Loading

0 comments on commit 669afdc

Please sign in to comment.