Skip to content

Commit fc7fa66

Browse files
committed
Add a few new catalog item resources and datasources
* Add vra_catalog_item_vm_image resource and datasource * Add vra_catalog_item_vro_workflow resource and datasource Signed-off-by: Ferran Rodenas <[email protected]>
1 parent 4290bcb commit fc7fa66

10 files changed

+631
-43
lines changed

docs/data-sources/vra_catalog_item.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,19 @@ data "vra_catalog_item" "this" {
4141

4242
## Attribute Reference
4343

44-
* `created_at` - Date-time when the entity was created.
44+
* `created_at` - Date when the entity was created. The date is in ISO 8601 and UTC.
4545

4646
* `created_by` - The user the entity was created by.
4747

48-
* `description` - Catalog item description.
48+
* `description` - A human-friendly description for the catalog item.
4949

50-
* `form_id` - Form ID.
50+
* `form_id` - ID of the form associated with this catalog item.
5151

52-
* `icon_id` - Icon ID.
52+
* `global` - Whether to allow this catalog to be shared with multiple projects or to restrict it to the specified project.
5353

54-
* `last_updated_at` - Date-time when the entity was last updated.
54+
* `icon_id` - ID of the icon associated with this catalog item.
55+
56+
* `last_updated_at` - Date when the entity was last updated. The date is ISO 8601 and UTC.
5557

5658
* `last_updated_by` - The user the entity was last updated by.
5759

@@ -73,6 +75,8 @@ data "vra_catalog_item" "this" {
7375

7476
* `source_name` - LibraryItem source name.
7577

78+
* `source_project_id` - Project ID with which the catalog item was associated when created.
79+
7680
* `type` -
7781

7882
* `description` - A human friendly description.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
page_title: "VMware Aria Automation: vra_catalog_item_vm_image"
3+
description: A resource for VM Image Catalog Items.
4+
---
5+
6+
# Resource: vra_catalog_item_vm_image
7+
8+
Creates a Catalog Item resource from a VM Image.
9+
10+
## Example Usages
11+
12+
The following example shows how to create a catalog item resource from a VM image:
13+
14+
```hcl
15+
resource "vra_catalog_item_vm_image" "catalog_item_vm_image" {
16+
name = "terraform-vm-image"
17+
description = "Catalog Item [terraform-vm-image] created by Terraform"
18+
project_id = var.project_id
19+
20+
image_name = var.image_name
21+
cloud_config = "#cloud-config\n# Sample cloud-config creating an admin user. Items in {{}} will appear as user inputs when deploying the VM.\nusers:\n - name: {{user_name}}\n plain_text_passwd: {{password}}\n lock_passwd: false\n sudo:\n - ALL=(ALL) NOPASSWD:ALL\n groups: sudo"
22+
}
23+
```
24+
25+
## Argument Reference
26+
27+
Create your resource with the following arguments:
28+
29+
* `cloud_config` - (Optional) Cloud config script to be applied to VMs provisioned from this image.
30+
31+
* `description` - (Optional) A human-friendly description for the catalog item.
32+
33+
* `global` - (Optional) Whether to allow this catalog to be shared with multiple projects or to restrict it to the specified project.
34+
35+
* `icon_id` - (Optional) ID of the icon to associate with this catalog item.
36+
37+
* `image_name` - (Required) Name of the VM image to publish.
38+
39+
* `name` - (Required) The name of the catalog item.
40+
41+
* `project_id` - (Required) ID of the project to share this catalog item with.
42+
43+
* `select_zone` - (Optional) Whether to create a zone input for the published catalog item.
44+
45+
## Attribute Reference
46+
47+
In addition to all arguments above, the following attributes are exported:
48+
49+
* `created_at` - Date when the entity was created. The date is in ISO 8601 and UTC.
50+
51+
* `created_by` - The user the entity was created by.
52+
53+
* `last_updated_at` - Date when the entity was last updated. The date is ISO 8601 and UTC.
54+
55+
* `last_updated_by` - The user the entity was last updated by.
56+
57+
## Import
58+
59+
To import an existing Catalog Item, use the `id` as in the following example:
60+
61+
`$ terraform import vra_catalog_item_vm_image.catalog_item_vm_image "b580ef9f-f191-4de2-b6f4-96f29d8c8d3d"`
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
page_title: "VMware Aria Automation: vra_catalog_item_vro_workflow"
3+
description: A resource for vRO Workflow Catalog Items.
4+
---
5+
6+
# Resource: vra_catalog_item_vro_workflow
7+
8+
Creates a Catalog Item resource from a vRO Workflow.
9+
10+
## Example Usages
11+
12+
The following example shows how to create a catalog item resource from a vRO Workflow:
13+
14+
```hcl
15+
resource "vra_catalog_item_vro_workflow" "catalog_item_vro_workflow" {
16+
name = "terraform-vro-workflow"
17+
description = "Catalog Item [terraform-vro-workflow] created by Terraform"
18+
project_id = var.project_id
19+
20+
workflow_id = var.workflow_id
21+
}
22+
```
23+
24+
## Argument Reference
25+
26+
Create your resource with the following arguments:
27+
28+
* `description` - (Optional) A human-friendly description for the catalog item.
29+
30+
* `global` - (Optional) Whether to allow this catalog to be shared with multiple projects or to restrict it to the specified project.
31+
32+
* `icon_id` - (Optional) ID of the icon to associate with this catalog item.
33+
34+
* `name` - (Required) The name of the catalog item.
35+
36+
* `project_id` - (Required) ID of the project to share this catalog item with.
37+
38+
* `workflow_id` - (Required) ID of the vRO workflow to publish.
39+
40+
## Attribute Reference
41+
42+
In addition to all arguments above, the following attributes are exported:
43+
44+
* `created_at` - Date when the entity was created. The date is in ISO 8601 and UTC.
45+
46+
* `created_by` - The user the entity was created by.
47+
48+
* `last_updated_at` - Date when the entity was last updated. The date is ISO 8601 and UTC.
49+
50+
* `last_updated_by` - The user the entity was last updated by.
51+
52+
## Import
53+
54+
To import an existing Catalog Item, use the `id` as in the following example:
55+
56+
`$ terraform import vra_catalog_item_vro_workflow.catalog_item_vro_workflow "a090b0c2-5b49-4fb5-9e69-c1b84b01c908"`

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/hashicorp/go-version v1.7.0
1010
github.com/hashicorp/terraform-plugin-sdk/v2 v2.36.1
1111
github.com/hashicorp/terraform-plugin-testing v1.12.0
12-
github.com/vmware/vra-sdk-go v0.6.3
12+
github.com/vmware/vra-sdk-go v0.6.4
1313
)
1414

1515
require (
@@ -74,7 +74,7 @@ require (
7474
golang.org/x/crypto v0.36.0 // indirect
7575
golang.org/x/mod v0.22.0 // indirect
7676
golang.org/x/net v0.38.0 // indirect
77-
golang.org/x/sync v0.13.0 // indirect
77+
golang.org/x/sync v0.14.0 // indirect
7878
golang.org/x/sys v0.31.0 // indirect
7979
golang.org/x/text v0.23.0 // indirect
8080
golang.org/x/tools v0.25.0 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IU
283283
github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok=
284284
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
285285
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
286-
github.com/vmware/vra-sdk-go v0.6.3 h1:Ppzt8jNEoGJbrSyK4NfY5fzi23xDSNM1ybRXgoOWHJQ=
287-
github.com/vmware/vra-sdk-go v0.6.3/go.mod h1:gUj5Z/+qvXEDk9+0NvW0ynDrMkTk3P5Bdt2JfN+AAC8=
286+
github.com/vmware/vra-sdk-go v0.6.4 h1:uXXQA+dvDvP/WH3rEFoc5rpiWNuTw9IECu7w07qiHsc=
287+
github.com/vmware/vra-sdk-go v0.6.4/go.mod h1:gUj5Z/+qvXEDk9+0NvW0ynDrMkTk3P5Bdt2JfN+AAC8=
288288
github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=
289289
github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw=
290290
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
@@ -346,8 +346,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
346346
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
347347
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
348348
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
349-
golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610=
350-
golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
349+
golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ=
350+
golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
351351
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
352352
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
353353
golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

vra/catalog_item_helper.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// © Broadcom. All Rights Reserved.
2+
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
3+
// SPDX-License-Identifier: MPL-2.0
4+
5+
package vra
6+
7+
import "encoding/json"
8+
9+
const (
10+
CatalogItemVMImageTypeID string = "com.vmw.vmimage"
11+
CatalogItemVroWorkflowTypeID string = "com.vmw.vro.workflow"
12+
)
13+
14+
type CatalogItemVMImagePublishSpec struct {
15+
CloudConfig *string `json:"cloudConfig,omitempty"`
16+
ImageName string `json:"imageName"`
17+
SelectZone *bool `json:"selectZone,omitempty"`
18+
}
19+
20+
type CatalogItemVroWorkflowPublishSpec struct {
21+
WorkflowID string `json:"workflowId"`
22+
}
23+
24+
func catalogItemSpecConvert(genericSpec any, castedSpec any) error {
25+
specJSON, err := json.Marshal(genericSpec)
26+
if err != nil {
27+
return err
28+
}
29+
30+
if err := json.Unmarshal(specJSON, &castedSpec); err != nil {
31+
return err
32+
}
33+
34+
return nil
35+
}

vra/data_source_catalog_item.go

Lines changed: 47 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,24 @@ func dataSourceCatalogItem() *schema.Resource {
1818
Read: dataSourceCatalogItemRead,
1919

2020
Schema: map[string]*schema.Schema{
21-
"created_at": {
22-
Type: schema.TypeString,
23-
Computed: true,
24-
Description: "Date-time when the entity was created.",
21+
"id": {
22+
Type: schema.TypeString,
23+
Computed: true,
24+
ConflictsWith: []string{"name"},
25+
Description: "The id of catalog item.",
26+
Optional: true,
2527
},
26-
"created_by": {
27-
Type: schema.TypeString,
28-
Computed: true,
29-
Description: "The user the entity was created by.",
28+
"name": {
29+
Type: schema.TypeString,
30+
Computed: true,
31+
ConflictsWith: []string{"id"},
32+
Description: "The name of the catalog item.",
33+
Optional: true,
3034
},
31-
"description": {
35+
"project_id": {
3236
Type: schema.TypeString,
33-
Computed: true,
34-
Description: "Catalog item description.",
37+
Optional: true,
38+
Description: "The id of the project to narrow the search while looking for catalog items.",
3539
},
3640
"expand_projects": {
3741
Type: schema.TypeBool,
@@ -43,42 +47,46 @@ func dataSourceCatalogItem() *schema.Resource {
4347
Optional: true,
4448
Description: "Flag to indicate whether to expand detailed versions of the catalog item.",
4549
},
46-
"form_id": {
50+
51+
"created_at": {
4752
Type: schema.TypeString,
4853
Computed: true,
49-
Description: "Form ID.",
54+
Description: "Date when the entity was created. The date is in ISO 8601 and UTC.",
5055
},
51-
"icon_id": {
56+
"created_by": {
5257
Type: schema.TypeString,
5358
Computed: true,
54-
Description: "Icon ID.",
59+
Description: "The user the entity was created by.",
5560
},
56-
"id": {
61+
"description": {
5762
Type: schema.TypeString,
58-
Optional: true,
5963
Computed: true,
60-
Description: "The id of catalog item. One of `id` or `name` must be provided.",
64+
Description: "A human-friendly description for the catalog item.",
6165
},
62-
"last_updated_at": {
66+
"form_id": {
6367
Type: schema.TypeString,
6468
Computed: true,
65-
Description: "Date-time when the entity was last updated.",
69+
Description: "ID of the form associated with this catalog item.",
6670
},
67-
"last_updated_by": {
71+
"global": {
72+
Type: schema.TypeBool,
73+
Computed: true,
74+
Description: "Whether to allow this catalog to be shared with multiple projects or to restrict it to the specified project.",
75+
},
76+
"icon_id": {
6877
Type: schema.TypeString,
6978
Computed: true,
70-
Description: "The user the entity was last updated by.",
79+
Description: "ID of the icon associated with this catalog item.",
7180
},
72-
"name": {
81+
"last_updated_at": {
7382
Type: schema.TypeString,
74-
Optional: true,
7583
Computed: true,
76-
Description: "The name of the catalog item. One of `id` or `name` must be provided.",
84+
Description: "Date when the entity was last updated. The date is ISO 8601 and UTC.",
7785
},
78-
"project_id": {
86+
"last_updated_by": {
7987
Type: schema.TypeString,
80-
Optional: true,
81-
Description: "The id of the project to narrow the search while looking for catalog items.",
88+
Computed: true,
89+
Description: "The user the entity was last updated by.",
8290
},
8391
"project_ids": {
8492
Type: schema.TypeSet,
@@ -104,6 +112,11 @@ func dataSourceCatalogItem() *schema.Resource {
104112
Computed: true,
105113
Description: "LibraryItem source name.",
106114
},
115+
"source_project_id": {
116+
Type: schema.TypeString,
117+
Computed: true,
118+
Description: "Project ID with which the catalog item was associated when created.",
119+
},
107120
"type": resourceReferenceSchema(),
108121
"versions": catalogItemVersionSchema(),
109122
},
@@ -118,7 +131,7 @@ func dataSourceCatalogItemRead(d *schema.ResourceData, meta interface{}) error {
118131
expandProjects := d.Get("expand_projects").(bool)
119132

120133
if !idOk && !nameOk {
121-
return fmt.Errorf("one of id or name is required")
134+
return fmt.Errorf("one of `id` or `name` is required")
122135
}
123136

124137
if !idOk {
@@ -148,7 +161,7 @@ func dataSourceCatalogItemRead(d *schema.ResourceData, meta interface{}) error {
148161
if err != nil {
149162
switch err.(type) {
150163
case *catalog_items.GetCatalogItemUsingGET5NotFound:
151-
return fmt.Errorf("catalog item '%s' not found", id)
164+
return fmt.Errorf("catalog item `%s` not found", id)
152165
default:
153166
// nop
154167
}
@@ -158,12 +171,13 @@ func dataSourceCatalogItemRead(d *schema.ResourceData, meta interface{}) error {
158171
catalogItem := getResp.GetPayload()
159172

160173
d.SetId(catalogItem.ID.String())
161-
d.Set("created_at", catalogItem.CreatedAt)
174+
d.Set("created_at", catalogItem.CreatedAt.String())
162175
d.Set("created_by", catalogItem.CreatedBy)
163176
d.Set("description", catalogItem.Description)
164177
d.Set("form_id", catalogItem.FormID)
178+
d.Set("global", catalogItem.Global)
165179
d.Set("icon_id", catalogItem.IconID)
166-
d.Set("last_updated_at", catalogItem.LastUpdatedAt)
180+
d.Set("last_updated_at", catalogItem.LastUpdatedAt.String())
167181
d.Set("last_updated_by", catalogItem.LastUpdatedBy)
168182
d.Set("name", catalogItem.Name)
169183
d.Set("project_ids", catalogItem.ProjectIds)
@@ -172,6 +186,7 @@ func dataSourceCatalogItemRead(d *schema.ResourceData, meta interface{}) error {
172186
d.Set("schema", string(schemaJSON))
173187
d.Set("source_id", catalogItem.SourceID.String())
174188
d.Set("source_name", catalogItem.SourceName)
189+
d.Set("source_project_id", catalogItem.SourceProjectID)
175190
d.Set("type", flattenResourceReference(catalogItem.Type))
176191

177192
if d.Get("expand_versions").(bool) {

vra/provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ func Provider() *schema.Provider {
141141
"vra_blueprint": resourceBlueprint(),
142142
"vra_blueprint_version": resourceBlueprintVersion(),
143143
"vra_catalog_item_entitlement": resourceCatalogItemEntitlement(),
144+
"vra_catalog_item_vm_image": resourceCatalogItemVMImage(),
145+
"vra_catalog_item_vro_workflow": resourceCatalogItemVroWorkflow(),
144146
"vra_catalog_source_blueprint": resourceCatalogSourceBlueprint(),
145147
"vra_catalog_source_entitlement": resourceCatalogSourceEntitlement(),
146148
"vra_cloud_account_aws": resourceCloudAccountAWS(),

0 commit comments

Comments
 (0)