Skip to content

Commit 4821fca

Browse files
authored
Merge pull request #416 from tenthirtyam/add-placement-policy
Add `placement_policy` to `vra_project`
2 parents 80e4cb5 + 7239f58 commit 4821fca

File tree

5 files changed

+75
-27
lines changed

5 files changed

+75
-27
lines changed

examples/project/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ resource "vra_project" "this" {
6666

6767
machine_naming_template = "$${resource.name}-$${####}"
6868

69+
placement_policy = "SPREAD"
70+
6971
constraints {
7072
extensibility {
7173
expression = "foo:bar"

vra/data_source_project.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ func dataSourceProject() *schema.Resource {
7474
Optional: true,
7575
Description: "The timeout that should be used for Blueprint operations and Provisioning tasks. The timeout is in seconds.",
7676
},
77+
"placement_policy": {
78+
Type: schema.TypeString,
79+
Optional: true,
80+
Description: "The placement policy that will be applied when selecting a cloud zone for provisioning.",
81+
},
7782
"id": {
7883
Type: schema.TypeString,
7984
Optional: true,
@@ -166,6 +171,7 @@ func dataSourceProjectRead(d *schema.ResourceData, meta interface{}) error {
166171
d.Set("member_roles", flattenUsers(project.Members))
167172
d.Set("name", project.Name)
168173
d.Set("operation_timeout", project.OperationTimeout)
174+
d.Set("placement_policy", project.PlacementPolicy)
169175
d.Set("shared_resources", project.SharedResources)
170176
d.Set("viewers", flattenUsers(project.Viewers))
171177
d.Set("viewer_roles", flattenUsers(project.Viewers))

vra/resource_project.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package vra
22

33
import (
44
"context"
5+
"fmt"
56

67
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
78
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -58,6 +59,20 @@ func resourceProject() *schema.Resource {
5859
Optional: true,
5960
Description: "The naming template to be used for resources provisioned in this project.",
6061
},
62+
"placement_policy": {
63+
Type: schema.TypeString,
64+
Default: "DEFAULT",
65+
Description: "The placement policy that will be applied when selecting a cloud zone for provisioning.",
66+
Optional: true,
67+
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
68+
value := v.(string)
69+
if value != "DEFAULT" && value != "SPREAD" {
70+
errors = append(errors, fmt.Errorf(
71+
"%q must be one of 'DEFAULT', 'SPREAD'", k))
72+
}
73+
return
74+
},
75+
},
6176
"members": {
6277
Type: schema.TypeSet,
6378
Optional: true,
@@ -149,6 +164,7 @@ func resourceProjectCreate(ctx context.Context, d *schema.ResourceData, m interf
149164
members := expandUserListAndNewUserList(d.Get("members").(*schema.Set).List(), d.Get("member_roles").(*schema.Set).List())
150165
name := d.Get("name").(string)
151166
operationTimeout := int64(d.Get("operation_timeout").(int))
167+
placementPolicy := d.Get("placement_policy").(string)
152168
sharedResources := d.Get("shared_resources").(bool)
153169
viewers := expandUserListAndNewUserList(d.Get("viewers").(*schema.Set).List(), d.Get("viewer_roles").(*schema.Set).List())
154170
zoneAssignment := expandZoneAssignment(d.Get("zone_assignments").(*schema.Set).List())
@@ -162,6 +178,7 @@ func resourceProjectCreate(ctx context.Context, d *schema.ResourceData, m interf
162178
Members: members,
163179
Name: &name,
164180
OperationTimeout: &operationTimeout,
181+
PlacementPolicy: placementPolicy,
165182
SharedResources: *withBool(sharedResources),
166183
Viewers: viewers,
167184
ZoneAssignmentConfigurations: zoneAssignment,
@@ -199,6 +216,7 @@ func resourceProjectRead(ctx context.Context, d *schema.ResourceData, m interfac
199216
d.Set("member_roles", flattenUsers(project.Members))
200217
d.Set("name", project.Name)
201218
d.Set("operation_timeout", project.OperationTimeout)
219+
d.Set("placement_policy", project.PlacementPolicy)
202220
d.Set("shared_resources", project.SharedResources)
203221
d.Set("viewers", flattenUsers(project.Viewers))
204222
d.Set("viewer_roles", flattenUsers(project.Viewers))
@@ -221,6 +239,7 @@ func resourceProjectUpdate(ctx context.Context, d *schema.ResourceData, m interf
221239
viewers := expandUserListAndNewUserList(d.Get("viewers").(*schema.Set).List(), d.Get("viewer_roles").(*schema.Set).List())
222240
name := d.Get("name").(string)
223241
operationTimeout := int64(d.Get("operation_timeout").(int))
242+
placementPolicy := d.Get("placement_policy").(string)
224243
sharedResources := d.Get("shared_resources").(bool)
225244
zoneAssignment := expandZoneAssignment(d.Get("zone_assignments").(*schema.Set).List())
226245

@@ -233,6 +252,7 @@ func resourceProjectUpdate(ctx context.Context, d *schema.ResourceData, m interf
233252
Members: members,
234253
Name: &name,
235254
OperationTimeout: &operationTimeout,
255+
PlacementPolicy: placementPolicy,
236256
SharedResources: *withBool(sharedResources),
237257
Viewers: viewers,
238258
ZoneAssignmentConfigurations: zoneAssignment,

website/docs/d/vra_project.html.markdown

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ description: |-
66
---
77

88
# Data Source: vra_project
9+
910
## Example Usages
1011
This is an example of how to create a project data source.
1112

@@ -29,12 +30,13 @@ A project data source supports the following arguments:
2930

3031
## Argument Reference
3132

32-
* `administrators` - (Optional) List of administrator users associated with the project. Only administrators can manage project's configuration.
33-
Deprecated, to specify the type of principal, please refer `administrator_roles`.
33+
* `administrators` - (Optional) A list of administrator users associated with the project. Only administrators can manage project's configuration.
34+
35+
> **Note**: Deprecated - please refer to `administrator_roles`.
3436
3537
* `administrator_roles` - (Optional) Administrator users or groups associated with the project. Only administrators can manage project's configuration.
3638

37-
* `constraints` - (Optional) List of storage, network and extensibility constraints to be applied when provisioning through this project.
39+
* `constraints` - (Optional) A list of storage, network and extensibility constraints to be applied when provisioning through this project.
3840

3941
* `custom_properties` - (Optional) The project custom properties which are added to all requests in this project.
4042

@@ -44,20 +46,26 @@ Deprecated, to specify the type of principal, please refer `administrator_roles`
4446

4547
* `machine_naming_template` - (Optional) The naming template to be used for resources provisioned in this project.
4648

47-
* `members` - (Optional) List of member users associated with the project. Deprecated, to specify the type of principal, please refer `member_roles`.
49+
* `members` - (Optional) A list of member users associated with the project.
50+
51+
> **Note**: Deprecated - please refer to `member_roles`.
4852
4953
* `member_roles` - (Optional) Member users or groups associated with the project.
5054

5155
* `name` - (Optional) A human-friendly name used as an identifier in APIs that support this option.
5256

5357
* `operation_timeout` - (Optional) The timeout that should be used for Blueprint operations and Provisioning tasks. The timeout is in seconds.
5458

59+
* `placement_policy` - (Optional) The placement policy that will be applied when selecting a cloud zone for provisioning. Must be one of `DEFAULT` or `SPREAD`.
60+
5561
* `shared_resources` - (Optional) Specifies whether the resources in this projects are shared or not. If not set default will be used.
5662

57-
* `zone_assignments` - (Optional) List of configurations for zone assignment to a project.
63+
* `zone_assignments` - (Optional) A list of configurations for zone assignment to a project.
5864

5965
* `shared_resources` - (Optional) The id of the organization this entity belongs to.
6066

61-
* `viewers` - (Optional) List of viewer users associated with the project. Deprecated, to specify the type of principal, please refer `viewer_roles`.
67+
* `viewers` - (Optional) A list of viewer users associated with the project.
68+
69+
> **Note**: Deprecated - please refer to `viewer_roles`.
6270
6371
* `viewer_roles` - (Optional) Viewer users or groups associated with the project.

website/docs/r/vra_project.html.markdown

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
layout: "vra"
33
page_title: "VMware vRealize Automation: vra_project"
44
description: |-
5-
Provides a VMware vRA vra_project resource.
5+
Provides a VMware vRealize Automation vra_project resource.
66
---
77
# Resource: vra\_project
8+
89
## Example Usages
10+
911
This is an example of how to create a project resource.
1012

1113
```hcl
@@ -34,51 +36,53 @@ resource "vra_project" "this" {
3436
3537
administrator_roles {
3638
37-
type = "user"
39+
type = "user"
3840
}
3941
4042
administrator_roles {
4143
42-
type = "group"
44+
type = "group"
4345
}
4446
4547
# Deprecated, please use member_roles instead.
4648
members = ["[email protected]"]
4749
4850
member_roles {
4951
50-
type = "user"
52+
type = "user"
5153
}
5254
5355
member_roles {
5456
55-
type = "group"
57+
type = "group"
5658
}
5759
5860
# Deprecated, please use viewer_roles instead
5961
viewers = ["[email protected]"]
6062
6163
viewer_roles {
6264
63-
type = "user"
65+
type = "user"
6466
}
6567
6668
viewer_roles {
6769
68-
type = "group"
70+
type = "group"
6971
}
7072
7173
operation_timeout = 6000
7274
7375
machine_naming_template = "$${resource.name}-$${####}"
7476
77+
placement_policy = "SPREAD"
78+
7579
constraints {
7680
extensibility {
7781
expression = "foo:bar"
7882
mandatory = false
7983
}
8084
extensibility {
81-
expression = "environment:Test"
85+
expression = "environment:test"
8286
mandatory = true
8387
}
8488
@@ -87,7 +91,7 @@ resource "vra_project" "this" {
8791
mandatory = false
8892
}
8993
network {
90-
expression = "environment:Test"
94+
expression = "environment:test"
9195
mandatory = true
9296
}
9397
@@ -96,7 +100,7 @@ resource "vra_project" "this" {
96100
mandatory = false
97101
}
98102
storage {
99-
expression = "environment:Test"
103+
expression = "environment:test"
100104
mandatory = true
101105
}
102106
}
@@ -107,40 +111,48 @@ A project resource supports the following arguments:
107111

108112
## Argument Reference
109113

110-
* `administrators` - (Optional) List of administrator users associated with the project. Only administrators can manage project's configuration.
111-
Deprecated, specify the type of principal, please refer `administrator_roles`.
114+
* `administrators` - (Optional) A list of administrator users associated with the project. Only administrators can manage project's configuration.
115+
116+
> **Note**: Deprecated - please refer to `administrator_roles`.
112117
113118
* `administrator_roles` - (Optional) Administrator users or groups associated with the project. Only administrators can manage project's configuration.
114119

115-
* `constraints` - (Optional) List of storage, network and extensibility constraints to be applied when provisioning through this project.
120+
* `constraints` - (Optional) A list of storage, network, and extensibility constraints to be applied when provisioning through this project.
116121

117122
* `custom_properties` - (Optional) The project custom properties which are added to all requests in this project.
118123

119124
* `description` - (Optional) A human-friendly description.
120125

121126
* `machine_naming_template` - (Optional) The naming template to be used for resources provisioned in this project.
122127

123-
* `members` - (Optional) List of member users associated with the project. Deprecated, specify the type of principal, please refer `member_roles`.
128+
* `members` - (Optional) A list of member users associated with the project.
129+
130+
> **Note**: Deprecated - please refer to `member_roles`.
124131
125132
* `member_roles` - (Optional) Member users or groups associated with the project.
126133

127134
* `name` - (Required) A human-friendly name used as an identifier in APIs that support this option.
128135

129-
* `operation_timeout` - (Optional) The timeout that should be used for Blueprint operations and Provisioning tasks. The timeout is in seconds.
136+
* `operation_timeout` - (Optional) The timeout that should be used for cloud template operations and provisioning tasks. The timeout is measured in seconds.
137+
138+
* `placement_policy` - (Optional) The placement policy that will be applied when selecting a cloud zone for provisioning. Must be one of `DEFAULT` or `SPREAD`.
130139

131140
* `shared_resources` - (Optional) Specifies whether the resources in this projects are shared or not. If not set default will be used.
132141

133-
* `viewers` - (Optional) List of viewer users associated with the project. Deprecated, specify the type of principal, please refer `viewer_roles`.
142+
* `viewers` - (Optional) A list of viewer users associated with the project.
143+
144+
> **Note**: Deprecated - please refer to `viewer_roles`.
134145
135146
* `viewer_roles` - (Optional) Viewer users or groups associated with the project.
136147

137-
* `zone_assignments` - (Optional) List of configurations for zone assignment to a project.
148+
* `zone_assignments` - (Optional) A list of configurations for zone assignment to a project.
138149

139-
**Due to the design of IAAS API to update a project, it's not able to add and remove user or group at the same time. Please execute `terraform apply` twice.**
150+
**Due to the design of the vRealize Automation IaaS API to update a project, it's not able to add and remove user or group at the same time. Please execute `terraform apply` twice.**
140151

141152
Example:
142153

143-
Initially, we have `jason` and `tony` configured as administrator in the config file
154+
Initially, we have `jason` and `tony` configured as administrator. The initial the configuration:
155+
144156
```hcl
145157
administrator_roles {
146158
@@ -153,7 +165,7 @@ Initially, we have `jason` and `tony` configured as administrator in the config
153165
}
154166
```
155167

156-
Now we want to add `bob` as a new administrator and remove `jason`, the modified config file will be
168+
Next, we want to add `bob` as a new administrator and remove `jason`. The modified configuration:
157169

158170
```hcl
159171
administrator_roles {
@@ -167,5 +179,5 @@ Now we want to add `bob` as a new administrator and remove `jason`, the modified
167179
}
168180
```
169181

170-
To complete the whole operation, it requires executing `terraform apply` twice.
182+
To complete the whole operation, it requires running `terraform apply` twice.
171183

0 commit comments

Comments
 (0)