Skip to content

Commit ec22d4a

Browse files
committed
Add dynamic group resource to the provider
Updated the examples accordingly Use the example spec correctly for the update value as well Drop superflous comment This has been systematically fixed now. Use tenancy ocid for identity resources that need to be created in root This was causing test case failures earlier. Add negative test case on bad syntax of matching rule Avoid hardcoding ocid Add hcl lang directive to the doc file Use computed attribute to ensure that happens-before is honored
1 parent 764821c commit ec22d4a

13 files changed

+777
-11
lines changed

docs/examples/identity/group.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,27 @@ data "oci_identity_groups" "groups1" {
2525
output "groups" {
2626
value = "${data.oci_identity_groups.groups1.groups}"
2727
}
28+
29+
/*
30+
* Some more directives to show dynamic groups and policy for it
31+
*/
32+
resource "oci_identity_dynamic_group" "dynamic-group-1" {
33+
compartment_id = "${var.tenancy_ocid}"
34+
name = "tf-example-dynamic-group"
35+
description = "dynamic group created by terraform"
36+
matching_rule = "instance.compartment.id = ${oci_identity_compartment.compartment1.id}"
37+
}
38+
39+
data "oci_identity_dynamic_groups" "dynamic-groups-1" {
40+
compartment_id = "${oci_identity_dynamic_group.dynamic-group-1.compartment_id}"
41+
42+
filter {
43+
name = "id"
44+
values = ["${oci_identity_dynamic_group.dynamic-group-1.id}"]
45+
}
46+
}
47+
48+
output "dynamicGroups" {
49+
value = "${data.oci_identity_dynamic_groups.dynamic-groups-1.dynamic_groups}"
50+
}
51+

docs/examples/identity/policy.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,27 @@ data "oci_identity_policies" "policies1" {
2424
output "policy" {
2525
value = "${data.oci_identity_policies.policies1.policies}"
2626
}
27+
28+
/*
29+
* Policies for dynamic groups
30+
*/
31+
resource "oci_identity_policy" "dynamic-policy-1" {
32+
name = "tf-example-dynamic-policy"
33+
description = "dynamic policy created by terraform"
34+
compartment_id = "${var.tenancy_ocid}"
35+
statements = ["Allow dynamic-group ${oci_identity_dynamic_group.dynamic-group-1.name} to read instances in compartment ${oci_identity_compartment.compartment1.name}",
36+
"Allow dynamic-group ${oci_identity_dynamic_group.dynamic-group-1.name} to inspect instances in compartment ${oci_identity_compartment.compartment1.name}"]
37+
}
38+
39+
data "oci_identity_policies" "dynamic-policies-1" {
40+
compartment_id = "${oci_identity_policy.dynamic-policy-1.compartment_id}"
41+
42+
filter {
43+
name = "id"
44+
values = ["${oci_identity_policy.dynamic-policy-1.id}"]
45+
}
46+
}
47+
48+
output "dynamicPolicies" {
49+
value = "${data.oci_identity_policies.dynamic-policies-1.policies}"
50+
}

docs/examples/identity/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ This example demonstrates the following Identity concepts:
1414
* Create users, add an api key and access their password
1515
* Create groups and add users
1616
* Create policies affecting groups and compartments
17-
17+
* Create dynamic groups and policies that govern it

docs/identity/dynamic_groups.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# oci_identity_dynamic_group
2+
3+
## DynamicGroup Resource
4+
5+
### DynamicGroup Reference
6+
7+
The following attributes are exported:
8+
9+
* `compartment_id` - The OCID of the tenancy containing the group.
10+
* `description` - The description you assign to the group. Does not have to be unique, and it's changeable.
11+
* `id` - The OCID of the group.
12+
* `inactive_state` - The detailed status of INACTIVE lifecycleState.
13+
* `matching_rule` - A rule string that defines which instance certificates will be matched. For syntax, see [Managing Dynamic Groups](https://docs.us-phoenix-1.oraclecloud.com/Content/Identity/Tasks/managingdynamicgroups.htm).
14+
* `name` - The name you assign to the group during creation. The name must be unique across all groups in the tenancy and cannot be changed.
15+
* `state` - The group's current state. After creating a group, make sure its `lifecycleState` changes from CREATING to ACTIVE before using it.
16+
* `time_created` - Date and time the group was created, in the format defined by RFC3339. Example: `2016-08-25T21:10:29.600Z`
17+
18+
19+
20+
### Create Operation
21+
Creates a new dynamic group in your tenancy.
22+
23+
You must specify your tenancy's OCID as the compartment ID in the request object (remember that the tenancy
24+
is simply the root compartment). Notice that IAM resources (users, groups, compartments, and some policies)
25+
reside within the tenancy itself, unlike cloud resources such as compute instances, which typically
26+
reside within compartments inside the tenancy. For information about OCIDs, see
27+
[Resource Identifiers](https://docs.us-phoenix-1.oraclecloud.com/Content/General/Concepts/identifiers.htm).
28+
29+
You must also specify a *name* for the dynamic group, which must be unique across all dynamic groups in your
30+
tenancy, and cannot be changed. Note that this name has to be also unique accross all groups in your tenancy.
31+
You can use this name or the OCID when writing policies that apply to the dynamic group. For more information
32+
about policies, see [How Policies Work](https://docs.us-phoenix-1.oraclecloud.com/Content/Identity/Concepts/policies.htm).
33+
34+
You must also specify a *description* for the dynamic group (although it can be an empty string). It does not
35+
have to be unique, and you can change it anytime with [UpdateDynamicGroup](https://docs.us-phoenix-1.oraclecloud.com/api/#/en/identity/20160918/DynamicGroup/UpdateDynamicGroup).
36+
37+
After you send your request, the new object's `lifecycleState` will temporarily be CREATING. Before using the
38+
object, first make sure its `lifecycleState` has changed to ACTIVE.
39+
40+
41+
The following arguments are supported:
42+
43+
* `compartment_id` - (Required) The OCID of the tenancy containing the group.
44+
* `description` - (Required) The description you assign to the group during creation. Does not have to be unique, and it's changeable.
45+
* `matching_rule` - (Required) The matching rule to dynamically match an instance certificate to this dynamic group. For rule syntax, see [Managing Dynamic Groups](https://docs.us-phoenix-1.oraclecloud.com/Content/Identity/Tasks/managingdynamicgroups.htm).
46+
* `name` - (Required) The name you assign to the group during creation. The name must be unique across all groups in the tenancy and cannot be changed.
47+
48+
49+
### Update Operation
50+
Updates the specified dynamic group.
51+
52+
The following arguments support updates:
53+
* `description` - The description you assign to the group during creation. Does not have to be unique, and it's changeable.
54+
* `matching_rule` - The matching rule to dynamically match an instance certificate to this dynamic group. For rule syntax, see [Managing Dynamic Groups](https://docs.us-phoenix-1.oraclecloud.com/Content/Identity/Tasks/managingdynamicgroups.htm).
55+
56+
57+
** IMPORTANT **
58+
Any change to a property that does not support update will force the destruction and recreation of the resource with the new property values
59+
60+
### Example Usage
61+
62+
```hcl
63+
resource "oci_identity_dynamic_group" "test_dynamic_group" {
64+
#Required
65+
compartment_id = "${var.compartment_id}"
66+
description = "${var.dynamic_group_description}"
67+
matching_rule = "${var.dynamic_group_matching_rule}"
68+
name = "${var.dynamic_group_name}"
69+
}
70+
```
71+
72+
# oci_identity_dynamic_groups
73+
74+
## DynamicGroup DataSource
75+
76+
Gets a list of dynamic_groups.
77+
78+
### List Operation
79+
Lists the dynamic groups in your tenancy. You must specify your tenancy's OCID as the value for
80+
the compartment ID (remember that the tenancy is simply the root compartment).
81+
See [Where to Get the Tenancy's OCID and User's OCID](https://docs.us-phoenix-1.oraclecloud.com/Content/API/Concepts/apisigningkey.htm#five).
82+
83+
The following arguments are supported:
84+
85+
* `compartment_id` - (Required) The OCID of the compartment (remember that the tenancy is simply the root compartment).
86+
87+
88+
The following attributes are exported:
89+
90+
* `dynamic_groups` - The list of dynamic_groups.
91+
92+
### Example Usage
93+
94+
```hcl
95+
data "oci_identity_dynamic_groups" "test_dynamic_groups" {
96+
#Required
97+
compartment_id = "${var.compartment_id}"
98+
}
99+
```

provider/identity_api_key_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ func TestIdentityApiKeyResource_basic(t *testing.T) {
4545
provider := testAccProvider
4646
config := testProviderConfig()
4747

48-
// For identity resources, the compartment ID *must* be the root compartment (a.k.a. tenancy ID)
4948
compartmentId := getRequiredEnvSetting("tenancy_ocid")
5049
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
5150

@@ -123,7 +122,6 @@ func TestIdentityApiKeyResource_forcenew(t *testing.T) {
123122
provider := testAccProvider
124123
config := testProviderConfig()
125124

126-
// For identity resources, the compartment ID *must* be the root compartment (a.k.a. tenancy ID)
127125
compartmentId := getRequiredEnvSetting("tenancy_ocid")
128126
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
129127

0 commit comments

Comments
 (0)