Skip to content

Commit e577547

Browse files
Add datasource for google_redis_cluster (#14340) (#23436)
[upstream:820410d7eea459af4364b1ad10ad32e643b06a36] Signed-off-by: Modular Magician <[email protected]>
1 parent 423ee1e commit e577547

File tree

5 files changed

+182
-0
lines changed

5 files changed

+182
-0
lines changed

.changelog/14340.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-datasource
2+
`google_redis_cluster`
3+
```

google/provider/provider_mmv1_resources.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ var handwrittenDatasources = map[string]*schema.Resource{
403403
"google_memorystore_instance": memorystore.DataSourceMemorystoreInstance(),
404404
"google_memcache_instance": memcache.DataSourceMemcacheInstance(),
405405
"google_redis_instance": redis.DataSourceGoogleRedisInstance(),
406+
"google_redis_cluster": redis.DataSourceRedisCluster(),
406407
"google_vertex_ai_index": vertexai.DataSourceVertexAIIndex(),
407408
"google_vmwareengine_cluster": vmwareengine.DataSourceVmwareengineCluster(),
408409
"google_vmwareengine_external_access_rule": vmwareengine.DataSourceVmwareengineExternalAccessRule(),
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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/redis/data_source_redis_cluster.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+
// Copyright (c) HashiCorp, Inc.
18+
// SPDX-License-Identifier: MPL-2.0
19+
package redis
20+
21+
import (
22+
"fmt"
23+
24+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
25+
"github.com/hashicorp/terraform-provider-google/google/tpgresource"
26+
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
27+
)
28+
29+
func DataSourceRedisCluster() *schema.Resource {
30+
// Generate datasource schema from resource
31+
dsSchema := tpgresource.DatasourceSchemaFromResourceSchema(ResourceRedisCluster().Schema)
32+
33+
// Set 'Required' schema elements
34+
tpgresource.AddRequiredFieldsToSchema(dsSchema, "name")
35+
// Set 'Optional' schema elements
36+
tpgresource.AddOptionalFieldsToSchema(dsSchema, "project", "region")
37+
38+
return &schema.Resource{
39+
Read: dataSourceRedisClusterRead,
40+
Schema: dsSchema,
41+
}
42+
}
43+
44+
func dataSourceRedisClusterRead(d *schema.ResourceData, meta interface{}) error {
45+
id, err := tpgresource.ReplaceVars(d, meta.(*transport_tpg.Config), "projects/{{project}}/locations/{{region}}/clusters/{{name}}")
46+
if err != nil {
47+
return fmt.Errorf("Error constructing id: %s", err)
48+
}
49+
d.SetId(id)
50+
51+
err = resourceRedisClusterRead(d, meta)
52+
if err != nil {
53+
return err
54+
}
55+
56+
if err := tpgresource.SetDataSourceLabels(d); err != nil {
57+
return err
58+
}
59+
60+
if d.Id() == "" {
61+
return fmt.Errorf("%s not found", id)
62+
}
63+
return nil
64+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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/redis/data_source_redis_cluster_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 redis_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+
)
25+
26+
func TestAccRedisClusterDatasource(t *testing.T) {
27+
t.Parallel()
28+
29+
context := map[string]interface{}{
30+
"random_suffix": acctest.RandString(t, 10),
31+
}
32+
33+
acctest.VcrTest(t, resource.TestCase{
34+
PreCheck: func() { acctest.AccTestPreCheck(t) },
35+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
36+
Steps: []resource.TestStep{
37+
{
38+
Config: testAccRedisClusterDatasourceConfig(context),
39+
Check: resource.ComposeTestCheckFunc(
40+
acctest.CheckDataSourceStateMatchesResourceState("data.google_redis_cluster.default", "google_redis_cluster.cluster"),
41+
),
42+
},
43+
},
44+
})
45+
}
46+
47+
func testAccRedisClusterDatasourceConfig(context map[string]interface{}) string {
48+
return acctest.Nprintf(`
49+
resource "google_redis_cluster" "cluster" {
50+
name = "tf-test-redis-cluster-%{random_suffix}"
51+
shard_count = 1
52+
region = "us-central1"
53+
deletion_protection_enabled = false
54+
55+
}
56+
57+
data "google_redis_cluster" "default" {
58+
name = google_redis_cluster.cluster.name
59+
region = "us-central1"
60+
}
61+
`, context)
62+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
# ----------------------------------------------------------------------------
3+
#
4+
# *** AUTO GENERATED CODE *** Type: Handwritten ***
5+
#
6+
# ----------------------------------------------------------------------------
7+
#
8+
# This code is generated by Magic Modules using the following:
9+
#
10+
# Source file: https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/website/docs/d/redis_cluster.html.markdown
11+
#
12+
# DO NOT EDIT this file directly. Any changes made to this file will be
13+
# overwritten during the next generation cycle.
14+
#
15+
# ----------------------------------------------------------------------------
16+
subcategory: "Memorystore (Redis)"
17+
description: |-
18+
Fetches the details of a Redis Cluster.
19+
---
20+
21+
# google_redis_cluster
22+
23+
Use this data source to get information about a Redis Cluster. For more details, see the [API documentation](https://cloud.google.com/memorystore/docs/cluster/reference/rest/v1/projects.locations.clusters).
24+
25+
## Example Usage
26+
27+
```hcl
28+
data "google_redis_cluster" "default" {
29+
name = "my-redis-cluster"
30+
region = "us-central1"
31+
}
32+
```
33+
34+
## Argument Reference
35+
36+
The following arguments are supported:
37+
38+
* `name` -
39+
(Required)
40+
The name of the Redis cluster.
41+
42+
* `region` -
43+
(Required)
44+
The region of the Redis cluster.
45+
46+
* `project` -
47+
(optional)
48+
The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
49+
50+
## Attributes Reference
51+
52+
See [google_redis_cluster](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/redis_cluster) resource for details of all the available attributes.

0 commit comments

Comments
 (0)