Skip to content

Commit b1f7bf9

Browse files
authored
doc(spanner): update documents to have example for IAM conditions use with google spanner database (GoogleCloudPlatform#10049)
1 parent 9f8d2aa commit b1f7bf9

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

mmv1/third_party/terraform/website/docs/r/spanner_database_iam.html.markdown

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,32 @@ resource "google_spanner_database_iam_policy" "database" {
3939
}
4040
```
4141

42+
With IAM Conditions:
43+
44+
```hcl
45+
data "google_iam_policy" "admin" {
46+
binding {
47+
role = "roles/editor"
48+
49+
members = [
50+
"user:jane@example.com",
51+
]
52+
53+
condition {
54+
title = "My Role"
55+
description = "Grant permissions on my_role"
56+
expression = "(resource.type == \"spanner.googleapis.com/DatabaseRole\" && (resource.name.endsWith(\"/myrole\")))"
57+
}
58+
}
59+
}
60+
61+
resource "google_spanner_database_iam_policy" "database" {
62+
instance = "your-instance-name"
63+
database = "your-database-name"
64+
policy_data = data.google_iam_policy.admin.policy_data
65+
}
66+
```
67+
4268
## google\_spanner\_database\_iam\_binding
4369

4470
```hcl
@@ -53,6 +79,26 @@ resource "google_spanner_database_iam_binding" "database" {
5379
}
5480
```
5581

82+
With IAM Conditions:
83+
84+
```hcl
85+
resource "google_spanner_database_iam_binding" "database" {
86+
instance = "your-instance-name"
87+
database = "your-database-name"
88+
role = "roles/compute.networkUser"
89+
90+
members = [
91+
"user:jane@example.com",
92+
]
93+
94+
condition {
95+
title = "My Role"
96+
description = "Grant permissions on my_role"
97+
expression = "(resource.type == \"spanner.googleapis.com/DatabaseRole\" && (resource.name.endsWith(\"/myrole\")))"
98+
}
99+
}
100+
```
101+
56102
## google\_spanner\_database\_iam\_member
57103

58104
```hcl
@@ -64,6 +110,23 @@ resource "google_spanner_database_iam_member" "database" {
64110
}
65111
```
66112

113+
With IAM Conditions:
114+
115+
```hcl
116+
resource "google_spanner_database_iam_member" "database" {
117+
instance = "your-instance-name"
118+
database = "your-database-name"
119+
role = "roles/compute.networkUser"
120+
member = "user:jane@example.com"
121+
122+
condition {
123+
title = "My Role"
124+
description = "Grant permissions on my_role"
125+
expression = "(resource.type == \"spanner.googleapis.com/DatabaseRole\" && (resource.name.endsWith(\"/myrole\")))"
126+
}
127+
}
128+
```
129+
67130
## Argument Reference
68131

69132
The following arguments are supported:
@@ -91,6 +154,23 @@ The following arguments are supported:
91154
* `project` - (Optional) The ID of the project in which the resource belongs. If it
92155
is not provided, the provider project is used.
93156

157+
* `condition` - (Optional) An [IAM Condition](https://cloud.google.com/iam/docs/conditions-overview) for a given binding.
158+
Structure is [documented below](#nested_condition).
159+
160+
---
161+
162+
<a name="nested_condition"></a>The `condition` block supports:
163+
164+
* `expression` - (Required) Textual representation of an expression in Common Expression Language syntax.
165+
166+
* `title` - (Required) A title for the expression, i.e. a short string describing its purpose.
167+
168+
* `description` - (Optional) An optional description of the expression. This is a longer text which describes the expression, e.g. when hovered over it in a UI.
169+
170+
~> **Warning:** Terraform considers the `role` and condition contents (`title`+`description`+`expression`) as the
171+
identifier for the binding. This means that if any part of the condition is changed out-of-band, Terraform will
172+
consider it to be an entirely different resource and will treat it as such.
173+
94174
## Attributes Reference
95175

96176
In addition to the arguments listed above, the following computed attributes are

0 commit comments

Comments
 (0)