Skip to content

Adding Memorystore import sources #9753

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/13577.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
memorystore: added `managed_backup_source` and ` gcs_source` fields to `google_memorystore_instance`
```
113 changes: 113 additions & 0 deletions google-beta/services/memorystore/resource_memorystore_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,29 @@ A duration in seconds with up to nine fractional digits, ending with 's'. Exampl
Optional: true,
Description: `Optional. Engine version of the instance.`,
},
"gcs_source": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Description: `GCS source for the instance.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"uris": {
Type: schema.TypeSet,
Required: true,
ForceNew: true,
Description: `URIs of the GCS objects to import.
Example: gs://bucket1/object1, gs//bucket2/folder2/object2`,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Set: schema.HashString,
},
},
},
ConflictsWith: []string{"managed_backup_source"},
},
"labels": {
Type: schema.TypeMap,
Optional: true,
Expand Down Expand Up @@ -371,6 +394,24 @@ resolution and up to nine fractional digits.`,
},
},
},
"managed_backup_source": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Description: `Managed backup source for the instance.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"backup": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `Example: //memorystore.googleapis.com/projects/{project}/locations/{location}/backups/{backupId}. In this case, it assumes the backup is under memorystore.googleapis.com.`,
},
},
},
ConflictsWith: []string{"gcs_source"},
},
"mode": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -511,6 +552,12 @@ Ignored for MULTI_ZONE mode.`,
},
},
},
"backup_collection": {
Type: schema.TypeString,
Computed: true,
Description: `The backup collection full resource name.
Example: projects/{project}/locations/{location}/backupCollections/{collection}`,
},
"create_time": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -949,6 +996,18 @@ func resourceMemorystoreInstanceCreate(d *schema.ResourceData, meta interface{})
} else if v, ok := d.GetOkExists("mode"); !tpgresource.IsEmptyValue(reflect.ValueOf(modeProp)) && (ok || !reflect.DeepEqual(v, modeProp)) {
obj["mode"] = modeProp
}
gcsSourceProp, err := expandMemorystoreInstanceGcsSource(d.Get("gcs_source"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("gcs_source"); !tpgresource.IsEmptyValue(reflect.ValueOf(gcsSourceProp)) && (ok || !reflect.DeepEqual(v, gcsSourceProp)) {
obj["gcsSource"] = gcsSourceProp
}
managedBackupSourceProp, err := expandMemorystoreInstanceManagedBackupSource(d.Get("managed_backup_source"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("managed_backup_source"); !tpgresource.IsEmptyValue(reflect.ValueOf(managedBackupSourceProp)) && (ok || !reflect.DeepEqual(v, managedBackupSourceProp)) {
obj["managedBackupSource"] = managedBackupSourceProp
}
labelsProp, err := expandMemorystoreInstanceEffectiveLabels(d.Get("effective_labels"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -1175,6 +1234,9 @@ func resourceMemorystoreInstanceRead(d *schema.ResourceData, meta interface{}) e
if err := d.Set("psc_auto_connections", flattenMemorystoreInstancePscAutoConnections(res["pscAutoConnections"], d, config)); err != nil {
return fmt.Errorf("Error reading Instance: %s", err)
}
if err := d.Set("backup_collection", flattenMemorystoreInstanceBackupCollection(res["backupCollection"], d, config)); err != nil {
return fmt.Errorf("Error reading Instance: %s", err)
}
if err := d.Set("terraform_labels", flattenMemorystoreInstanceTerraformLabels(res["labels"], d, config)); err != nil {
return fmt.Errorf("Error reading Instance: %s", err)
}
Expand Down Expand Up @@ -2354,6 +2416,10 @@ func flattenMemorystoreInstancePscAutoConnectionsPort(v interface{}, d *schema.R
return v // let terraform core handle it otherwise
}

func flattenMemorystoreInstanceBackupCollection(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenMemorystoreInstanceTerraformLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return v
Expand Down Expand Up @@ -2993,6 +3059,53 @@ func expandMemorystoreInstanceMode(v interface{}, d tpgresource.TerraformResourc
return v, nil
}

func expandMemorystoreInstanceGcsSource(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
return nil, nil
}
raw := l[0]
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})

transformedUris, err := expandMemorystoreInstanceGcsSourceUris(original["uris"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedUris); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["uris"] = transformedUris
}

return transformed, nil
}

func expandMemorystoreInstanceGcsSourceUris(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
v = v.(*schema.Set).List()
return v, nil
}

func expandMemorystoreInstanceManagedBackupSource(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
return nil, nil
}
raw := l[0]
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})

transformedBackup, err := expandMemorystoreInstanceManagedBackupSourceBackup(original["backup"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedBackup); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["backup"] = transformedBackup
}

return transformed, nil
}

func expandMemorystoreInstanceManagedBackupSourceBackup(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandMemorystoreInstanceEffectiveLabels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
if v == nil {
return map[string]string{}, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ fields:
- field: 'authorization_mode'
- field: 'automated_backup_config.fixed_frequency_schedule.start_time.hours'
- field: 'automated_backup_config.retention'
- field: 'backup_collection'
- field: 'create_time'
- field: 'cross_instance_replication_config.instance_role'
- field: 'cross_instance_replication_config.membership.primary_instance.instance'
Expand Down Expand Up @@ -40,6 +41,7 @@ fields:
- field: 'endpoints.connections.psc_auto_connection.service_attachment'
- field: 'engine_configs'
- field: 'engine_version'
- field: 'gcs_source.uris'
- field: 'instance_id'
provider_only: true
- field: 'labels'
Expand All @@ -56,6 +58,7 @@ fields:
- field: 'maintenance_schedule.end_time'
- field: 'maintenance_schedule.schedule_deadline_time'
- field: 'maintenance_schedule.start_time'
- field: 'managed_backup_source.backup'
- field: 'mode'
- field: 'name'
- field: 'node_config.size_gb'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestAccMemorystoreInstance_memorystoreInstanceBasicExample(t *testing.T) {
ResourceName: "google_memorystore_instance.instance-basic",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"instance_id", "labels", "location", "terraform_labels"},
ImportStateVerifyIgnore: []string{"gcs_source", "instance_id", "labels", "location", "managed_backup_source", "terraform_labels"},
},
},
})
Expand Down Expand Up @@ -135,7 +135,7 @@ func TestAccMemorystoreInstance_memorystoreInstanceFullExample(t *testing.T) {
ResourceName: "google_memorystore_instance.instance-full",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"instance_id", "labels", "location", "terraform_labels"},
ImportStateVerifyIgnore: []string{"gcs_source", "instance_id", "labels", "location", "managed_backup_source", "terraform_labels"},
},
},
})
Expand Down Expand Up @@ -243,7 +243,7 @@ func TestAccMemorystoreInstance_memorystoreInstancePersistenceAofExample(t *test
ResourceName: "google_memorystore_instance.instance-persistence-aof",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"instance_id", "labels", "location", "terraform_labels"},
ImportStateVerifyIgnore: []string{"gcs_source", "instance_id", "labels", "location", "managed_backup_source", "terraform_labels"},
},
},
})
Expand Down Expand Up @@ -325,7 +325,7 @@ func TestAccMemorystoreInstance_memorystoreInstanceSecondaryInstanceExample(t *t
ResourceName: "google_memorystore_instance.secondary_instance",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"instance_id", "labels", "location", "terraform_labels"},
ImportStateVerifyIgnore: []string{"gcs_source", "instance_id", "labels", "location", "managed_backup_source", "terraform_labels"},
},
},
})
Expand Down
Loading