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 upload from URL for catalog_item resource and allow update name and descriptions #770

Merged
merged 17 commits into from
Jan 18, 2022
Merged
2 changes: 2 additions & 0 deletions .changes/v3.6.0/770-features.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* `vcd_catalog_item` allows using `ova_url` to upload vApp template from URL [GH-770]
* `vcd_catalog_item` update allows changing `name` and `description` [GH-770]
vbauzys marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ require (
github.com/kr/pretty v0.2.1
github.com/vmware/go-vcloud-director/v2 v2.14.0
)

replace github.com/vmware/go-vcloud-director/v2 => github.com/vbauzysvmware/go-vcloud-director/v2 v2.0.0-20220110131834-ca8127ff7eec
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,13 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/ulikunitz/xz v0.5.8 h1:ERv8V6GKqVi23rgu5cj9pVfVzJbOqAY2Ntl88O6c2nQ=
github.com/ulikunitz/xz v0.5.8/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/vbauzysvmware/go-vcloud-director/v2 v2.0.0-20220110131834-ca8127ff7eec h1:hDpL1w29IkabnLfnD7AMjxgGY+M9qZPeU0lvlYp0x0A=
github.com/vbauzysvmware/go-vcloud-director/v2 v2.0.0-20220110131834-ca8127ff7eec/go.mod h1:2BS1yw61VN34WI0/nUYoInFvBc3Zcuf84d4ESiAAl68=
github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI=
github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4=
github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI=
github.com/vmware/go-vcloud-director/v2 v2.14.0 h1:ZSw1xuHbk0JomkpT0qr1R6Q9VWtb9vEsTnVYcqm9+oQ=
github.com/vmware/go-vcloud-director/v2 v2.14.0/go.mod h1:2BS1yw61VN34WI0/nUYoInFvBc3Zcuf84d4ESiAAl68=
github.com/xanzy/ssh-agent v0.3.0 h1:wUMzuKtKilRgBAD1sUb8gOwwRr2FGoBVumcjoOACClI=
github.com/xanzy/ssh-agent v0.3.0/go.mod h1:3s9xbODqPuuhK9JV1R321M/FlMZSBvE5aY6eAcqrDh0=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
13 changes: 7 additions & 6 deletions vcd/catalogitem.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package vcd

import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"log"
"strings"

Expand All @@ -10,36 +11,36 @@ import (
)

// Deletes catalog item which can be vApp template OVA or media ISO file
func deleteCatalogItem(d *schema.ResourceData, vcdClient *VCDClient) error {
func deleteCatalogItem(d *schema.ResourceData, vcdClient *VCDClient) diag.Diagnostics {
log.Printf("[TRACE] Catalog item delete started")

adminOrg, err := vcdClient.GetAdminOrgFromResource(d)
if err != nil {
return fmt.Errorf(errorRetrievingOrg, err)
return diag.Errorf(errorRetrievingOrg, err)
}

catalog, err := adminOrg.GetCatalogByName(d.Get("catalog").(string), false)
if err != nil {
log.Printf("[DEBUG] Unable to find catalog. Removing from tfstate")
return fmt.Errorf("unable to find catalog")
return diag.Errorf("unable to find catalog")
}

catalogItemName := d.Get("name").(string)
catalogItem, err := catalog.GetCatalogItemByName(catalogItemName, false)
if err != nil {
log.Printf("[DEBUG] Unable to find catalog item. Removing from tfstate")
return fmt.Errorf("unable to find catalog item %s", catalogItemName)
return diag.Errorf("unable to find catalog item %s", catalogItemName)
}

err = catalogItem.Delete()
if err != nil {
log.Printf("[DEBUG] Error removing catalog item %s", err)
return fmt.Errorf("error removing catalog item %s", err)
return diag.Errorf("error removing catalog item %s", err)
}

_, err = catalog.GetCatalogItemByName(catalogItemName, true)
if err == nil {
return fmt.Errorf("catalog item %s still found after deletion", catalogItemName)
return diag.Errorf("catalog item %s still found after deletion", catalogItemName)
}
log.Printf("[TRACE] Catalog item delete completed: %s", catalogItemName)

Expand Down
1 change: 1 addition & 0 deletions vcd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ type TestConfig struct {
} `json:"logging"`
Ova struct {
OvaPath string `json:"ovaPath,omitempty"`
OvfUrl string `json:"ovfUrl,omitempty"`
UploadPieceSize int64 `json:"uploadPieceSize,omitempty"`
UploadProgress bool `json:"uploadProgress,omitempty"`
OvaTestFileName string `json:"ovaTestFileName,omitempty"`
Expand Down
10 changes: 7 additions & 3 deletions vcd/datasource_vcd_catalog_item.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package vcd

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

func datasourceVcdCatalogItem() *schema.Resource {
return &schema.Resource{
Read: dataSourceVcdCatalogItemRead,
ReadContext: dataSourceVcdCatalogItemRead,
Schema: map[string]*schema.Schema{
"org": {
Type: schema.TypeString,
Expand Down Expand Up @@ -57,6 +61,6 @@ func datasourceVcdCatalogItem() *schema.Resource {
}
}

func dataSourceVcdCatalogItemRead(d *schema.ResourceData, meta interface{}) error {
func dataSourceVcdCatalogItemRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
return genericVcdCatalogItemRead(d, meta, "datasource")
}
6 changes: 4 additions & 2 deletions vcd/datasource_vcd_catalog_media.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package vcd

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

func datasourceVcdCatalogMedia() *schema.Resource {
return &schema.Resource{
Read: dataSourceVcdMediaRead,
ReadContext: dataSourceVcdMediaRead,

Schema: map[string]*schema.Schema{
"org": {
Expand Down Expand Up @@ -92,6 +94,6 @@ func datasourceVcdCatalogMedia() *schema.Resource {
}
}

func dataSourceVcdMediaRead(d *schema.ResourceData, meta interface{}) error {
func dataSourceVcdMediaRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
return genericVcdMediaRead(d, meta, "datasource")
}
Loading