Skip to content

Commit b8e279c

Browse files
Adding replication field for Filestore Instance (#11897) (#21194)
[upstream:383b394588fdd1b7d971a7f5b6f0321dd1c65d5d] Signed-off-by: Modular Magician <[email protected]>
1 parent 77dc585 commit b8e279c

File tree

6 files changed

+260
-3
lines changed

6 files changed

+260
-3
lines changed

.changelog/11897.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
filestore: added `initial_replication` field for peer instance configuration and `effective_replication` output for replication configuration output to `google_filestore_instance`
3+
```

google/services/filestore/resource_filestore_instance.go

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,39 @@ Possible values include: STANDARD, PREMIUM, BASIC_HDD, BASIC_SSD, HIGH_SCALE_SSD
232232
Optional: true,
233233
Description: `A description of the instance.`,
234234
},
235+
"initial_replication": {
236+
Type: schema.TypeList,
237+
Optional: true,
238+
ForceNew: true,
239+
Description: `Replication configuration, once set, this cannot be updated.
240+
Addtionally this should be specified on the replica instance only, indicating the active as the peer_instance`,
241+
MaxItems: 1,
242+
Elem: &schema.Resource{
243+
Schema: map[string]*schema.Schema{
244+
"replicas": {
245+
Type: schema.TypeList,
246+
Optional: true,
247+
Description: `The replication role.`,
248+
Elem: &schema.Resource{
249+
Schema: map[string]*schema.Schema{
250+
"peer_instance": {
251+
Type: schema.TypeString,
252+
Required: true,
253+
Description: `The peer instance.`,
254+
},
255+
},
256+
},
257+
},
258+
"role": {
259+
Type: schema.TypeString,
260+
Optional: true,
261+
ValidateFunc: verify.ValidateEnum([]string{"ROLE_UNSPECIFIED", "ACTIVE", "STANDBY", ""}),
262+
Description: `The replication role. Default value: "STANDBY" Possible values: ["ROLE_UNSPECIFIED", "ACTIVE", "STANDBY"]`,
263+
Default: "STANDBY",
264+
},
265+
},
266+
},
267+
},
235268
"kms_key_name": {
236269
Type: schema.TypeString,
237270
Optional: true,
@@ -353,6 +386,44 @@ resource, see the 'google_tags_tag_value' resource.`,
353386
Description: `All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services.`,
354387
Elem: &schema.Schema{Type: schema.TypeString},
355388
},
389+
"effective_replication": {
390+
Type: schema.TypeList,
391+
Computed: true,
392+
Description: `Output only fields for replication configuration.`,
393+
Elem: &schema.Resource{
394+
Schema: map[string]*schema.Schema{
395+
"replicas": {
396+
Type: schema.TypeList,
397+
Optional: true,
398+
Description: `The replication role.`,
399+
Elem: &schema.Resource{
400+
Schema: map[string]*schema.Schema{
401+
"last_active_sync_time": {
402+
Type: schema.TypeString,
403+
Computed: true,
404+
Description: `Output only. The timestamp of the latest replication snapshot taken on the active instance and is already replicated safely.
405+
A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits.
406+
Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z"`,
407+
},
408+
"state": {
409+
Type: schema.TypeString,
410+
Computed: true,
411+
Description: `Output only. The replica state`,
412+
},
413+
"state_reasons": {
414+
Type: schema.TypeList,
415+
Computed: true,
416+
Description: `Output only. Additional information about the replication state, if available.`,
417+
Elem: &schema.Schema{
418+
Type: schema.TypeString,
419+
},
420+
},
421+
},
422+
},
423+
},
424+
},
425+
},
426+
},
356427
"etag": {
357428
Type: schema.TypeString,
358429
Computed: true,
@@ -615,6 +686,9 @@ func resourceFilestoreInstanceRead(d *schema.ResourceData, meta interface{}) err
615686
if err := d.Set("performance_config", flattenFilestoreInstancePerformanceConfig(res["performanceConfig"], d, config)); err != nil {
616687
return fmt.Errorf("Error reading Instance: %s", err)
617688
}
689+
if err := d.Set("effective_replication", flattenFilestoreInstanceEffectiveReplication(res["replication"], d, config)); err != nil {
690+
return fmt.Errorf("Error reading Instance: %s", err)
691+
}
618692
if err := d.Set("terraform_labels", flattenFilestoreInstanceTerraformLabels(res["labels"], d, config)); err != nil {
619693
return fmt.Errorf("Error reading Instance: %s", err)
620694
}
@@ -1117,6 +1191,51 @@ func flattenFilestoreInstancePerformanceConfigFixedIopsMaxIops(v interface{}, d
11171191
return v // let terraform core handle it otherwise
11181192
}
11191193

1194+
func flattenFilestoreInstanceEffectiveReplication(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1195+
if v == nil {
1196+
return nil
1197+
}
1198+
original := v.(map[string]interface{})
1199+
if len(original) == 0 {
1200+
return nil
1201+
}
1202+
transformed := make(map[string]interface{})
1203+
transformed["replicas"] =
1204+
flattenFilestoreInstanceEffectiveReplicationReplicas(original["replicas"], d, config)
1205+
return []interface{}{transformed}
1206+
}
1207+
func flattenFilestoreInstanceEffectiveReplicationReplicas(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1208+
if v == nil {
1209+
return v
1210+
}
1211+
l := v.([]interface{})
1212+
transformed := make([]interface{}, 0, len(l))
1213+
for _, raw := range l {
1214+
original := raw.(map[string]interface{})
1215+
if len(original) < 1 {
1216+
// Do not include empty json objects coming back from the api
1217+
continue
1218+
}
1219+
transformed = append(transformed, map[string]interface{}{
1220+
"state": flattenFilestoreInstanceEffectiveReplicationReplicasState(original["state"], d, config),
1221+
"state_reasons": flattenFilestoreInstanceEffectiveReplicationReplicasStateReasons(original["stateReasons"], d, config),
1222+
"last_active_sync_time": flattenFilestoreInstanceEffectiveReplicationReplicasLastActiveSyncTime(original["lastActiveSyncTime"], d, config),
1223+
})
1224+
}
1225+
return transformed
1226+
}
1227+
func flattenFilestoreInstanceEffectiveReplicationReplicasState(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1228+
return v
1229+
}
1230+
1231+
func flattenFilestoreInstanceEffectiveReplicationReplicasStateReasons(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1232+
return v
1233+
}
1234+
1235+
func flattenFilestoreInstanceEffectiveReplicationReplicasLastActiveSyncTime(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1236+
return v
1237+
}
1238+
11201239
func flattenFilestoreInstanceTerraformLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
11211240
if v == nil {
11221241
return v

google/services/filestore/resource_filestore_instance_generated_meta.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ fields:
1010
- field: 'description'
1111
- field: 'effective_labels'
1212
provider_only: true
13+
- field: 'effective_replication.replicas.last_active_sync_time'
14+
api_field: 'replication.replicas.last_active_sync_time'
15+
- field: 'effective_replication.replicas.state'
16+
api_field: 'replication.replicas.state'
17+
- field: 'effective_replication.replicas.state_reasons'
18+
api_field: 'replication.replicas.state_reasons'
1319
- field: 'etag'
1420
- field: 'file_shares.capacity_gb'
1521
- field: 'file_shares.name'
@@ -19,6 +25,10 @@ fields:
1925
- field: 'file_shares.nfs_export_options.ip_ranges'
2026
- field: 'file_shares.nfs_export_options.squash_mode'
2127
- field: 'file_shares.source_backup'
28+
- field: 'initial_replication.replicas.peer_instance'
29+
provider_only: true
30+
- field: 'initial_replication.role'
31+
provider_only: true
2232
- field: 'kms_key_name'
2333
- field: 'labels'
2434
- field: 'location'

google/services/filestore/resource_filestore_instance_generated_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func TestAccFilestoreInstance_filestoreInstanceBasicExample(t *testing.T) {
4949
ResourceName: "google_filestore_instance.instance",
5050
ImportState: true,
5151
ImportStateVerify: true,
52-
ImportStateVerifyIgnore: []string{"labels", "location", "name", "tags", "terraform_labels", "zone"},
52+
ImportStateVerifyIgnore: []string{"initial_replication", "labels", "location", "name", "tags", "terraform_labels", "zone"},
5353
},
5454
},
5555
})
@@ -94,7 +94,7 @@ func TestAccFilestoreInstance_filestoreInstanceFullExample(t *testing.T) {
9494
ResourceName: "google_filestore_instance.instance",
9595
ImportState: true,
9696
ImportStateVerify: true,
97-
ImportStateVerifyIgnore: []string{"labels", "location", "name", "tags", "terraform_labels", "zone"},
97+
ImportStateVerifyIgnore: []string{"initial_replication", "labels", "location", "name", "tags", "terraform_labels", "zone"},
9898
},
9999
},
100100
})
@@ -154,7 +154,7 @@ func TestAccFilestoreInstance_filestoreInstanceProtocolExample(t *testing.T) {
154154
ResourceName: "google_filestore_instance.instance",
155155
ImportState: true,
156156
ImportStateVerify: true,
157-
ImportStateVerifyIgnore: []string{"labels", "location", "name", "tags", "terraform_labels", "zone"},
157+
ImportStateVerifyIgnore: []string{"initial_replication", "labels", "location", "name", "tags", "terraform_labels", "zone"},
158158
},
159159
},
160160
})

google/services/filestore/resource_filestore_instance_test.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,3 +462,74 @@ tags = {`, name)
462462
l += fmt.Sprintf("}\n}")
463463
return r + l
464464
}
465+
466+
func TestAccFilestoreInstance_replication(t *testing.T) {
467+
t.Parallel()
468+
469+
context := map[string]interface{}{
470+
"random_suffix": acctest.RandString(t, 10),
471+
"location_1": "us-central1",
472+
"location_2": "us-west1",
473+
"tier": "ENTERPRISE",
474+
}
475+
acctest.VcrTest(t, resource.TestCase{
476+
PreCheck: func() { acctest.AccTestPreCheck(t) },
477+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
478+
CheckDestroy: testAccCheckFilestoreInstanceDestroyProducer(t),
479+
Steps: []resource.TestStep{
480+
{
481+
Config: testAccFilestoreInstance_replication(context),
482+
},
483+
{
484+
ResourceName: "google_filestore_instance.replica-instance",
485+
ImportState: true,
486+
ImportStateVerify: true,
487+
ImportStateVerifyIgnore: []string{"zone", "initial_replication"},
488+
},
489+
},
490+
})
491+
}
492+
493+
func testAccFilestoreInstance_replication(context map[string]interface{}) string {
494+
return acctest.Nprintf(`
495+
resource "google_filestore_instance" "instance" {
496+
name = "tf-instance-%{random_suffix}"
497+
location = "%{location_1}"
498+
tier = "%{tier}"
499+
description = "An instance created during testing."
500+
501+
file_shares {
502+
capacity_gb = 1024
503+
name = "share"
504+
}
505+
506+
networks {
507+
network = "default"
508+
modes = ["MODE_IPV4"]
509+
}
510+
}
511+
512+
resource "google_filestore_instance" "replica-instance" {
513+
name = "tf-rinstance-%{random_suffix}"
514+
location = "%{location_2}"
515+
tier = "%{tier}"
516+
description = "An replica instance created during testing."
517+
518+
file_shares {
519+
capacity_gb = 1024
520+
name = "share"
521+
}
522+
523+
networks {
524+
network = "default"
525+
modes = ["MODE_IPV4"]
526+
}
527+
528+
initial_replication {
529+
replicas {
530+
peer_instance = google_filestore_instance.instance.id
531+
}
532+
}
533+
}
534+
`, context)
535+
}

website/docs/r/filestore_instance.html.markdown

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,12 @@ The following arguments are supported:
322322
will trigger recreation. To apply tags to an existing
323323
resource, see the `google_tags_tag_value` resource.
324324

325+
* `initial_replication` -
326+
(Optional)
327+
Replication configuration, once set, this cannot be updated.
328+
Addtionally this should be specified on the replica instance only, indicating the active as the peer_instance
329+
Structure is [documented below](#nested_initial_replication).
330+
325331
* `zone` -
326332
(Optional, Deprecated)
327333
The name of the Filestore zone of the instance.
@@ -369,6 +375,26 @@ The following arguments are supported:
369375
The number of IOPS to provision for the instance.
370376
max_iops must be in multiple of 1000.
371377

378+
<a name="nested_initial_replication"></a>The `initial_replication` block supports:
379+
380+
* `role` -
381+
(Optional)
382+
The replication role.
383+
Default value is `STANDBY`.
384+
Possible values are: `ROLE_UNSPECIFIED`, `ACTIVE`, `STANDBY`.
385+
386+
* `replicas` -
387+
(Optional)
388+
The replication role.
389+
Structure is [documented below](#nested_initial_replication_replicas).
390+
391+
392+
<a name="nested_initial_replication_replicas"></a>The `replicas` block supports:
393+
394+
* `peer_instance` -
395+
(Required)
396+
The peer instance.
397+
372398
## Attributes Reference
373399

374400
In addition to the arguments listed above, the following computed attributes are exported:
@@ -382,6 +408,10 @@ In addition to the arguments listed above, the following computed attributes are
382408
Server-specified ETag for the instance resource to prevent
383409
simultaneous updates from overwriting each other.
384410

411+
* `effective_replication` -
412+
Output only fields for replication configuration.
413+
Structure is [documented below](#nested_effective_replication).
414+
385415
* `terraform_labels` -
386416
The combination of labels configured directly on the resource
387417
and default labels configured on the provider.
@@ -390,6 +420,30 @@ In addition to the arguments listed above, the following computed attributes are
390420
All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services.
391421

392422

423+
<a name="nested_effective_replication"></a>The `effective_replication` block contains:
424+
425+
* `replicas` -
426+
(Optional)
427+
The replication role.
428+
Structure is [documented below](#nested_effective_replication_replicas).
429+
430+
431+
<a name="nested_effective_replication_replicas"></a>The `replicas` block supports:
432+
433+
* `state` -
434+
(Output)
435+
Output only. The replica state
436+
437+
* `state_reasons` -
438+
(Output)
439+
Output only. Additional information about the replication state, if available.
440+
441+
* `last_active_sync_time` -
442+
(Output)
443+
Output only. The timestamp of the latest replication snapshot taken on the active instance and is already replicated safely.
444+
A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits.
445+
Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z"
446+
393447
## Timeouts
394448

395449
This resource provides the following

0 commit comments

Comments
 (0)