Skip to content

Fix redis authorized network and tests. The Redis API currently only accepts partial links. The tests weren't failing because they weren't actually using the network (oops). There were a few other test issues that I fixed while I was there. Fixes #1571. #1599

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
merged 1 commit into from
Jun 6, 2018
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
15 changes: 10 additions & 5 deletions google/resource_redis_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ func resourceRedisInstance() *schema.Resource {
ForceNew: true,
},
"authorized_network": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
DiffSuppressFunc: compareSelfLinkRelativePaths,
},
"display_name": {
Type: schema.TypeString,
Expand Down Expand Up @@ -556,7 +557,11 @@ func expandRedisInstanceAlternativeLocationId(v interface{}, d *schema.ResourceD
}

func expandRedisInstanceAuthorizedNetwork(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
return v, nil
fv, err := ParseNetworkFieldValue(v.(string), d, config)
if err != nil {
return nil, err
}
return fv.RelativeLink(), nil
}

func expandRedisInstanceDisplayName(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
Expand Down
37 changes: 33 additions & 4 deletions google/resource_redis_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package google

import (
"fmt"
"strings"
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)

func TestAccRedisInstance_basic(t *testing.T) {
Expand All @@ -16,7 +18,7 @@ func TestAccRedisInstance_basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeAddressDestroy,
CheckDestroy: testAccCheckRedisInstanceDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccRedisInstance_basic(name),
Expand All @@ -38,7 +40,7 @@ func TestAccRedisInstance_update(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeAddressDestroy,
CheckDestroy: testAccCheckRedisInstanceDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccRedisInstance_update(name),
Expand Down Expand Up @@ -69,7 +71,7 @@ func TestAccRedisInstance_full(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeAddressDestroy,
CheckDestroy: testAccCheckRedisInstanceDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccRedisInstance_full(name, network),
Expand All @@ -83,6 +85,31 @@ func TestAccRedisInstance_full(t *testing.T) {
})
}

func testAccCheckRedisInstanceDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)

for _, rs := range s.RootModule().Resources {
if rs.Type != "google_redis_instance" {
continue
}

redisIdParts := strings.Split(rs.Primary.ID, "/")
if len(redisIdParts) != 3 {
return fmt.Errorf("Unexpected resource ID %s, expected {project}/{region}/{name}", rs.Primary.ID)
}

project, region, inst := redisIdParts[0], redisIdParts[1], redisIdParts[2]

name := fmt.Sprintf("projects/%s/locations/%s/instances/%s", project, region, inst)
_, err := config.clientRedis.Projects.Locations.Get(name).Do()
if err == nil {
return fmt.Errorf("Redis instance still exists")
}
}

return nil
}

func testAccRedisInstance_basic(name string) string {
return fmt.Sprintf(`
resource "google_redis_instance" "test" {
Expand Down Expand Up @@ -130,6 +157,8 @@ resource "google_redis_instance" "test" {
tier = "STANDARD_HA"
memory_size_gb = 1

authorized_network = "${google_compute_network.test.self_link}"

region = "us-central1"
location_id = "us-central1-a"
alternative_location_id = "us-central1-f"
Expand All @@ -142,5 +171,5 @@ resource "google_redis_instance" "test" {
my_key = "my_val"
other_key = "other_val"
}
}`, name, network)
}`, network, name)
}