Skip to content
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

Added support for redis instance data source #6536

Closed
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
27 changes: 27 additions & 0 deletions google/data_source_google_redis_instance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package google

import "github.com/hashicorp/terraform-plugin-sdk/helper/schema"

func dataSourceGoogleRedisInstance() *schema.Resource {
// Generate datasource schema from resource
dsSchema := datasourceSchemaFromResourceSchema(resourceRedisInstance().Schema)

// Set 'Required' schema elements
addRequiredFieldsToSchema(dsSchema, "name")

// Set 'Optional' schema elements
addOptionalFieldsToSchema(dsSchema, "project", "region")

return &schema.Resource{
Read: dataSourceGoogleRedisInstanceRead,
Schema: dsSchema,
}
}

func dataSourceGoogleRedisInstanceRead(d *schema.ResourceData, meta interface{}) error {
instanceName := d.Get("name").(string)

d.SetId(instanceName)

return resourceRedisInstanceRead(d, meta)
}
39 changes: 39 additions & 0 deletions google/data_source_google_redis_instance_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package google

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccRedisInstanceDatasource_basic(t *testing.T) {
t.Parallel()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccRedisInstanceDatasourceConfig(randString(t, 10)),
Check: resource.ComposeTestCheckFunc(
checkDataSourceStateMatchesResourceState("data.google_redis_instance.redis", "google_redis_instance.redis"),
),
},
},
})
}

func testAccRedisInstanceDatasourceConfig(suffix string) string {
return fmt.Sprintf(`
resource "google_redis_instance" "redis" {
name = "redis-test-%s"
memory_size_gb = 1
region = "europe-west1"
}

data "google_redis_instance" "redis" {
name = "${google_redis_instance.redis.name}"
}
`, suffix)
}
1 change: 1 addition & 0 deletions google/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ func Provider() terraform.ResourceProvider {
"google_storage_project_service_account": dataSourceGoogleStorageProjectServiceAccount(),
"google_storage_transfer_project_service_account": dataSourceGoogleStorageTransferProjectServiceAccount(),
"google_tpu_tensorflow_versions": dataSourceTpuTensorflowVersions(),
"google_redis_instance": dataSourceGoogleRedisInstance(),
},

ResourcesMap: ResourceMap(),
Expand Down
46 changes: 46 additions & 0 deletions website/docs/d/datasource_google_redis_instance.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
subcategory: "Memorystore (Redis)"
layout: "google"
page_title: "Google: google_redis_instance"
sidebar_current: "docs-google-datasource-redis-instance"
description: |-
Get information about a Google Cloud Redis instance.
---

# google\_redis\_instance

Get information about a Google Cloud Redis instance. For more information see
the [official documentation](https://cloud.google.com/memorystore/docs/redis)
and [API](https://cloud.google.com/memorystore/docs/redis/apis).

## Example Usage

```hcl
data "google_redis_instance" "default" {
name = "my-redis-instance"
}
```

## Argument Reference

The following arguments are supported:

* `name` - (Required) The name of a Redis instance.

- - -

* `project` - (Optional) The project in which the resource belongs. If it
is not provided, the provider project is used.

* `region` - (Optional) The region in which the resource belongs. If it
is not provided, the provider region is used.


## Attributes Reference

The following attributes are exported:

* `host` - Hostname or IP address of the exposed Redis endpoint used by clients
to connect to the service.

* `port` - The port number of the exposed Redis endpoint.
10 changes: 10 additions & 0 deletions website/google.erb
Original file line number Diff line number Diff line change
Expand Up @@ -1797,6 +1797,16 @@
<li>
<a href="#">Memorystore (Redis)</a>
<ul class="nav">
<li>
<a href="#">Data Sources</a>
<ul class="nav nav-auto-expand">

<li>
<a href="/docs/providers/google/d/datasource_google_redis_instance.html">google_redis_instance</a>
</li>

</ul>
</li>
<li>
<a href="#">Resources</a>
<ul class="nav nav-auto-expand">
Expand Down