Skip to content

Commit 7a89d85

Browse files
filestore: fixed initial_replication config not being send in request body to API (#14023) (#23001)
[upstream:027afcedcdbc1e2b91abde1a782f3a11eb02b648] Signed-off-by: Modular Magician <[email protected]>
1 parent 1748e4e commit 7a89d85

File tree

5 files changed

+126
-11
lines changed

5 files changed

+126
-11
lines changed

.changelog/14023.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```release-note:enhancement
2+
filestore: added `effective_replication.role` and `effective_replication.replicas.peer_instance` fields to `google_filestore_instance` resource
3+
```
4+
5+
```release-note:bug
6+
filestore: fixed bug where `google_filestore_instance.initial_replication` field could not be set
7+
```

google/services/filestore/resource_filestore_instance.go

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ Possible values include: STANDARD, PREMIUM, BASIC_HDD, BASIC_SSD, HIGH_SCALE_SSD
239239
Optional: true,
240240
ForceNew: true,
241241
Description: `Replication configuration, once set, this cannot be updated.
242-
Addtionally this should be specified on the replica instance only, indicating the active as the peer_instance`,
242+
Additionally this should be specified on the replica instance only, indicating the active as the peer_instance`,
243243
MaxItems: 1,
244244
Elem: &schema.Resource{
245245
Schema: map[string]*schema.Schema{
@@ -407,6 +407,11 @@ resource, see the 'google_tags_tag_value' resource.`,
407407
A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits.
408408
Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z"`,
409409
},
410+
"peer_instance": {
411+
Type: schema.TypeString,
412+
Computed: true,
413+
Description: `The peer instance.`,
414+
},
410415
"state": {
411416
Type: schema.TypeString,
412417
Computed: true,
@@ -423,6 +428,11 @@ Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z"`,
423428
},
424429
},
425430
},
431+
"role": {
432+
Type: schema.TypeString,
433+
Computed: true,
434+
Description: `The replication role.`,
435+
},
426436
},
427437
},
428438
},
@@ -518,6 +528,12 @@ func resourceFilestoreInstanceCreate(d *schema.ResourceData, meta interface{}) e
518528
} else if v, ok := d.GetOkExists("tags"); !tpgresource.IsEmptyValue(reflect.ValueOf(tagsProp)) && (ok || !reflect.DeepEqual(v, tagsProp)) {
519529
obj["tags"] = tagsProp
520530
}
531+
replicationProp, err := expandFilestoreInstanceInitialReplication(d.Get("initial_replication"), d, config)
532+
if err != nil {
533+
return err
534+
} else if v, ok := d.GetOkExists("initial_replication"); !tpgresource.IsEmptyValue(reflect.ValueOf(replicationProp)) && (ok || !reflect.DeepEqual(v, replicationProp)) {
535+
obj["replication"] = replicationProp
536+
}
521537
labelsProp, err := expandFilestoreInstanceEffectiveLabels(d.Get("effective_labels"), d, config)
522538
if err != nil {
523539
return err
@@ -1202,10 +1218,16 @@ func flattenFilestoreInstanceEffectiveReplication(v interface{}, d *schema.Resou
12021218
return nil
12031219
}
12041220
transformed := make(map[string]interface{})
1221+
transformed["role"] =
1222+
flattenFilestoreInstanceEffectiveReplicationRole(original["role"], d, config)
12051223
transformed["replicas"] =
12061224
flattenFilestoreInstanceEffectiveReplicationReplicas(original["replicas"], d, config)
12071225
return []interface{}{transformed}
12081226
}
1227+
func flattenFilestoreInstanceEffectiveReplicationRole(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1228+
return v
1229+
}
1230+
12091231
func flattenFilestoreInstanceEffectiveReplicationReplicas(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
12101232
if v == nil {
12111233
return v
@@ -1219,13 +1241,18 @@ func flattenFilestoreInstanceEffectiveReplicationReplicas(v interface{}, d *sche
12191241
continue
12201242
}
12211243
transformed = append(transformed, map[string]interface{}{
1244+
"peer_instance": flattenFilestoreInstanceEffectiveReplicationReplicasPeerInstance(original["peerInstance"], d, config),
12221245
"state": flattenFilestoreInstanceEffectiveReplicationReplicasState(original["state"], d, config),
12231246
"state_reasons": flattenFilestoreInstanceEffectiveReplicationReplicasStateReasons(original["stateReasons"], d, config),
12241247
"last_active_sync_time": flattenFilestoreInstanceEffectiveReplicationReplicasLastActiveSyncTime(original["lastActiveSyncTime"], d, config),
12251248
})
12261249
}
12271250
return transformed
12281251
}
1252+
func flattenFilestoreInstanceEffectiveReplicationReplicasPeerInstance(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1253+
return v
1254+
}
1255+
12291256
func flattenFilestoreInstanceEffectiveReplicationReplicasState(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
12301257
return v
12311258
}
@@ -1559,6 +1586,62 @@ func expandFilestoreInstanceTags(v interface{}, d tpgresource.TerraformResourceD
15591586
return m, nil
15601587
}
15611588

1589+
func expandFilestoreInstanceInitialReplication(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1590+
l := v.([]interface{})
1591+
if len(l) == 0 || l[0] == nil {
1592+
return nil, nil
1593+
}
1594+
raw := l[0]
1595+
original := raw.(map[string]interface{})
1596+
transformed := make(map[string]interface{})
1597+
1598+
transformedRole, err := expandFilestoreInstanceInitialReplicationRole(original["role"], d, config)
1599+
if err != nil {
1600+
return nil, err
1601+
} else if val := reflect.ValueOf(transformedRole); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1602+
transformed["role"] = transformedRole
1603+
}
1604+
1605+
transformedReplicas, err := expandFilestoreInstanceInitialReplicationReplicas(original["replicas"], d, config)
1606+
if err != nil {
1607+
return nil, err
1608+
} else if val := reflect.ValueOf(transformedReplicas); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1609+
transformed["replicas"] = transformedReplicas
1610+
}
1611+
1612+
return transformed, nil
1613+
}
1614+
1615+
func expandFilestoreInstanceInitialReplicationRole(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1616+
return v, nil
1617+
}
1618+
1619+
func expandFilestoreInstanceInitialReplicationReplicas(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1620+
l := v.([]interface{})
1621+
req := make([]interface{}, 0, len(l))
1622+
for _, raw := range l {
1623+
if raw == nil {
1624+
continue
1625+
}
1626+
original := raw.(map[string]interface{})
1627+
transformed := make(map[string]interface{})
1628+
1629+
transformedPeerInstance, err := expandFilestoreInstanceInitialReplicationReplicasPeerInstance(original["peer_instance"], d, config)
1630+
if err != nil {
1631+
return nil, err
1632+
} else if val := reflect.ValueOf(transformedPeerInstance); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1633+
transformed["peerInstance"] = transformedPeerInstance
1634+
}
1635+
1636+
req = append(req, transformed)
1637+
}
1638+
return req, nil
1639+
}
1640+
1641+
func expandFilestoreInstanceInitialReplicationReplicasPeerInstance(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1642+
return v, nil
1643+
}
1644+
15621645
func expandFilestoreInstanceEffectiveLabels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
15631646
if v == nil {
15641647
return map[string]string{}, nil

google/services/filestore/resource_filestore_instance_generated_meta.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ fields:
1313
provider_only: true
1414
- field: 'effective_replication.replicas.last_active_sync_time'
1515
api_field: 'replication.replicas.last_active_sync_time'
16+
- field: 'effective_replication.replicas.peer_instance'
17+
api_field: 'replication.replicas.peer_instance'
1618
- field: 'effective_replication.replicas.state'
1719
api_field: 'replication.replicas.state'
1820
- field: 'effective_replication.replicas.state_reasons'
1921
api_field: 'replication.replicas.state_reasons'
22+
- field: 'effective_replication.role'
23+
api_field: 'replication.role'
2024
- field: 'etag'
2125
- field: 'file_shares.capacity_gb'
2226
- field: 'file_shares.name'
@@ -27,9 +31,9 @@ fields:
2731
- field: 'file_shares.nfs_export_options.squash_mode'
2832
- field: 'file_shares.source_backup'
2933
- field: 'initial_replication.replicas.peer_instance'
30-
provider_only: true
34+
api_field: 'replication.replicas.peer_instance'
3135
- field: 'initial_replication.role'
32-
provider_only: true
36+
api_field: 'replication.role'
3337
- field: 'kms_key_name'
3438
- field: 'labels'
3539
- field: 'location'

google/services/filestore/resource_filestore_instance_test.go

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ func TestAccFilestoreInstance_replication(t *testing.T) {
481481
"location_1": "us-east1",
482482
"location_2": "us-west1",
483483
"tier": "ENTERPRISE",
484+
"project": envvar.GetTestProjectFromEnv(),
484485
}
485486
acctest.VcrTest(t, resource.TestCase{
486487
PreCheck: func() { acctest.AccTestPreCheck(t) },
@@ -489,9 +490,21 @@ func TestAccFilestoreInstance_replication(t *testing.T) {
489490
Steps: []resource.TestStep{
490491
{
491492
Config: testAccFilestoreInstance_replication(context),
493+
Check: resource.ComposeTestCheckFunc(
494+
resource.TestCheckResourceAttr(
495+
"google_filestore_instance.replica_instance",
496+
"effective_replication.0.replicas.0.peer_instance",
497+
"projects/"+context["project"].(string)+"/locations/us-east1/instances/tf-test-source-instance-"+context["random_suffix"].(string),
498+
),
499+
resource.TestCheckResourceAttr(
500+
"google_filestore_instance.replica_instance",
501+
"effective_replication.0.role",
502+
"STANDBY",
503+
),
504+
),
492505
},
493506
{
494-
ResourceName: "google_filestore_instance.replica-instance",
507+
ResourceName: "google_filestore_instance.replica_instance",
495508
ImportState: true,
496509
ImportStateVerify: true,
497510
ImportStateVerifyIgnore: []string{"zone", "initial_replication"},
@@ -502,11 +515,11 @@ func TestAccFilestoreInstance_replication(t *testing.T) {
502515

503516
func testAccFilestoreInstance_replication(context map[string]interface{}) string {
504517
return acctest.Nprintf(`
505-
resource "google_filestore_instance" "instance" {
506-
name = "tf-test-instance-%{random_suffix}"
518+
resource "google_filestore_instance" "source_instance" {
519+
name = "tf-test-source-instance-%{random_suffix}"
507520
location = "%{location_1}"
508521
tier = "%{tier}"
509-
description = "An instance created during testing."
522+
description = "An source instance created during testing."
510523
511524
file_shares {
512525
capacity_gb = 1024
@@ -519,8 +532,8 @@ resource "google_filestore_instance" "instance" {
519532
}
520533
}
521534
522-
resource "google_filestore_instance" "replica-instance" {
523-
name = "tf-test-instance-%{random_suffix}"
535+
resource "google_filestore_instance" "replica_instance" {
536+
name = "tf-test-replica-instance-%{random_suffix}"
524537
location = "%{location_2}"
525538
tier = "%{tier}"
526539
description = "An replica instance created during testing."
@@ -537,7 +550,7 @@ resource "google_filestore_instance" "replica-instance" {
537550
538551
initial_replication {
539552
replicas {
540-
peer_instance = google_filestore_instance.instance.id
553+
peer_instance = google_filestore_instance.source_instance.id
541554
}
542555
}
543556
}

website/docs/r/filestore_instance.html.markdown

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ The following arguments are supported:
348348
* `initial_replication` -
349349
(Optional)
350350
Replication configuration, once set, this cannot be updated.
351-
Addtionally this should be specified on the replica instance only, indicating the active as the peer_instance
351+
Additionally this should be specified on the replica instance only, indicating the active as the peer_instance
352352
Structure is [documented below](#nested_initial_replication).
353353

354354
* `directory_services` -
@@ -486,6 +486,10 @@ In addition to the arguments listed above, the following computed attributes are
486486

487487
<a name="nested_effective_replication"></a>The `effective_replication` block contains:
488488

489+
* `role` -
490+
(Output)
491+
The replication role.
492+
489493
* `replicas` -
490494
(Optional)
491495
The replication role.
@@ -494,6 +498,10 @@ In addition to the arguments listed above, the following computed attributes are
494498

495499
<a name="nested_effective_replication_replicas"></a>The `replicas` block supports:
496500

501+
* `peer_instance` -
502+
(Output)
503+
The peer instance.
504+
497505
* `state` -
498506
(Output)
499507
Output only. The replica state

0 commit comments

Comments
 (0)