Skip to content

Commit f7ce3c3

Browse files
Firestore Tags R2401 terraform support (#14489) (#23569)
[upstream:be2c0371794509e16928f1e6fbd3b80525ccd80a] Signed-off-by: Modular Magician <[email protected]>
1 parent d3f0b18 commit f7ce3c3

File tree

6 files changed

+133
-5
lines changed

6 files changed

+133
-5
lines changed

.changelog/14489.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
firestore: added `tags` field to `google_firestore_database` resource
3+
```

google/services/firestore/resource_firestore_database.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,18 @@ and reads against 1-minute snapshots beyond 1 hour and within 7 days.
170170
If 'POINT_IN_TIME_RECOVERY_DISABLED' is selected, reads are supported on any version of the data from within the past 1 hour. Default value: "POINT_IN_TIME_RECOVERY_DISABLED" Possible values: ["POINT_IN_TIME_RECOVERY_ENABLED", "POINT_IN_TIME_RECOVERY_DISABLED"]`,
171171
Default: "POINT_IN_TIME_RECOVERY_DISABLED",
172172
},
173+
"tags": {
174+
Type: schema.TypeMap,
175+
Optional: true,
176+
ForceNew: true,
177+
Description: `Input only. A map of resource manager tags. Resource manager tag keys
178+
and values have the same definition as resource manager tags.
179+
Keys must be in the format tagKeys/{tag_key_id}, and values are in the format tagValues/456.
180+
The field is ignored when empty. The field is immutable and causes
181+
resource replacement when mutated. To apply tags to an existing resource, see
182+
the 'google_tags_tag_value' resource.`,
183+
Elem: &schema.Schema{Type: schema.TypeString},
184+
},
173185
"create_time": {
174186
Type: schema.TypeString,
175187
Computed: true,
@@ -304,6 +316,12 @@ func resourceFirestoreDatabaseCreate(d *schema.ResourceData, meta interface{}) e
304316
} else if v, ok := d.GetOkExists("cmek_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(cmekConfigProp)) && (ok || !reflect.DeepEqual(v, cmekConfigProp)) {
305317
obj["cmekConfig"] = cmekConfigProp
306318
}
319+
tagsProp, err := expandFirestoreDatabaseTags(d.Get("tags"), d, config)
320+
if err != nil {
321+
return err
322+
} else if v, ok := d.GetOkExists("tags"); !tpgresource.IsEmptyValue(reflect.ValueOf(tagsProp)) && (ok || !reflect.DeepEqual(v, tagsProp)) {
323+
obj["tags"] = tagsProp
324+
}
307325

308326
url, err := tpgresource.ReplaceVars(d, config, "{{FirestoreBasePath}}projects/{{project}}/databases?databaseId={{name}}")
309327
if err != nil {
@@ -824,3 +842,14 @@ func expandFirestoreDatabaseCmekConfigKmsKeyName(v interface{}, d tpgresource.Te
824842
func expandFirestoreDatabaseCmekConfigActiveKeyVersion(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
825843
return v, nil
826844
}
845+
846+
func expandFirestoreDatabaseTags(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
847+
if v == nil {
848+
return map[string]string{}, nil
849+
}
850+
m := make(map[string]string)
851+
for k, val := range v.(map[string]interface{}) {
852+
m[k] = val.(string)
853+
}
854+
return m, nil
855+
}

google/services/firestore/resource_firestore_database_generated_meta.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ fields:
2020
- field: 'location_id'
2121
- field: 'name'
2222
- field: 'point_in_time_recovery_enablement'
23+
- field: 'tags'
2324
- field: 'type'
2425
- field: 'uid'
2526
- field: 'update_time'

google/services/firestore/resource_firestore_database_generated_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func TestAccFirestoreDatabase_firestoreDatabaseExample(t *testing.T) {
5252
ResourceName: "google_firestore_database.database",
5353
ImportState: true,
5454
ImportStateVerify: true,
55-
ImportStateVerifyIgnore: []string{"deletion_policy", "etag", "project"},
55+
ImportStateVerifyIgnore: []string{"deletion_policy", "etag", "project", "tags"},
5656
},
5757
},
5858
})
@@ -95,7 +95,7 @@ func TestAccFirestoreDatabase_firestoreCmekDatabaseExample(t *testing.T) {
9595
ResourceName: "google_firestore_database.database",
9696
ImportState: true,
9797
ImportStateVerify: true,
98-
ImportStateVerifyIgnore: []string{"deletion_policy", "etag", "project"},
98+
ImportStateVerifyIgnore: []string{"deletion_policy", "etag", "project", "tags"},
9999
},
100100
},
101101
})
@@ -168,7 +168,7 @@ func TestAccFirestoreDatabase_firestoreDatabaseInDatastoreModeExample(t *testing
168168
ResourceName: "google_firestore_database.datastore_mode_database",
169169
ImportState: true,
170170
ImportStateVerify: true,
171-
ImportStateVerifyIgnore: []string{"deletion_policy", "etag", "project"},
171+
ImportStateVerifyIgnore: []string{"deletion_policy", "etag", "project", "tags"},
172172
},
173173
},
174174
})
@@ -211,7 +211,7 @@ func TestAccFirestoreDatabase_firestoreCmekDatabaseInDatastoreModeExample(t *tes
211211
ResourceName: "google_firestore_database.database",
212212
ImportState: true,
213213
ImportStateVerify: true,
214-
ImportStateVerifyIgnore: []string{"deletion_policy", "etag", "project"},
214+
ImportStateVerifyIgnore: []string{"deletion_policy", "etag", "project", "tags"},
215215
},
216216
},
217217
})
@@ -283,7 +283,7 @@ func TestAccFirestoreDatabase_firestoreDatabaseEnterpriseExample(t *testing.T) {
283283
ResourceName: "google_firestore_database.enterprise-db",
284284
ImportState: true,
285285
ImportStateVerify: true,
286-
ImportStateVerifyIgnore: []string{"deletion_policy", "etag", "project"},
286+
ImportStateVerifyIgnore: []string{"deletion_policy", "etag", "project", "tags"},
287287
},
288288
},
289289
})
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
// ----------------------------------------------------------------------------
4+
//
5+
// *** AUTO GENERATED CODE *** Type: Handwritten ***
6+
//
7+
// ----------------------------------------------------------------------------
8+
//
9+
// This code is generated by Magic Modules using the following:
10+
//
11+
// Source file: https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/services/firestore/resource_firestore_database_test.go
12+
//
13+
// DO NOT EDIT this file directly. Any changes made to this file will be
14+
// overwritten during the next generation cycle.
15+
//
16+
// ----------------------------------------------------------------------------
17+
package firestore_test
18+
19+
import (
20+
"testing"
21+
22+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
23+
"github.com/hashicorp/terraform-provider-google/google/acctest"
24+
"github.com/hashicorp/terraform-provider-google/google/envvar"
25+
)
26+
27+
func TestAccFirestoreDatabase_tags(t *testing.T) {
28+
t.Parallel()
29+
30+
// Bootstrap shared tag key and value
31+
tagKey := acctest.BootstrapSharedTestProjectTagKey(t, "firestore-databases-tagkey", map[string]interface{}{})
32+
context := map[string]interface{}{
33+
"pid": envvar.GetTestProjectFromEnv(),
34+
"tagKey": tagKey,
35+
"tagValue": acctest.BootstrapSharedTestProjectTagValue(t, "firestore-databases-tagvalue", tagKey),
36+
"random_suffix": acctest.RandString(t, 10),
37+
}
38+
39+
acctest.VcrTest(t, resource.TestCase{
40+
PreCheck: func() { acctest.AccTestPreCheck(t) },
41+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
42+
CheckDestroy: testAccCheckFirestoreDatabaseDestroyProducer(t),
43+
Steps: []resource.TestStep{
44+
{
45+
Config: testAccFirestoreDatabaseTags(context),
46+
},
47+
{
48+
ResourceName: "google_firestore_database.database",
49+
ImportState: true,
50+
ImportStateVerify: true,
51+
ImportStateVerifyIgnore: []string{"project", "etag", "deletion_policy", "tags"},
52+
},
53+
},
54+
})
55+
}
56+
57+
func testAccFirestoreDatabaseTags(context map[string]interface{}) string {
58+
return acctest.Nprintf(`
59+
resource "google_firestore_database" "database" {
60+
name = "tf-test-database-%{random_suffix}"
61+
location_id = "nam5"
62+
type = "FIRESTORE_NATIVE"
63+
delete_protection_state = "DELETE_PROTECTION_DISABLED"
64+
deletion_policy = "DELETE"
65+
tags = {
66+
"%{pid}/%{tagKey}" = "%{tagValue}"
67+
}
68+
}
69+
`, context)
70+
}

website/docs/r/firestore_database.html.markdown

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,22 @@ resource "google_firestore_database" "database" {
6363
deletion_policy = "DELETE"
6464
}
6565
```
66+
## Example Usage - Firestore Database With Tags
67+
68+
69+
```hcl
70+
resource "google_firestore_database" "database" {
71+
project = "my-project-name"
72+
name = "database-with-tags-id"
73+
location_id = "nam5"
74+
type = "FIRESTORE_NATIVE"
75+
delete_protection_state = "DELETE_PROTECTION_ENABLED"
76+
deletion_policy = "DELETE"
77+
tags = {
78+
"keyname" = "valuename"
79+
}
80+
}
81+
```
6682
## Example Usage - Firestore Cmek Database
6783

6884

@@ -263,6 +279,15 @@ The following arguments are supported:
263279
encryption key.
264280
Structure is [documented below](#nested_cmek_config).
265281

282+
* `tags` -
283+
(Optional)
284+
Input only. A map of resource manager tags. Resource manager tag keys
285+
and values have the same definition as resource manager tags.
286+
Keys must be in the format tagKeys/{tag_key_id}, and values are in the format tagValues/456.
287+
The field is ignored when empty. The field is immutable and causes
288+
resource replacement when mutated. To apply tags to an existing resource, see
289+
the `google_tags_tag_value` resource.
290+
266291
* `project` - (Optional) The ID of the project in which the resource belongs.
267292
If it is not provided, the provider project is used.
268293

0 commit comments

Comments
 (0)