From 7a1d1d2a04aa9488beb1ca051720ea988ecfaa24 Mon Sep 17 00:00:00 2001 From: Giuseppe Maxia Date: Thu, 1 Dec 2022 21:04:59 +0100 Subject: [PATCH 01/16] Add functions to find a catalog without its Org These changes fix the problem of a catalog that was shared to the current org, but a tenant could not retrieve it for lack of privileges. It also fixes the case when multiple catalogs with the same name are available in the organization. The new functions search for catalogs without need of accessing the sharing organization. Also added a new 'is_local' property to all catalog resources and data sources. This property tells whether the catalog was created in the current org or not. Signed-off-by: Giuseppe Maxia --- vcd/datasource_vcd_catalog.go | 71 +++++++++++++++++++++--- vcd/datasource_vcd_subscribed_catalog.go | 7 ++- vcd/resource_vcd_catalog.go | 37 ++++++++---- vcd/resource_vcd_subscribed_catalog.go | 7 ++- 4 files changed, 102 insertions(+), 20 deletions(-) diff --git a/vcd/datasource_vcd_catalog.go b/vcd/datasource_vcd_catalog.go index 270bbc78f..4184b3af5 100644 --- a/vcd/datasource_vcd_catalog.go +++ b/vcd/datasource_vcd_catalog.go @@ -2,9 +2,12 @@ package vcd import ( "context" + "fmt" "log" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/vmware/go-vcloud-director/v2/types/v56" + "github.com/vmware/go-vcloud-director/v2/util" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/vmware/go-vcloud-director/v2/govcd" @@ -106,6 +109,11 @@ func datasourceVcdCatalog() *schema.Resource { Computed: true, Description: "True if this catalog is shared.", }, + "is_local": { + Type: schema.TypeBool, + Computed: true, + Description: "True if this catalog belongs to the current organization.", + }, "is_published": { Type: schema.TypeBool, Computed: true, @@ -141,30 +149,77 @@ func datasourceVcdCatalog() *schema.Resource { } } +func getOrgName(vcdClient *VCDClient, d *schema.ResourceData) string { + orgName := d.Get("org").(string) + if orgName == "" { + orgName = vcdClient.Org + } + return orgName +} + +func getCatalogFromResource(catalogName string, d *schema.ResourceData, meta interface{}) (*govcd.AdminCatalog, error) { + vcdClient := meta.(*VCDClient) + + orgName := getOrgName(vcdClient, d) + if orgName == "" { + return nil, fmt.Errorf("'org' property not supplied in the resource or in provider") + } + + catalogRecords, err := vcdClient.VCDClient.Client.QueryCatalogRecords(catalogName) + if err != nil { + return nil, fmt.Errorf("error retrieving catalog records for catalog %s", catalogName) + } + var catalogRecord *types.CatalogRecord + for _, cr := range catalogRecords { + if cr.OrgName == orgName { + catalogRecord = cr + break + } + } + if catalogRecord == nil { + return nil, fmt.Errorf("no records found for catalog '%s' from org '%s'", catalogName, orgName) + } + return vcdClient.VCDClient.Client.GetCatalogByHref(catalogRecord.HREF) +} + func datasourceVcdCatalogRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var ( - vcdClient = meta.(*VCDClient) - catalog *govcd.AdminCatalog + vcdClient = meta.(*VCDClient) + catalog *govcd.AdminCatalog + err error + catalogOrgIsAvailable bool = true ) if !nameOrFilterIsSet(d) { return diag.Errorf(noNameOrFilterError, "vcd_catalog") } - adminOrg, err := vcdClient.GetAdminOrgFromResource(d) - if err != nil { - return diag.Errorf(errorRetrievingOrg, err) + orgName := getOrgName(vcdClient, d) + if orgName == "" { + return diag.Errorf("'org' property not supplied in the resource or in provider") } - log.Printf("[TRACE] Org %s found", adminOrg.AdminOrg.Name) + + adminOrg, orgErr := vcdClient.GetAdminOrgFromResource(d) + orgFound := "" + if orgErr != nil { + util.Logger.Printf("[TRACE] error retrieving org: %s", orgErr) + catalogOrgIsAvailable = false + orgFound = "NOT" + } + log.Printf("[TRACE] Org '%s' %s found", orgName, orgFound) identifier := d.Get("name").(string) filter, hasFilter := d.GetOk("filter") if hasFilter { + if !catalogOrgIsAvailable { + return diag.Errorf("cannot search by filter when org is not reachable by the current user. "+ + "If the catalog is shared, it will be retrieved only by name: %s", orgErr) + } catalog, err = getCatalogByFilter(adminOrg, filter, vcdClient.Client.IsSysAdmin) } else { - catalog, err = adminOrg.GetAdminCatalogByNameOrId(identifier, false) + catalog, err = getCatalogFromResource(identifier, d, meta) } if err != nil { log.Printf("[DEBUG] Catalog %s not found. Setting ID to nothing", identifier) @@ -193,7 +248,7 @@ func datasourceVcdCatalogRead(_ context.Context, d *schema.ResourceData, meta in return diag.Errorf("There was an issue when setting metadata into the schema - %s", err) } - err = setCatalogData(d, adminOrg, catalog, "vcd_catalog") + err = setCatalogData(d, vcdClient, orgName, catalog, "vcd_catalog") if err != nil { return diag.FromErr(err) } diff --git a/vcd/datasource_vcd_subscribed_catalog.go b/vcd/datasource_vcd_subscribed_catalog.go index 4338da206..090a668e8 100644 --- a/vcd/datasource_vcd_subscribed_catalog.go +++ b/vcd/datasource_vcd_subscribed_catalog.go @@ -90,6 +90,11 @@ func datasourceVcdSubscribedCatalog() *schema.Resource { Computed: true, Description: "True if this catalog is shared.", }, + "is_local": { + Type: schema.TypeBool, + Computed: true, + Description: "True if this catalog belongs to the current organization.", + }, "is_published": { Type: schema.TypeBool, Computed: true, @@ -180,7 +185,7 @@ func datasourceVcdSubscribedCatalogRead(ctx context.Context, d *schema.ResourceD dSet(d, "subscription_url", adminCatalog.AdminCatalog.ExternalCatalogSubscription.Location) dSet(d, "make_local_copy", adminCatalog.AdminCatalog.ExternalCatalogSubscription.LocalCopy) - err = setCatalogData(d, adminOrg, adminCatalog, "vcd_subscribed_catalog") + err = setCatalogData(d, vcdClient, adminOrg.AdminOrg.Name, adminCatalog, "vcd_subscribed_catalog") if err != nil { return diag.Errorf("%v", err) } diff --git a/vcd/resource_vcd_catalog.go b/vcd/resource_vcd_catalog.go index ab2432154..0058fe5c3 100644 --- a/vcd/resource_vcd_catalog.go +++ b/vcd/resource_vcd_catalog.go @@ -142,6 +142,11 @@ func resourceVcdCatalog() *schema.Resource { Computed: true, Description: "True if this catalog is shared.", }, + "is_local": { + Type: schema.TypeBool, + Computed: true, + Description: "True if this catalog belongs to the current organization.", + }, "is_published": { Type: schema.TypeBool, Computed: true, @@ -289,7 +294,7 @@ func genericResourceVcdCatalogRead(d *schema.ResourceData, meta interface{}) err return err } - err = setCatalogData(d, adminOrg, adminCatalog, "vcd_catalog") + err = setCatalogData(d, vcdClient, adminOrg.AdminOrg.Name, adminCatalog, "vcd_catalog") if err != nil { return err } @@ -462,19 +467,31 @@ func resourceVcdCatalogImport(_ context.Context, d *schema.ResourceData, meta in return []*schema.ResourceData{d}, nil } -func setCatalogData(d *schema.ResourceData, adminOrg *govcd.AdminOrg, adminCatalog *govcd.AdminCatalog, resourceType string) error { +func setCatalogData(d *schema.ResourceData, vcdClient *VCDClient, orgName string, adminCatalog *govcd.AdminCatalog, resourceType string) error { // Catalog record is retrieved to get the owner name, number of vApp templates and medias, and if the catalog is shared and published - catalogRecords, err := adminOrg.FindCatalogRecords(adminCatalog.AdminCatalog.Name) + catalogRecords, err := vcdClient.VCDClient.Client.QueryCatalogRecords(adminCatalog.AdminCatalog.Name) if err != nil { - log.Printf("[DEBUG] Unable to retrieve catalog record: %s", err) - return fmt.Errorf("unable to retrieve catalog record - %s", err) + log.Printf("[DEBUG] Unable to retrieve catalog records: %s", err) + return fmt.Errorf("unable to retrieve catalog records - %s", err) + } + var catalogRecord *types.CatalogRecord + + for _, cr := range catalogRecords { + if cr.OrgName == orgName { + catalogRecord = cr + break + } + } + if catalogRecord == nil { + return fmt.Errorf("error retrieving catalog record for catalog '%s' from org '%s'", adminCatalog.AdminCatalog.Name, orgName) } - dSet(d, "catalog_version", catalogRecords[0].Version) - dSet(d, "owner_name", catalogRecords[0].OwnerName) - dSet(d, "is_published", catalogRecords[0].IsPublished) - dSet(d, "is_shared", catalogRecords[0].IsShared) - dSet(d, "publish_subscription_type", catalogRecords[0].PublishSubscriptionType) + dSet(d, "catalog_version", catalogRecord.Version) + dSet(d, "owner_name", catalogRecord.OwnerName) + dSet(d, "is_published", catalogRecord.IsPublished) + dSet(d, "is_shared", catalogRecord.IsShared) + dSet(d, "is_local", catalogRecord.IsLocal) + dSet(d, "publish_subscription_type", catalogRecord.PublishSubscriptionType) var rawMediaItemsList []interface{} var rawVappTemplatesList []interface{} diff --git a/vcd/resource_vcd_subscribed_catalog.go b/vcd/resource_vcd_subscribed_catalog.go index b85a9f1ef..6922ba006 100644 --- a/vcd/resource_vcd_subscribed_catalog.go +++ b/vcd/resource_vcd_subscribed_catalog.go @@ -146,6 +146,11 @@ func resourceVcdSubscribedCatalog() *schema.Resource { Computed: true, Description: "True if this catalog is shared.", }, + "is_local": { + Type: schema.TypeBool, + Computed: true, + Description: "True if this catalog belongs to the current organization.", + }, "is_published": { Type: schema.TypeBool, Computed: true, @@ -335,7 +340,7 @@ func resourceVcdSubscribedCatalogRead(ctx context.Context, d *schema.ResourceDat } dSet(d, "subscription_url", adminCatalog.AdminCatalog.ExternalCatalogSubscription.Location) dSet(d, "make_local_copy", adminCatalog.AdminCatalog.ExternalCatalogSubscription.LocalCopy) - err = setCatalogData(d, adminOrg, adminCatalog, "vcd_subscribed_catalog") + err = setCatalogData(d, vcdClient, adminOrg.AdminOrg.Name, adminCatalog, "vcd_subscribed_catalog") if err != nil { return diag.Errorf("%v", err) } From 42f74a599afd4a7a31642076fdc3202fd6872195 Mon Sep 17 00:00:00 2001 From: Giuseppe Maxia Date: Thu, 1 Dec 2022 21:13:11 +0100 Subject: [PATCH 02/16] Prepare for point release Signed-off-by: Giuseppe Maxia --- CHANGELOG.md | 4 ++++ PREVIOUS_VERSION | 2 +- VERSION | 2 +- website/docs/index.html.markdown | 4 ++-- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ab284ba2..f2acaae7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.8.1 (TBC) + +Changes in progress for v3.8.1 are available at [.changes/v3.8.1](https://github.com/vmware/terraform-provider-vcd/tree/main/.changes/v3.8.1) until the release. + ## 3.8.0 (November 25, 2022) ### FEATURES diff --git a/PREVIOUS_VERSION b/PREVIOUS_VERSION index d1e9cf3bb..40c06ccb7 100644 --- a/PREVIOUS_VERSION +++ b/PREVIOUS_VERSION @@ -1 +1 @@ -v3.7.0 +v3.8.0 diff --git a/VERSION b/VERSION index 40c06ccb7..32f8572ea 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v3.8.0 +v3.8.1 diff --git a/website/docs/index.html.markdown b/website/docs/index.html.markdown index 2f6818289..1e0f9be70 100644 --- a/website/docs/index.html.markdown +++ b/website/docs/index.html.markdown @@ -6,7 +6,7 @@ description: |- The VMware Cloud Director provider is used to interact with the resources supported by VMware Cloud Director. The provider needs to be configured with the proper credentials before it can be used. --- -# VMware Cloud Director Provider 3.8 +# VMware Cloud Director Provider 3.8.1 The VMware Cloud Director provider is used to interact with the resources supported by VMware Cloud Director. The provider needs to be configured with the proper credentials before it can be used. @@ -23,7 +23,7 @@ When upgrading the provider please check for such labels for the resources you a The following Cloud Director versions are supported by this provider: * 10.3 -* 10.4 +* 10.4.1 Also Cloud Director Service (CDS) is supported. From 4d45964db29c620e324f60f140c3066966b3dfd2 Mon Sep 17 00:00:00 2001 From: Giuseppe Maxia Date: Thu, 1 Dec 2022 21:13:46 +0100 Subject: [PATCH 03/16] Fix title of catalog operations guide Signed-off-by: Giuseppe Maxia --- .../docs/guides/catalog_subscription_and_sharing.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/guides/catalog_subscription_and_sharing.html.markdown b/website/docs/guides/catalog_subscription_and_sharing.html.markdown index 1768c4953..b417a79e3 100644 --- a/website/docs/guides/catalog_subscription_and_sharing.html.markdown +++ b/website/docs/guides/catalog_subscription_and_sharing.html.markdown @@ -1,6 +1,6 @@ --- layout: "vcd" -page_title: "VMware Cloud Director: catalog-subscription-and-sharing" +page_title: "VMware Cloud Director: Catalog subscription and sharing" sidebar_current: "docs-vcd-guides-catalog-subscription-and-sharing" description: |- Provides guidance to VMware Cloud catalog publishing, subscribing, and sharing From f0d332a576d9aa3684ff1ae60610002df0726567 Mon Sep 17 00:00:00 2001 From: Giuseppe Maxia Date: Thu, 1 Dec 2022 21:14:15 +0100 Subject: [PATCH 04/16] Update go.mod with go-vcloud-director latest Signed-off-by: Giuseppe Maxia --- go.mod | 4 ++++ go.sum | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 9ac99d627..0eb4d4bb5 100644 --- a/go.mod +++ b/go.mod @@ -59,3 +59,7 @@ require ( google.golang.org/grpc v1.50.1 // indirect google.golang.org/protobuf v1.28.1 // indirect ) + +replace github.com/vmware/go-vcloud-director/v2 => github.com/dataclouder/go-vcloud-director/v2 v2.17.0-alpha.3.0.20221201195234-f349169a26b6 + +// replace github.com/vmware/go-vcloud-director/v2 => ../go-vcloud-director diff --git a/go.sum b/go.sum index 363fb11f7..9ac6e5dd3 100644 --- a/go.sum +++ b/go.sum @@ -22,6 +22,8 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkY github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/dataclouder/go-vcloud-director/v2 v2.17.0-alpha.3.0.20221201195234-f349169a26b6 h1:rG5E9UKgJo63YATMitqtFwNbpNlfp3kFfZhNB89XyZw= +github.com/dataclouder/go-vcloud-director/v2 v2.17.0-alpha.3.0.20221201195234-f349169a26b6/go.mod h1:KjnB8t5l1bRrc+jLKDJbx0vZLRzz2RPzNQ7xzg7yI3o= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -178,8 +180,6 @@ github.com/vmihailenco/msgpack/v4 v4.3.12 h1:07s4sz9IReOgdikxLTKNbBdqDMLsjPKXwvC github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4= github.com/vmihailenco/tagparser v0.1.1 h1:quXMXlA39OCbd2wAdTsGDlK9RkOk6Wuw+x37wVyIuWY= github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI= -github.com/vmware/go-vcloud-director/v2 v2.17.0 h1:msrrtEKD7H/e3cNPaXlCkZf3TMzSSyH306EXettv0c8= -github.com/vmware/go-vcloud-director/v2 v2.17.0/go.mod h1:KjnB8t5l1bRrc+jLKDJbx0vZLRzz2RPzNQ7xzg7yI3o= 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/zclconf/go-cty v1.1.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLEih+O3s= From 56e3f674eaeaabc9ba16464ef15e756e78d467bf Mon Sep 17 00:00:00 2001 From: Giuseppe Maxia Date: Thu, 1 Dec 2022 22:22:09 +0100 Subject: [PATCH 05/16] Add changelog entry Signed-off-by: Giuseppe Maxia --- .changes/v3.8.1/949-bug-fixes.md | 1 + go.mod | 2 +- go.sum | 4 ++-- vcd/datasource_vcd_catalog.go | 9 ++++----- 4 files changed, 8 insertions(+), 8 deletions(-) create mode 100644 .changes/v3.8.1/949-bug-fixes.md diff --git a/.changes/v3.8.1/949-bug-fixes.md b/.changes/v3.8.1/949-bug-fixes.md new file mode 100644 index 000000000..3b4bb3863 --- /dev/null +++ b/.changes/v3.8.1/949-bug-fixes.md @@ -0,0 +1 @@ +* Fix issue #944 shared catalog datasource not working [GH-949] diff --git a/go.mod b/go.mod index 0eb4d4bb5..007f55c4c 100644 --- a/go.mod +++ b/go.mod @@ -60,6 +60,6 @@ require ( google.golang.org/protobuf v1.28.1 // indirect ) -replace github.com/vmware/go-vcloud-director/v2 => github.com/dataclouder/go-vcloud-director/v2 v2.17.0-alpha.3.0.20221201195234-f349169a26b6 +replace github.com/vmware/go-vcloud-director/v2 => github.com/dataclouder/go-vcloud-director/v2 v2.17.0-alpha.3.0.20221201211517-6f7a2228fc89 // replace github.com/vmware/go-vcloud-director/v2 => ../go-vcloud-director diff --git a/go.sum b/go.sum index 9ac6e5dd3..93158bcfb 100644 --- a/go.sum +++ b/go.sum @@ -22,8 +22,8 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkY github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -github.com/dataclouder/go-vcloud-director/v2 v2.17.0-alpha.3.0.20221201195234-f349169a26b6 h1:rG5E9UKgJo63YATMitqtFwNbpNlfp3kFfZhNB89XyZw= -github.com/dataclouder/go-vcloud-director/v2 v2.17.0-alpha.3.0.20221201195234-f349169a26b6/go.mod h1:KjnB8t5l1bRrc+jLKDJbx0vZLRzz2RPzNQ7xzg7yI3o= +github.com/dataclouder/go-vcloud-director/v2 v2.17.0-alpha.3.0.20221201211517-6f7a2228fc89 h1:2NZ2PQyQq7wXW4WjEsXL78D5ZCs6JNLCuT5UaDGi/ik= +github.com/dataclouder/go-vcloud-director/v2 v2.17.0-alpha.3.0.20221201211517-6f7a2228fc89/go.mod h1:KjnB8t5l1bRrc+jLKDJbx0vZLRzz2RPzNQ7xzg7yI3o= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/vcd/datasource_vcd_catalog.go b/vcd/datasource_vcd_catalog.go index 4184b3af5..c310706c5 100644 --- a/vcd/datasource_vcd_catalog.go +++ b/vcd/datasource_vcd_catalog.go @@ -3,7 +3,6 @@ package vcd import ( "context" "fmt" - "log" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/vmware/go-vcloud-director/v2/types/v56" @@ -167,7 +166,7 @@ func getCatalogFromResource(catalogName string, d *schema.ResourceData, meta int catalogRecords, err := vcdClient.VCDClient.Client.QueryCatalogRecords(catalogName) if err != nil { - return nil, fmt.Errorf("error retrieving catalog records for catalog %s", catalogName) + return nil, fmt.Errorf("[getCatalogFromResource] error retrieving catalog records for catalog %s: %s", catalogName, err) } var catalogRecord *types.CatalogRecord for _, cr := range catalogRecords { @@ -206,7 +205,7 @@ func datasourceVcdCatalogRead(_ context.Context, d *schema.ResourceData, meta in catalogOrgIsAvailable = false orgFound = "NOT" } - log.Printf("[TRACE] Org '%s' %s found", orgName, orgFound) + util.Logger.Printf("[TRACE] Org '%s' %s found", orgName, orgFound) identifier := d.Get("name").(string) @@ -222,8 +221,8 @@ func datasourceVcdCatalogRead(_ context.Context, d *schema.ResourceData, meta in catalog, err = getCatalogFromResource(identifier, d, meta) } if err != nil { - log.Printf("[DEBUG] Catalog %s not found. Setting ID to nothing", identifier) - return diag.Errorf("error retrieving catalog %s: %s", identifier, err) + util.Logger.Printf("[DEBUG] Catalog %s not found. Setting ID to nothing", identifier) + return diag.Errorf("[catalog read DS] error retrieving catalog %s: %s", identifier, err) } dSet(d, "description", catalog.AdminCatalog.Description) From c65f37562098957c9adf76de15ccdd5ed3e1149c Mon Sep 17 00:00:00 2001 From: Giuseppe Maxia Date: Thu, 1 Dec 2022 23:10:13 +0100 Subject: [PATCH 06/16] Add informative message for catalog not found Signed-off-by: Giuseppe Maxia --- vcd/datasource_vcd_catalog.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/vcd/datasource_vcd_catalog.go b/vcd/datasource_vcd_catalog.go index c310706c5..7be894c14 100644 --- a/vcd/datasource_vcd_catalog.go +++ b/vcd/datasource_vcd_catalog.go @@ -169,14 +169,20 @@ func getCatalogFromResource(catalogName string, d *schema.ResourceData, meta int return nil, fmt.Errorf("[getCatalogFromResource] error retrieving catalog records for catalog %s: %s", catalogName, err) } var catalogRecord *types.CatalogRecord + var orgNames []string for _, cr := range catalogRecords { + orgNames = append(orgNames, cr.OrgName) if cr.OrgName == orgName { catalogRecord = cr break } } if catalogRecord == nil { - return nil, fmt.Errorf("no records found for catalog '%s' from org '%s'", catalogName, orgName) + message := fmt.Sprintf("no records found for catalog '%s' from org '%s'", catalogName, orgName) + if len(orgNames) > 0 { + message = fmt.Sprintf("%s\nThere are catalogs with the same name from other orgs: %v", message, orgNames) + } + return nil, fmt.Errorf(message) } return vcdClient.VCDClient.Client.GetCatalogByHref(catalogRecord.HREF) } From aeebfd4413a9edee6afa7c2e4cf77fc817770f8e Mon Sep 17 00:00:00 2001 From: Giuseppe Maxia Date: Fri, 2 Dec 2022 08:08:16 +0100 Subject: [PATCH 07/16] Improve error checking Signed-off-by: Giuseppe Maxia --- go.mod | 4 ++-- go.sum | 4 ++-- vcd/datasource_vcd_catalog.go | 8 ++++++-- vcd/datasource_vcd_subscribed_catalog.go | 2 +- vcd/resource_vcd_catalog.go | 15 +++++++++------ vcd/resource_vcd_subscribed_catalog.go | 2 +- 6 files changed, 21 insertions(+), 14 deletions(-) diff --git a/go.mod b/go.mod index 007f55c4c..8564b58b7 100644 --- a/go.mod +++ b/go.mod @@ -60,6 +60,6 @@ require ( google.golang.org/protobuf v1.28.1 // indirect ) -replace github.com/vmware/go-vcloud-director/v2 => github.com/dataclouder/go-vcloud-director/v2 v2.17.0-alpha.3.0.20221201211517-6f7a2228fc89 +replace github.com/vmware/go-vcloud-director/v2 => github.com/dataclouder/go-vcloud-director/v2 v2.17.0-alpha.3.0.20221202070623-3d1e5ac6ea20 -// replace github.com/vmware/go-vcloud-director/v2 => ../go-vcloud-director +//replace github.com/vmware/go-vcloud-director/v2 => ../go-vcloud-director diff --git a/go.sum b/go.sum index 93158bcfb..a3706fbdd 100644 --- a/go.sum +++ b/go.sum @@ -22,8 +22,8 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkY github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -github.com/dataclouder/go-vcloud-director/v2 v2.17.0-alpha.3.0.20221201211517-6f7a2228fc89 h1:2NZ2PQyQq7wXW4WjEsXL78D5ZCs6JNLCuT5UaDGi/ik= -github.com/dataclouder/go-vcloud-director/v2 v2.17.0-alpha.3.0.20221201211517-6f7a2228fc89/go.mod h1:KjnB8t5l1bRrc+jLKDJbx0vZLRzz2RPzNQ7xzg7yI3o= +github.com/dataclouder/go-vcloud-director/v2 v2.17.0-alpha.3.0.20221202070623-3d1e5ac6ea20 h1:9q8DQBPyXQkgWEjuLBMP/rbovqhHuV1mrMcKVbLHODI= +github.com/dataclouder/go-vcloud-director/v2 v2.17.0-alpha.3.0.20221202070623-3d1e5ac6ea20/go.mod h1:KjnB8t5l1bRrc+jLKDJbx0vZLRzz2RPzNQ7xzg7yI3o= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/vcd/datasource_vcd_catalog.go b/vcd/datasource_vcd_catalog.go index 7be894c14..b890aa43d 100644 --- a/vcd/datasource_vcd_catalog.go +++ b/vcd/datasource_vcd_catalog.go @@ -164,7 +164,7 @@ func getCatalogFromResource(catalogName string, d *schema.ResourceData, meta int return nil, fmt.Errorf("'org' property not supplied in the resource or in provider") } - catalogRecords, err := vcdClient.VCDClient.Client.QueryCatalogRecords(catalogName) + catalogRecords, err := vcdClient.VCDClient.Client.QueryCatalogRecords(catalogName, govcd.TenantContext{}) if err != nil { return nil, fmt.Errorf("[getCatalogFromResource] error retrieving catalog records for catalog %s: %s", catalogName, err) } @@ -253,7 +253,11 @@ func datasourceVcdCatalogRead(_ context.Context, d *schema.ResourceData, meta in return diag.Errorf("There was an issue when setting metadata into the schema - %s", err) } - err = setCatalogData(d, vcdClient, orgName, catalog, "vcd_catalog") + orgId := "" + if adminOrg != nil { + orgId = adminOrg.AdminOrg.ID + } + err = setCatalogData(d, vcdClient, orgName, orgId, catalog, "vcd_catalog") if err != nil { return diag.FromErr(err) } diff --git a/vcd/datasource_vcd_subscribed_catalog.go b/vcd/datasource_vcd_subscribed_catalog.go index 090a668e8..33588a6a1 100644 --- a/vcd/datasource_vcd_subscribed_catalog.go +++ b/vcd/datasource_vcd_subscribed_catalog.go @@ -185,7 +185,7 @@ func datasourceVcdSubscribedCatalogRead(ctx context.Context, d *schema.ResourceD dSet(d, "subscription_url", adminCatalog.AdminCatalog.ExternalCatalogSubscription.Location) dSet(d, "make_local_copy", adminCatalog.AdminCatalog.ExternalCatalogSubscription.LocalCopy) - err = setCatalogData(d, vcdClient, adminOrg.AdminOrg.Name, adminCatalog, "vcd_subscribed_catalog") + err = setCatalogData(d, vcdClient, adminOrg.AdminOrg.Name, adminOrg.AdminOrg.ID, adminCatalog, "vcd_subscribed_catalog") if err != nil { return diag.Errorf("%v", err) } diff --git a/vcd/resource_vcd_catalog.go b/vcd/resource_vcd_catalog.go index 0058fe5c3..1b6d80879 100644 --- a/vcd/resource_vcd_catalog.go +++ b/vcd/resource_vcd_catalog.go @@ -7,7 +7,9 @@ import ( "sort" "strings" + "github.com/kr/pretty" "github.com/vmware/go-vcloud-director/v2/types/v56" + "github.com/vmware/go-vcloud-director/v2/util" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -294,7 +296,7 @@ func genericResourceVcdCatalogRead(d *schema.ResourceData, meta interface{}) err return err } - err = setCatalogData(d, vcdClient, adminOrg.AdminOrg.Name, adminCatalog, "vcd_catalog") + err = setCatalogData(d, vcdClient, adminOrg.AdminOrg.Name, adminOrg.AdminOrg.ID, adminCatalog, "vcd_catalog") if err != nil { return err } @@ -467,12 +469,12 @@ func resourceVcdCatalogImport(_ context.Context, d *schema.ResourceData, meta in return []*schema.ResourceData{d}, nil } -func setCatalogData(d *schema.ResourceData, vcdClient *VCDClient, orgName string, adminCatalog *govcd.AdminCatalog, resourceType string) error { +func setCatalogData(d *schema.ResourceData, vcdClient *VCDClient, orgName, orgId string, adminCatalog *govcd.AdminCatalog, resourceType string) error { // Catalog record is retrieved to get the owner name, number of vApp templates and medias, and if the catalog is shared and published - catalogRecords, err := vcdClient.VCDClient.Client.QueryCatalogRecords(adminCatalog.AdminCatalog.Name) + catalogRecords, err := vcdClient.VCDClient.Client.QueryCatalogRecords(adminCatalog.AdminCatalog.Name, govcd.TenantContext{OrgName: orgName, OrgId: orgId}) if err != nil { - log.Printf("[DEBUG] Unable to retrieve catalog records: %s", err) - return fmt.Errorf("unable to retrieve catalog records - %s", err) + log.Printf("[DEBUG] [setCatalogData] Unable to retrieve catalog records: %s", err) + return fmt.Errorf("[setCatalogData] unable to retrieve catalog records - %s", err) } var catalogRecord *types.CatalogRecord @@ -483,9 +485,10 @@ func setCatalogData(d *schema.ResourceData, vcdClient *VCDClient, orgName string } } if catalogRecord == nil { - return fmt.Errorf("error retrieving catalog record for catalog '%s' from org '%s'", adminCatalog.AdminCatalog.Name, orgName) + return fmt.Errorf("[setCatalogData] error retrieving catalog record for catalog '%s' from org '%s'", adminCatalog.AdminCatalog.Name, orgName) } + util.Logger.Printf("[setCatalogData] catalogRecord %# v\n", pretty.Formatter(catalogRecord)) dSet(d, "catalog_version", catalogRecord.Version) dSet(d, "owner_name", catalogRecord.OwnerName) dSet(d, "is_published", catalogRecord.IsPublished) diff --git a/vcd/resource_vcd_subscribed_catalog.go b/vcd/resource_vcd_subscribed_catalog.go index 6922ba006..e6d44d9b0 100644 --- a/vcd/resource_vcd_subscribed_catalog.go +++ b/vcd/resource_vcd_subscribed_catalog.go @@ -340,7 +340,7 @@ func resourceVcdSubscribedCatalogRead(ctx context.Context, d *schema.ResourceDat } dSet(d, "subscription_url", adminCatalog.AdminCatalog.ExternalCatalogSubscription.Location) dSet(d, "make_local_copy", adminCatalog.AdminCatalog.ExternalCatalogSubscription.LocalCopy) - err = setCatalogData(d, vcdClient, adminOrg.AdminOrg.Name, adminCatalog, "vcd_subscribed_catalog") + err = setCatalogData(d, vcdClient, adminOrg.AdminOrg.Name, adminOrg.AdminOrg.ID, adminCatalog, "vcd_subscribed_catalog") if err != nil { return diag.Errorf("%v", err) } From 01cfca41628b35e0c547ffeeed56b620f1f18f19 Mon Sep 17 00:00:00 2001 From: Giuseppe Maxia Date: Fri, 2 Dec 2022 08:27:53 +0100 Subject: [PATCH 08/16] Update getCatalogFromResource Improve search as system administrator Signed-off-by: Giuseppe Maxia --- vcd/datasource_vcd_catalog.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/vcd/datasource_vcd_catalog.go b/vcd/datasource_vcd_catalog.go index b890aa43d..3456ec646 100644 --- a/vcd/datasource_vcd_catalog.go +++ b/vcd/datasource_vcd_catalog.go @@ -164,7 +164,16 @@ func getCatalogFromResource(catalogName string, d *schema.ResourceData, meta int return nil, fmt.Errorf("'org' property not supplied in the resource or in provider") } - catalogRecords, err := vcdClient.VCDClient.Client.QueryCatalogRecords(catalogName, govcd.TenantContext{}) + tenantContext := govcd.TenantContext{} + if vcdClient.Client.IsSysAdmin { + org, err := vcdClient.GetAdminOrgByName(orgName) + if err != nil { + return nil, fmt.Errorf("[getCatalogFromResource] error retrieving org %s: %s", orgName, err) + } + tenantContext.OrgId = org.AdminOrg.ID + tenantContext.OrgName = orgName + } + catalogRecords, err := vcdClient.VCDClient.Client.QueryCatalogRecords(catalogName, tenantContext) if err != nil { return nil, fmt.Errorf("[getCatalogFromResource] error retrieving catalog records for catalog %s: %s", catalogName, err) } From 57ca83dd660ae007d0caf98023fcfc7853f688f3 Mon Sep 17 00:00:00 2001 From: Giuseppe Maxia Date: Fri, 2 Dec 2022 14:12:23 +0100 Subject: [PATCH 09/16] Add docs for new catalog field "is_local" Signed-off-by: Giuseppe Maxia --- website/docs/d/catalog.html.markdown | 1 + website/docs/d/subscribed_catalog.html.markdown | 1 + website/docs/r/catalog.html.markdown | 1 + website/docs/r/subscribed_catalog.html.markdown | 1 + 4 files changed, 4 insertions(+) diff --git a/website/docs/d/catalog.html.markdown b/website/docs/d/catalog.html.markdown index a08a07429..9c50fe6bb 100644 --- a/website/docs/d/catalog.html.markdown +++ b/website/docs/d/catalog.html.markdown @@ -56,6 +56,7 @@ The following arguments are supported: * `media_item_list` - (*v3.8+*) List of media item names in this catalog, in alphabetical order. * `is_shared` - (*v3.6+*) Indicates if the catalog is shared. * `is_published` - (*v3.6+*) Indicates if this catalog is shared to all organizations. +* `is_local` - (*v3.8.1+*) Indicates if this catalog was created in the current organization. * `created` - (*v3.6+*) Date and time of catalog creation * `publish_subscription_type` - (*v3.6+*) Shows if the catalog is `PUBLISHED`, if it is a subscription from another one (`SUBSCRIBED`), or none of those (`UNPUBLISHED`). * `publish_subscription_url` - (*v3.8+*) URL to which other catalogs can subscribe. diff --git a/website/docs/d/subscribed_catalog.html.markdown b/website/docs/d/subscribed_catalog.html.markdown index 81ea6b60b..fddffcb66 100644 --- a/website/docs/d/subscribed_catalog.html.markdown +++ b/website/docs/d/subscribed_catalog.html.markdown @@ -46,6 +46,7 @@ The following arguments are supported: * `media_item_list` List of media item names in this catalog, in alphabetical order. * `is_shared` - Indicates if the catalog is shared (`true` or `false`). * `is_published` - Indicates if this catalog is available for subscription. (Always return `false` for this data source) +* `is_local` - (*v3.8.1+*) Indicates if this catalog was created in the current organization. * `publish_subscription_type` - Shows if the catalog is published, if it is a subscription from another one or none of those. (Always returns `SUBSCRIBED` for this data source) * `href` - the catalog's Hyper reference. * `created` - Date and time of catalog creation. diff --git a/website/docs/r/catalog.html.markdown b/website/docs/r/catalog.html.markdown index 9849ab902..c6dcae154 100644 --- a/website/docs/r/catalog.html.markdown +++ b/website/docs/r/catalog.html.markdown @@ -75,6 +75,7 @@ source [vcd_storage_profile](/providers/vmware/vcd/latest/docs/data-sources/stor * `number_of_media` - (*v3.6+*) Number of media items available in this catalog. * `is_shared` - (*v3.6+*) Indicates if the catalog is shared. * `is_published` - (*v3.6+*) Indicates if this catalog is shared to all organizations. +* `is_local` - (*v3.8.1+*) Indicates if this catalog was created in the current organization. * `created` - (*v3.6+*) Date and time of catalog creation * `publish_subscription_type` - (*v3.6+*) Shows if the catalog is `PUBLISHED`, if it is a subscription from another one (`SUBSCRIBED`), or none of those (`UNPUBLISHED`). * `publish_subscription_url` - (*v3.8+*) URL to which other catalogs can subscribe. diff --git a/website/docs/r/subscribed_catalog.html.markdown b/website/docs/r/subscribed_catalog.html.markdown index 12d777ad4..d4708c6f3 100644 --- a/website/docs/r/subscribed_catalog.html.markdown +++ b/website/docs/r/subscribed_catalog.html.markdown @@ -92,6 +92,7 @@ The following arguments are supported: * `media_item_list` List of media item names in this catalog, in alphabetical order. * `is_shared` - Indicates if the catalog is shared. * `is_published` - Indicates if this catalog is available for subscription. (Always false) +* `is_local` - (*v3.8.1+*) Indicates if this catalog was created in the current organization. * `publish_subscription_type` - Shows if the catalog is published, if it is a subscription from another one or none of those. (Always `SUBSCRIBED`) * `href` - the catalog's Hyper reference. * `created` - Date and time of catalog creation. This is the creation date of the subscription, not the original published catalog. From 5e8c42111175f0982d7ef536c5d14203c101dd95 Mon Sep 17 00:00:00 2001 From: Giuseppe Maxia Date: Fri, 2 Dec 2022 19:36:10 +0100 Subject: [PATCH 10/16] Remove unnecessary function getOrgName Signed-off-by: Giuseppe Maxia --- vcd/datasource_vcd_catalog.go | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/vcd/datasource_vcd_catalog.go b/vcd/datasource_vcd_catalog.go index 3456ec646..01d84a99f 100644 --- a/vcd/datasource_vcd_catalog.go +++ b/vcd/datasource_vcd_catalog.go @@ -148,20 +148,12 @@ func datasourceVcdCatalog() *schema.Resource { } } -func getOrgName(vcdClient *VCDClient, d *schema.ResourceData) string { - orgName := d.Get("org").(string) - if orgName == "" { - orgName = vcdClient.Org - } - return orgName -} - func getCatalogFromResource(catalogName string, d *schema.ResourceData, meta interface{}) (*govcd.AdminCatalog, error) { vcdClient := meta.(*VCDClient) - orgName := getOrgName(vcdClient, d) - if orgName == "" { - return nil, fmt.Errorf("'org' property not supplied in the resource or in provider") + orgName, err := vcdClient.GetOrgNameFromResource(d) + if err != nil { + return nil, fmt.Errorf("'org' property not supplied in the resource or in provider: %s", err) } tenantContext := govcd.TenantContext{} @@ -208,9 +200,9 @@ func datasourceVcdCatalogRead(_ context.Context, d *schema.ResourceData, meta in return diag.Errorf(noNameOrFilterError, "vcd_catalog") } - orgName := getOrgName(vcdClient, d) - if orgName == "" { - return diag.Errorf("'org' property not supplied in the resource or in provider") + orgName, err := vcdClient.GetOrgNameFromResource(d) + if err != nil { + return diag.Errorf("'org' property not supplied in the resource or in provider: %s", err) } adminOrg, orgErr := vcdClient.GetAdminOrgFromResource(d) From 7155beb2648904688d7afdbeb20cf056d686a00c Mon Sep 17 00:00:00 2001 From: Giuseppe Maxia Date: Sun, 4 Dec 2022 17:48:02 +0100 Subject: [PATCH 11/16] Return right error message when catalog DS not found Signed-off-by: Giuseppe Maxia --- vcd/datasource_vcd_catalog.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vcd/datasource_vcd_catalog.go b/vcd/datasource_vcd_catalog.go index 01d84a99f..2ab417c89 100644 --- a/vcd/datasource_vcd_catalog.go +++ b/vcd/datasource_vcd_catalog.go @@ -228,8 +228,7 @@ func datasourceVcdCatalogRead(_ context.Context, d *schema.ResourceData, meta in catalog, err = getCatalogFromResource(identifier, d, meta) } if err != nil { - util.Logger.Printf("[DEBUG] Catalog %s not found. Setting ID to nothing", identifier) - return diag.Errorf("[catalog read DS] error retrieving catalog %s: %s", identifier, err) + return diag.Errorf("[catalog read DS] error retrieving catalog %s: %s - %s", identifier, govcd.ErrorEntityNotFound, err) } dSet(d, "description", catalog.AdminCatalog.Description) From c192752b47172d3aa0ecc4d9f5bdf9399dabbf8a Mon Sep 17 00:00:00 2001 From: Giuseppe Maxia Date: Mon, 5 Dec 2022 10:53:04 +0100 Subject: [PATCH 12/16] Update docs Signed-off-by: Giuseppe Maxia --- website/docs/index.html.markdown | 2 +- website/docs/r/catalog.html.markdown | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/website/docs/index.html.markdown b/website/docs/index.html.markdown index 1e0f9be70..e62787f40 100644 --- a/website/docs/index.html.markdown +++ b/website/docs/index.html.markdown @@ -23,7 +23,7 @@ When upgrading the provider please check for such labels for the resources you a The following Cloud Director versions are supported by this provider: * 10.3 -* 10.4.1 +* 10.4 Also Cloud Director Service (CDS) is supported. diff --git a/website/docs/r/catalog.html.markdown b/website/docs/r/catalog.html.markdown index c6dcae154..35fd8e801 100644 --- a/website/docs/r/catalog.html.markdown +++ b/website/docs/r/catalog.html.markdown @@ -51,7 +51,9 @@ resource "vcd_catalog" "myNewCatalog" { The following arguments are supported: -* `org` - (Optional) The name of organization to use, optional if defined at provider level. Useful when connected as sysadmin working across different organisations +* `org` - (Optional) The name of organization to use, optional if defined at provider level. Useful when connected as sysadmin working across different organizations. + When using a catalog shared from another organization, this field must have the name of that one, not the current one. + If you don't know the name of the sharing org, and put the current one, an error message will list the possible names. * `name` - (Required) Catalog name * `description` - (Optional) Description of catalog * `storage_profile_id` - (Optional, *v3.1+*) Allows to set specific storage profile to be used for catalog. **Note.** Data From 5a4f3183713220ecd35e067265fda21e6446cc44 Mon Sep 17 00:00:00 2001 From: Giuseppe Maxia Date: Mon, 5 Dec 2022 11:50:27 +0100 Subject: [PATCH 13/16] Update go.mod Signed-off-by: Giuseppe Maxia --- go.mod | 6 +----- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 8564b58b7..539456ec1 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/hashicorp/go-version v1.6.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1 github.com/kr/pretty v0.2.1 - github.com/vmware/go-vcloud-director/v2 v2.17.0 + github.com/vmware/go-vcloud-director/v2 v2.17.1-0.20221205101510-d9d568efdf11 ) require ( @@ -59,7 +59,3 @@ require ( google.golang.org/grpc v1.50.1 // indirect google.golang.org/protobuf v1.28.1 // indirect ) - -replace github.com/vmware/go-vcloud-director/v2 => github.com/dataclouder/go-vcloud-director/v2 v2.17.0-alpha.3.0.20221202070623-3d1e5ac6ea20 - -//replace github.com/vmware/go-vcloud-director/v2 => ../go-vcloud-director diff --git a/go.sum b/go.sum index a3706fbdd..f6799801e 100644 --- a/go.sum +++ b/go.sum @@ -22,8 +22,6 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkY github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -github.com/dataclouder/go-vcloud-director/v2 v2.17.0-alpha.3.0.20221202070623-3d1e5ac6ea20 h1:9q8DQBPyXQkgWEjuLBMP/rbovqhHuV1mrMcKVbLHODI= -github.com/dataclouder/go-vcloud-director/v2 v2.17.0-alpha.3.0.20221202070623-3d1e5ac6ea20/go.mod h1:KjnB8t5l1bRrc+jLKDJbx0vZLRzz2RPzNQ7xzg7yI3o= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -180,6 +178,8 @@ github.com/vmihailenco/msgpack/v4 v4.3.12 h1:07s4sz9IReOgdikxLTKNbBdqDMLsjPKXwvC github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4= github.com/vmihailenco/tagparser v0.1.1 h1:quXMXlA39OCbd2wAdTsGDlK9RkOk6Wuw+x37wVyIuWY= github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI= +github.com/vmware/go-vcloud-director/v2 v2.17.1-0.20221205101510-d9d568efdf11 h1:J4PtMISIqbMHekCvgs8pfwYcAKFdq6DyNssREDYd5PE= +github.com/vmware/go-vcloud-director/v2 v2.17.1-0.20221205101510-d9d568efdf11/go.mod h1:KjnB8t5l1bRrc+jLKDJbx0vZLRzz2RPzNQ7xzg7yI3o= 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/zclconf/go-cty v1.1.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLEih+O3s= From 69e4f082954c32e92fcdd418993fc4e18ba637b8 Mon Sep 17 00:00:00 2001 From: Giuseppe Maxia Date: Mon, 5 Dec 2022 12:49:16 +0100 Subject: [PATCH 14/16] Update error message Signed-off-by: Giuseppe Maxia --- vcd/datasource_vcd_catalog.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vcd/datasource_vcd_catalog.go b/vcd/datasource_vcd_catalog.go index 2ab417c89..6d8147bb3 100644 --- a/vcd/datasource_vcd_catalog.go +++ b/vcd/datasource_vcd_catalog.go @@ -179,9 +179,9 @@ func getCatalogFromResource(catalogName string, d *schema.ResourceData, meta int } } if catalogRecord == nil { - message := fmt.Sprintf("no records found for catalog '%s' from org '%s'", catalogName, orgName) + message := fmt.Sprintf("no records found for catalog '%s' in org '%s'", catalogName, orgName) if len(orgNames) > 0 { - message = fmt.Sprintf("%s\nThere are catalogs with the same name from other orgs: %v", message, orgNames) + message = fmt.Sprintf("%s\nThere are catalogs with the same name in other orgs: %v", message, orgNames) } return nil, fmt.Errorf(message) } From 8f7ade2749710f5a7df3356e5c902a4fcd268108 Mon Sep 17 00:00:00 2001 From: Giuseppe Maxia Date: Mon, 5 Dec 2022 12:55:20 +0100 Subject: [PATCH 15/16] Update changelog item Signed-off-by: Giuseppe Maxia --- .changes/v3.8.1/949-bug-fixes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changes/v3.8.1/949-bug-fixes.md b/.changes/v3.8.1/949-bug-fixes.md index 3b4bb3863..02cd651a2 100644 --- a/.changes/v3.8.1/949-bug-fixes.md +++ b/.changes/v3.8.1/949-bug-fixes.md @@ -1 +1 @@ -* Fix issue #944 shared catalog datasource not working [GH-949] +* Fix issue #944 shared catalog datasource not accessible to org users [GH-949] From fd38e1f7a4d1c3485f0a149917ebf67902f6a6aa Mon Sep 17 00:00:00 2001 From: Giuseppe Maxia Date: Mon, 5 Dec 2022 13:25:07 +0100 Subject: [PATCH 16/16] Add chengelog item Signed-off-by: Giuseppe Maxia --- .changes/v3.8.1/949-improvements.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .changes/v3.8.1/949-improvements.md diff --git a/.changes/v3.8.1/949-improvements.md b/.changes/v3.8.1/949-improvements.md new file mode 100644 index 000000000..c00f7fceb --- /dev/null +++ b/.changes/v3.8.1/949-improvements.md @@ -0,0 +1,2 @@ +* Resource and data source `vcd_catalog` and `vcd_subscribed_catalog` introduce new computed field `is_local` to specify + whether the catalog originated from the current org [GH-949] \ No newline at end of file