Skip to content

Commit

Permalink
Redis cluster Multi vpc support (#12548) (#20977)
Browse files Browse the repository at this point in the history
[upstream:f7be33fce8fb1b020bba9f16fed20fe48b9e3d12]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Jan 21, 2025
1 parent dd1da30 commit ae715aa
Show file tree
Hide file tree
Showing 8 changed files with 1,636 additions and 36 deletions.
6 changes: 6 additions & 0 deletions .changelog/12548.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
```release-note:new-resource
`google_redis_cluster_user_created_connections`
```
```release-note:enhancement
redis: added `psc_service_attachments` field to `google_redis_cluster` resource, to enable use of the fine-grained resource `google_redis_cluster_user_created_connections`
```
5 changes: 3 additions & 2 deletions google/provider/provider_mmv1_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,9 @@ var handwrittenIAMDatasources = map[string]*schema.Resource{
}

// Resources
// Generated resources: 511
// Generated resources: 512
// Generated IAM resources: 270
// Total generated resources: 781
// Total generated resources: 782
var generatedResources = map[string]*schema.Resource{
"google_folder_access_approval_settings": accessapproval.ResourceAccessApprovalFolderSettings(),
"google_organization_access_approval_settings": accessapproval.ResourceAccessApprovalOrganizationSettings(),
Expand Down Expand Up @@ -1113,6 +1113,7 @@ var generatedResources = map[string]*schema.Resource{
"google_pubsub_lite_subscription": pubsublite.ResourcePubsubLiteSubscription(),
"google_pubsub_lite_topic": pubsublite.ResourcePubsubLiteTopic(),
"google_redis_cluster": redis.ResourceRedisCluster(),
"google_redis_cluster_user_created_connections": redis.ResourceRedisClusterUserCreatedConnections(),
"google_redis_instance": redis.ResourceRedisInstance(),
"google_resource_manager_lien": resourcemanager.ResourceResourceManagerLien(),
"google_secret_manager_secret": secretmanager.ResourceSecretManagerSecret(),
Expand Down
86 changes: 68 additions & 18 deletions google/services/redis/resource_redis_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,6 @@ func ResourceRedisCluster() *schema.Resource {
Description: `Unique name of the resource in this scope including project and location using the form:
projects/{projectId}/locations/{locationId}/clusters/{clusterId}`,
},
"psc_configs": {
Type: schema.TypeList,
Required: true,
Description: `Required. Each PscConfig configures the consumer network where two
network addresses will be designated to the cluster for client access.
Currently, only one PscConfig is supported.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"network": {
Type: schema.TypeString,
Required: true,
Description: `Required. The consumer network where the network address of
the discovery endpoint will be reserved, in the form of
projects/{network_project_id_or_number}/global/networks/{network_id}.`,
},
},
},
},
"shard_count": {
Type: schema.TypeInt,
Required: true,
Expand Down Expand Up @@ -398,6 +380,24 @@ If not provided, the current time will be used.`,
},
},
},
"psc_configs": {
Type: schema.TypeList,
Optional: true,
Description: `Required. Each PscConfig configures the consumer network where two
network addresses will be designated to the cluster for client access.
Currently, only one PscConfig is supported.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"network": {
Type: schema.TypeString,
Required: true,
Description: `Required. The consumer network where the network address of
the discovery endpoint will be reserved, in the form of
projects/{network_project_id_or_number}/global/networks/{network_id}.`,
},
},
},
},
"redis_configs": {
Type: schema.TypeMap,
Optional: true,
Expand Down Expand Up @@ -429,6 +429,7 @@ If not provided, encryption is disabled for the cluster. Default value: "TRANSIT
},
"zone_distribution_config": {
Type: schema.TypeList,
Computed: true,
Optional: true,
ForceNew: true,
Description: `Immutable. Zone distribution config for Memorystore Redis cluster.`,
Expand Down Expand Up @@ -567,6 +568,25 @@ resolution and up to nine fractional digits.`,
},
},
},
"psc_service_attachments": {
Type: schema.TypeList,
Computed: true,
Description: `Service attachment details to configure Psc connections.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"connection_type": {
Type: schema.TypeString,
Computed: true,
Description: `Type of a PSC connection targeting this service attachment.`,
},
"service_attachment": {
Type: schema.TypeString,
Computed: true,
Description: `Service attachment URI which your self-created PscConnection should use as`,
},
},
},
},
"size_gb": {
Type: schema.TypeInt,
Computed: true,
Expand Down Expand Up @@ -869,6 +889,9 @@ func resourceRedisClusterRead(d *schema.ResourceData, meta interface{}) error {
if err := d.Set("cross_cluster_replication_config", flattenRedisClusterCrossClusterReplicationConfig(res["crossClusterReplicationConfig"], d, config)); err != nil {
return fmt.Errorf("Error reading Cluster: %s", err)
}
if err := d.Set("psc_service_attachments", flattenRedisClusterPscServiceAttachments(res["pscServiceAttachments"], d, config)); err != nil {
return fmt.Errorf("Error reading Cluster: %s", err)
}

return nil
}
Expand Down Expand Up @@ -1741,6 +1764,33 @@ func flattenRedisClusterCrossClusterReplicationConfigUpdateTime(v interface{}, d
return v
}

func flattenRedisClusterPscServiceAttachments(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return v
}
l := v.([]interface{})
transformed := make([]interface{}, 0, len(l))
for _, raw := range l {
original := raw.(map[string]interface{})
if len(original) < 1 {
// Do not include empty json objects coming back from the api
continue
}
transformed = append(transformed, map[string]interface{}{
"service_attachment": flattenRedisClusterPscServiceAttachmentsServiceAttachment(original["serviceAttachment"], d, config),
"connection_type": flattenRedisClusterPscServiceAttachmentsConnectionType(original["connectionType"], d, config),
})
}
return transformed
}
func flattenRedisClusterPscServiceAttachmentsServiceAttachment(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

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

func expandRedisClusterAuthorizationMode(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
Expand Down
Loading

0 comments on commit ae715aa

Please sign in to comment.