Skip to content

Commit eba778a

Browse files
committed
Add fabric_compute resource
Signed-off-by: Ferran Rodenas <[email protected]>
1 parent ae4e4ad commit eba778a

File tree

4 files changed

+298
-0
lines changed

4 files changed

+298
-0
lines changed

vra/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ func Provider() *schema.Provider {
104104
"vra_cloud_account_vsphere": resourceCloudAccountVsphere(),
105105
"vra_content_source": resourceContentSource(),
106106
"vra_deployment": resourceDeployment(),
107+
"vra_fabric_compute": resourceFabricCompute(),
107108
"vra_fabric_network_vsphere": resourceFabricNetworkVsphere(),
108109
"vra_flavor_profile": resourceFlavorProfile(),
109110
"vra_image_profile": resourceImageProfile(),

vra/resource_fabric_compute.go

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
package vra
2+
3+
import (
4+
"context"
5+
"errors"
6+
7+
"github.com/vmware/vra-sdk-go/pkg/client/fabric_compute"
8+
"github.com/vmware/vra-sdk-go/pkg/models"
9+
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
11+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
12+
)
13+
14+
func resourceFabricCompute() *schema.Resource {
15+
return &schema.Resource{
16+
CreateContext: resourceFabricComputeCreate,
17+
ReadContext: resourceFabricComputeRead,
18+
UpdateContext: resourceFabricComputeUpdate,
19+
DeleteContext: resourceFabricComputeDelete,
20+
Importer: &schema.ResourceImporter{
21+
StateContext: schema.ImportStatePassthroughContext,
22+
},
23+
24+
Schema: map[string]*schema.Schema{
25+
"created_at": {
26+
Type: schema.TypeString,
27+
Computed: true,
28+
Description: "Date when the entity was created. The date is in ISO 8601 and UTC.",
29+
},
30+
"custom_properties": {
31+
Type: schema.TypeMap,
32+
Computed: true,
33+
Description: "A list of key value pair of custom properties for the fabric compute resource.",
34+
},
35+
"description": {
36+
Type: schema.TypeString,
37+
Computed: true,
38+
Description: "A human-friendly description.",
39+
},
40+
"external_id": {
41+
Type: schema.TypeString,
42+
Computed: true,
43+
Description: "The id of the external entity on the provider side.",
44+
},
45+
"external_region_id": {
46+
Type: schema.TypeString,
47+
Computed: true,
48+
Description: "The external region id of the fabric compute.",
49+
},
50+
"external_zone_id": {
51+
Type: schema.TypeString,
52+
Computed: true,
53+
Description: "The external zone id of the fabric compute.",
54+
},
55+
"lifecycle_state": {
56+
Type: schema.TypeString,
57+
Computed: true,
58+
Description: "Lifecycle status of the compute instance.",
59+
},
60+
"links": linksSchema(),
61+
"name": {
62+
Type: schema.TypeString,
63+
Computed: true,
64+
Description: "A human-friendly name used as an identifier for the fabric compute resource instance.",
65+
},
66+
"org_id": {
67+
Type: schema.TypeString,
68+
Computed: true,
69+
Description: "The id of the organization this entity belongs to.",
70+
},
71+
"owner": {
72+
Type: schema.TypeString,
73+
Computed: true,
74+
Description: "Email of the user that owns the entity.",
75+
},
76+
"power_state": {
77+
Type: schema.TypeString,
78+
Computed: true,
79+
Description: "Power state of fabric compute instance.",
80+
},
81+
"tags": tagsSchema(),
82+
"type": {
83+
Type: schema.TypeString,
84+
Computed: true,
85+
Description: "Type of the fabric compute instance.",
86+
},
87+
"updated_at": {
88+
Type: schema.TypeString,
89+
Computed: true,
90+
Description: "Date when the entity was last updated. The date is ISO 8601 and UTC.",
91+
},
92+
},
93+
}
94+
}
95+
96+
func resourceFabricComputeCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
97+
return diag.FromErr(errors.New("vra_fabric_compute resources are only importable"))
98+
}
99+
100+
func resourceFabricComputeRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
101+
apiClient := m.(*Client).apiClient
102+
103+
id := d.Id()
104+
105+
getResp, err := apiClient.FabricCompute.GetFabricCompute(fabric_compute.NewGetFabricComputeParams().WithID(id))
106+
if err != nil {
107+
switch err.(type) {
108+
case *fabric_compute.GetFabricComputeNotFound:
109+
return diag.Errorf("fabric compute '%s' not found", id)
110+
default:
111+
// nop
112+
}
113+
return diag.FromErr(err)
114+
}
115+
116+
fabricCompute := getResp.GetPayload()
117+
d.SetId(*fabricCompute.ID)
118+
d.Set("created_at", fabricCompute.CreatedAt)
119+
d.Set("custom_properties", fabricCompute.CustomProperties)
120+
d.Set("description", fabricCompute.Description)
121+
d.Set("external_id", fabricCompute.ExternalID)
122+
d.Set("external_region_id", fabricCompute.ExternalRegionID)
123+
d.Set("external_zone_id", fabricCompute.ExternalZoneID)
124+
d.Set("lifecycle_state", fabricCompute.LifecycleState)
125+
d.Set("name", fabricCompute.Name)
126+
d.Set("org_id", fabricCompute.OrgID)
127+
d.Set("owner", fabricCompute.Owner)
128+
d.Set("power_state", fabricCompute.PowerState)
129+
d.Set("type", fabricCompute.Type)
130+
d.Set("updated_at", fabricCompute.UpdatedAt)
131+
132+
if err := d.Set("links", flattenLinks(fabricCompute.Links)); err != nil {
133+
return diag.Errorf("error setting zone links - error: %#v", err)
134+
}
135+
136+
if err := d.Set("tags", flattenTags(fabricCompute.Tags)); err != nil {
137+
return diag.Errorf("error setting zone tags - error: %v", err)
138+
}
139+
140+
return nil
141+
}
142+
143+
func resourceFabricComputeUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
144+
apiClient := m.(*Client).apiClient
145+
146+
id := d.Id()
147+
148+
fabricComputeSpecification := &models.FabricComputeSpecification{
149+
Tags: expandTags(d.Get("tags").(*schema.Set).List()),
150+
}
151+
152+
if _, err := apiClient.FabricCompute.UpdateFabricCompute(fabric_compute.NewUpdateFabricComputeParams().WithID(id).WithBody(fabricComputeSpecification)); err != nil {
153+
return diag.FromErr(err)
154+
}
155+
156+
return resourceFabricComputeRead(ctx, d, m)
157+
}
158+
159+
func resourceFabricComputeDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
160+
return nil
161+
}

vra/resource_fabric_compute_test.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package vra
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"regexp"
7+
"testing"
8+
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
11+
"github.com/vmware/vra-sdk-go/pkg/client/fabric_compute"
12+
)
13+
14+
func TestAccVRAFabricCompute_importBasic(t *testing.T) {
15+
resourceName := "vra_fabric_compute.this"
16+
fabricComputeID := os.Getenv("VRA_FABRIC_COMPUTE_ID")
17+
18+
checkFn := func(s []*terraform.InstanceState) error {
19+
if len(s) != 1 {
20+
return fmt.Errorf("expected 1 state %#v", s)
21+
}
22+
23+
fabricComputeState := s[0]
24+
if fabricComputeID != fabricComputeState.ID {
25+
return fmt.Errorf("expected fabric compute ID of %s,%s received instead", fabricComputeID, fabricComputeState.ID)
26+
}
27+
return nil
28+
}
29+
resource.Test(t, resource.TestCase{
30+
PreCheck: func() { testAccPreCheckFabricCompute(t) },
31+
Providers: testAccProviders,
32+
CheckDestroy: testAccCheckVRAFabricComputeDestroy,
33+
Steps: []resource.TestStep{
34+
{
35+
Config: testAccCheckVRAFabricComputeConfig(),
36+
ExpectError: regexp.MustCompile("vra_fabric_compute resources are only importable"),
37+
},
38+
{
39+
Config: testAccCheckVRAFabricComputeConfig(),
40+
ResourceName: resourceName,
41+
ImportState: true,
42+
ImportStateId: fabricComputeID,
43+
ImportStateCheck: checkFn,
44+
},
45+
},
46+
})
47+
}
48+
49+
func testAccCheckVRAFabricComputeDestroy(s *terraform.State) error {
50+
apiClient := testAccProviderVRA.Meta().(*Client).apiClient
51+
52+
for _, rs := range s.RootModule().Resources {
53+
if rs.Type == "vra_fabric_compute" {
54+
if _, err := apiClient.FabricCompute.GetFabricCompute(fabric_compute.NewGetFabricComputeParams().WithID(rs.Primary.ID)); err == nil {
55+
return fmt.Errorf("Resource 'vra_fabric_compute' with id `%s` does not exist", rs.Primary.ID)
56+
}
57+
}
58+
59+
}
60+
61+
return nil
62+
}
63+
64+
func testAccCheckVRAFabricComputeConfig() string {
65+
regionName := os.Getenv("VRA_FABRIC_COMPUTE_NAME")
66+
return fmt.Sprintf(`
67+
resource "vra_fabric_compute" "this" {
68+
name = "%s"
69+
}`, regionName)
70+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
layout: "vra"
3+
page_title: "VMware vRealize Automation: fabric_compute"
4+
description: |-
5+
Updates a fabric_compute resource.
6+
---
7+
8+
# Resource: fabric_compute
9+
10+
Updates a VMware vRealize Automation fabric_compute resource.
11+
12+
## Example Usages
13+
14+
You cannot create a fabric compute resource, however you can import it using the command specified in the import section below.
15+
16+
Once a resource is imported, you can update it as shown below:
17+
18+
```hcl
19+
resource "fabric_compute" "this" {
20+
tags {
21+
key = "foo"
22+
value = "bar"
23+
}
24+
}
25+
```
26+
## Argument Reference
27+
28+
* `tags` - A set of tag keys and optional values that were set on this resource:
29+
* `key` - Tag’s key.
30+
* `value` - Tag’s value.
31+
32+
## Attribute Reference
33+
34+
* `created_at` - Date when the entity was created. The date is in ISO 8601 and UTC.
35+
36+
* `custom_properties` - A list of key value pair of custom properties for the fabric compute resource.
37+
38+
* `description` - A human-friendly description.
39+
40+
* `external_id` - The id of the external entity on the provider side.
41+
42+
* `external_region_id` - The external region id of the fabric compute.
43+
44+
* `external_zone_id` - The external zone id of the fabric compute.
45+
46+
* `lifecycle_state` - Lifecycle status of the compute instance.
47+
48+
* `links` - HATEOAS of the entity.
49+
50+
* `name` - A human-friendly name used as an identifier for the fabric compute resource instance.
51+
52+
* `org_id` - The id of the organization this entity belongs to.
53+
54+
* `owner` - Email of the user that owns the entity.
55+
56+
* `power_state` - Power state of fabric compute instance.
57+
58+
* `type` - Type of the fabric compute instance.
59+
60+
* `updated_at` - Date when the entity was last updated. The date is ISO 8601 and UTC.
61+
62+
## Import
63+
64+
To import the fabric compute resource, use the ID as in the following example:
65+
66+
`$ terraform import vra_fabric_compute.this 88fdea8b-92ed-4aa9-b6ee-4670412961b0

0 commit comments

Comments
 (0)