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: 2 additions & 0 deletions .changes/v1.0.0/13-features.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* **New Resource:** `vcfa_content_library_item` to manage Content Library Items [GH-13]
* **New Data Source:** `vcfa_content_library_item` to read Content Library Items [GH-13]
Binary file added test-resources/test_vapp_template.ova
Binary file not shown.
3 changes: 3 additions & 0 deletions vcfa/datasource_not_found_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func testSpecificDataSourceNotFound(dataSourceName string, vcdClient *VCDClient)
"vcfa_org_vdc",
"vcfa_tier0_gateway",
"vcfa_content_library",
"vcfa_content_library_item",
}

if contains(dataSourcesRequiringSysAdmin, dataSourceName) && !usingSysAdmin() {
Expand Down Expand Up @@ -150,6 +151,8 @@ func addMandatoryParams(dataSourceName string, mandatoryFields []string, t *test
templateFields = templateFields + `org_id = "urn:vcloud:org:12345678-1234-1234-1234-123456789012"` + "\n"
case "edge_cluster_id":
templateFields = templateFields + `edge_cluster_id = "urn:vcloud:edgeCluster:12345678-1234-1234-1234-123456789012"` + "\n"
case "content_library_id":
templateFields = templateFields + `content_library_id = "urn:vcloud:contentLibrary:12345678-1234-1234-1234-123456789012"` + "\n"
}
}

Expand Down
4 changes: 2 additions & 2 deletions vcfa/datasource_vcfa_content_library.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ func datasourceVcfaContentLibrary() *schema.Resource {
"library_type": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("The type of content library, can be either PROVIDER (%s that is scoped to a "+
"provider) or TENANT (%s that is scoped to a tenant organization)", labelVcfaContentLibrary, labelVcfaContentLibrary),
Description: fmt.Sprintf("The type of %s, can be either PROVIDER (%s that is scoped to a "+
"provider) or TENANT (%s that is scoped to a tenant organization)", labelVcfaContentLibrary, labelVcfaContentLibrary, labelVcfaContentLibrary),
},
"subscription_config": {
Type: schema.TypeList,
Expand Down
95 changes: 95 additions & 0 deletions vcfa/datasource_vcfa_content_library_item.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package vcfa

import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func datasourceVcfaContentLibraryItem() *schema.Resource {
return &schema.Resource{
ReadContext: datasourceVcfaContentLibraryItemRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: fmt.Sprintf("Name of the %s", labelVcfaContentLibraryItem),
},
"content_library_id": {
Type: schema.TypeString,
Required: true,
Description: fmt.Sprintf("ID of the %s that this %s belongs to", labelVcfaContentLibrary, labelVcfaContentLibraryItem),
},
"creation_date": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("The ISO-8601 timestamp representing when this %s was created", labelVcfaContentLibraryItem),
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("The description of the %s", labelVcfaContentLibraryItem),
},
"image_identifier": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("Virtual Machine Identifier (VMI) of the %s. This is a read only field", labelVcfaContentLibraryItem),
},
"is_published": {
Type: schema.TypeBool,
Computed: true,
Description: fmt.Sprintf("Whether this %s is published", labelVcfaContentLibraryItem),
},
"is_subscribed": {
Type: schema.TypeBool,
Computed: true,
Description: fmt.Sprintf("Whether this %s is subscribed", labelVcfaContentLibraryItem),
},
"last_successful_sync": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("The ISO-8601 timestamp representing when this %s was last synced if subscribed", labelVcfaContentLibraryItem),
},
"owner_org_id": {
Type: schema.TypeString,
// TODO: TM: This should be optional: Either Provider or Tenant can create CLs
Computed: true,
Description: fmt.Sprintf("The reference to the %s that the %s belongs to", labelVcfaOrg, labelVcfaContentLibraryItem),
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("Status of this %s", labelVcfaContentLibraryItem),
},
"version": {
Type: schema.TypeInt,
Computed: true,
Description: fmt.Sprintf("The version of this %s. For a subscribed library, this version is same as in publisher library", labelVcfaContentLibraryItem),
},
},
}
}

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

// TODO: TM: Tenant Context should not be nil and depend on the configured owner_org_id
cl, err := vcdClient.GetContentLibraryById(d.Get("content_library_id").(string), nil)
if err != nil {
return diag.Errorf("error retrieving %s: %s", labelVcfaContentLibrary, err)
}

cli, err := cl.GetContentLibraryItemByName(d.Get("name").(string))
if err != nil {
return diag.Errorf("error retrieving %s: %s", labelVcfaContentLibraryItem, err)
}

err = setContentLibraryItemData(vcdClient, d, cli)
if err != nil {
return diag.FromErr(err)
}

return nil
}
20 changes: 11 additions & 9 deletions vcfa/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,24 @@ var globalDataSourceMap = map[string]*schema.Resource{
"vcfa_region_storage_policy": datasourceVcfaRegionStoragePolicy(), // 1.0
"vcfa_storage_class": datasourceVcfaStorageClass(), // 1.0
"vcfa_content_library": datasourceVcfaContentLibrary(), // 1.0
"vcfa_content_library_item": datasourceVcfaContentLibraryItem(), // 1.0
"vcfa_tier0_gateway": datasourceVcfaTier0Gateway(), // 1.0
"vcfa_provider_gateway": datasourceVcfaProviderGateway(), // 1.0
"vcfa_edge_cluster": datasourceVcfaEdgeCluster(), // 1.0
"vcfa_edge_cluster_qos": datasourceVcfaEdgeClusterQos(), // 1.0
}

var globalResourceMap = map[string]*schema.Resource{
"vcfa_vcenter": resourceVcfaVcenter(), // 1.0
"vcfa_org": resourceVcfaOrg(), // 1.0
"vcfa_nsx_manager": resourceVcfaNsxManager(), // 1.0
"vcfa_region": resourceVcfaRegion(), // 1.0
"vcfa_ip_space": resourceVcfaIpSpace(), // 1.0
"vcfa_org_vdc": resourceVcfaOrgVdc(), // 1.0
"vcfa_content_library": resourceVcfaContentLibrary(), // 1.0
"vcfa_provider_gateway": resourceVcfaProviderGateway(), // 1.0
"vcfa_edge_cluster_qos": resourceVcfaEdgeClusterQos(), // 1.0
"vcfa_vcenter": resourceVcfaVcenter(), // 1.0
"vcfa_org": resourceVcfaOrg(), // 1.0
"vcfa_nsx_manager": resourceVcfaNsxManager(), // 1.0
"vcfa_region": resourceVcfaRegion(), // 1.0
"vcfa_ip_space": resourceVcfaIpSpace(), // 1.0
"vcfa_org_vdc": resourceVcfaOrgVdc(), // 1.0
"vcfa_content_library": resourceVcfaContentLibrary(), // 1.0
"vcfa_content_library_item": resourceVcfaContentLibraryItem(), // 1.0
"vcfa_provider_gateway": resourceVcfaProviderGateway(), // 1.0
"vcfa_edge_cluster_qos": resourceVcfaEdgeClusterQos(), // 1.0
}

// Provider returns a terraform.ResourceProvider.
Expand Down
11 changes: 4 additions & 7 deletions vcfa/resource_vcfa_content_library.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ import (

const labelVcfaContentLibrary = "Content Library"

// TODO: TM: Move to Content Library Item
const labelVcfaContentLibraryItem = "Content Library Item"

func resourceVcfaContentLibrary() *schema.Resource {
return &schema.Resource{
CreateContext: resourceVcfaContentLibraryCreate,
Expand Down Expand Up @@ -91,8 +88,8 @@ func resourceVcfaContentLibrary() *schema.Resource {
"library_type": {
Type: schema.TypeString,
Computed: true,
Description: fmt.Sprintf("The type of content library, can be either PROVIDER (%s that is scoped to a "+
"provider) or TENANT (%s that is scoped to a tenant organization)", labelVcfaContentLibrary, labelVcfaContentLibrary),
Description: fmt.Sprintf("The type of %s, can be either PROVIDER (%s that is scoped to a "+
"provider) or TENANT (%s that is scoped to a tenant organization)", labelVcfaContentLibrary, labelVcfaContentLibrary, labelVcfaContentLibrary),
},
"subscription_config": {
Type: schema.TypeList,
Expand Down Expand Up @@ -164,7 +161,7 @@ func resourceVcfaContentLibraryRead(_ context.Context, d *schema.ResourceData, m
}
if govcd.ContainsNotFound(err) {
d.SetId("")
log.Printf("[DEBUG] Content Library no longer exists. Removing from tfstate")
log.Printf("[DEBUG] %s no longer exists. Removing from tfstate", labelVcfaContentLibrary)
}
if err != nil {
return diag.FromErr(err)
Expand Down Expand Up @@ -216,7 +213,7 @@ func resourceVcfaContentLibraryImport(_ context.Context, d *schema.ResourceData,

idSplit := strings.Split(d.Id(), ImportSeparator)
if len(idSplit) > 2 {
return nil, fmt.Errorf("invalid import identifier '%s', should be either <Content Library name>, or <Organization name>%s<Content Library name>", d.Id(), ImportSeparator)
return nil, fmt.Errorf("invalid import identifier '%s', should be either <%s name>, or <%s name>%s<%s name>", labelVcfaContentLibrary, labelVcfaOrg, labelVcfaContentLibrary, d.Id(), ImportSeparator)
}
var cl *govcd.ContentLibrary
var org *govcd.TmOrg
Expand Down
Loading