From 7b483c45579fa390106f4c791a0565e89f6111ac Mon Sep 17 00:00:00 2001 From: Nathan McKinley Date: Tue, 22 Oct 2019 23:05:33 +0000 Subject: [PATCH] Add description to service account. Signed-off-by: Modular Magician --- .../resource_cloudiot_registry_test.go | 40 +-- .../resource_compute_autoscaler_test.go | 121 +------ .../resource_compute_backend_service_test.go | 322 ++++-------------- google-beta/resource_compute_disk_test.go | 162 +++------ .../resource_compute_global_address_test.go | 65 ---- ...esource_compute_https_health_check_test.go | 83 +---- .../resource_google_service_account.go | 13 +- .../resource_google_service_account_test.go | 2 + 8 files changed, 159 insertions(+), 649 deletions(-) diff --git a/google-beta/resource_cloudiot_registry_test.go b/google-beta/resource_cloudiot_registry_test.go index f6bf7365b8..2468de1412 100644 --- a/google-beta/resource_cloudiot_registry_test.go +++ b/google-beta/resource_cloudiot_registry_test.go @@ -46,10 +46,6 @@ func TestAccCloudIoTRegistry_basic(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccCloudIoTRegistry_basic(registryName), - Check: resource.ComposeTestCheckFunc( - testAccCloudIoTRegistryExists( - "google_cloudiot_registry.foobar"), - ), }, { ResourceName: "google_cloudiot_registry.foobar", @@ -72,10 +68,6 @@ func TestAccCloudIoTRegistry_extended(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccCloudIoTRegistry_extended(registryName), - Check: resource.ComposeTestCheckFunc( - testAccCloudIoTRegistryExists( - "google_cloudiot_registry.foobar"), - ), }, { ResourceName: "google_cloudiot_registry.foobar", @@ -98,14 +90,20 @@ func TestAccCloudIoTRegistry_update(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccCloudIoTRegistry_basic(registryName), - Check: resource.ComposeTestCheckFunc( - testAccCloudIoTRegistryExists( - "google_cloudiot_registry.foobar"), - ), + }, + { + ResourceName: "google_cloudiot_registry.foobar", + ImportState: true, + ImportStateVerify: true, }, { Config: testAccCloudIoTRegistry_extended(registryName), }, + { + ResourceName: "google_cloudiot_registry.foobar", + ImportState: true, + ImportStateVerify: true, + }, { Config: testAccCloudIoTRegistry_basic(registryName), }, @@ -223,24 +221,6 @@ func testAccCheckCloudIoTRegistryDestroy(s *terraform.State) error { return nil } -func testAccCloudIoTRegistryExists(n string) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - if rs.Primary.ID == "" { - return fmt.Errorf("No ID is set") - } - config := testAccProvider.Meta().(*Config) - _, err := config.clientCloudIoT.Projects.Locations.Registries.Get(rs.Primary.ID).Do() - if err != nil { - return fmt.Errorf("Registry does not exist") - } - return nil - } -} - func testAccCloudIoTRegistry_basic(registryName string) string { return fmt.Sprintf(` resource "google_cloudiot_registry" "foobar" { diff --git a/google-beta/resource_compute_autoscaler_test.go b/google-beta/resource_compute_autoscaler_test.go index 9c05b7369e..8c1fe2e411 100644 --- a/google-beta/resource_compute_autoscaler_test.go +++ b/google-beta/resource_compute_autoscaler_test.go @@ -2,20 +2,15 @@ package google import ( "fmt" - "strings" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" - "google.golang.org/api/compute/v1" ) func TestAccComputeAutoscaler_update(t *testing.T) { t.Parallel() - var ascaler compute.Autoscaler - var it_name = fmt.Sprintf("autoscaler-test-%s", acctest.RandString(10)) var tp_name = fmt.Sprintf("autoscaler-test-%s", acctest.RandString(10)) var igm_name = fmt.Sprintf("autoscaler-test-%s", acctest.RandString(10)) @@ -28,19 +23,19 @@ func TestAccComputeAutoscaler_update(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccComputeAutoscaler_basic(it_name, tp_name, igm_name, autoscaler_name), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeAutoscalerExists( - "google_compute_autoscaler.foobar", &ascaler), - ), + }, + { + ResourceName: "google_compute_autoscaler.foobar", + ImportState: true, + ImportStateVerify: true, }, { Config: testAccComputeAutoscaler_update(it_name, tp_name, igm_name, autoscaler_name), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeAutoscalerExists( - "google_compute_autoscaler.foobar", &ascaler), - testAccCheckComputeAutoscalerUpdated( - "google_compute_autoscaler.foobar", 10), - ), + }, + { + ResourceName: "google_compute_autoscaler.foobar", + ImportState: true, + ImportStateVerify: true, }, }, }) @@ -61,7 +56,6 @@ func TestAccComputeAutoscaler_multicondition(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccComputeAutoscaler_multicondition(it_name, tp_name, igm_name, autoscaler_name), - Check: testAccCheckComputeAutoscalerMultifunction("google_compute_autoscaler.foobar"), }, { ResourceName: "google_compute_autoscaler.foobar", @@ -72,101 +66,6 @@ func TestAccComputeAutoscaler_multicondition(t *testing.T) { }) } -func testAccCheckComputeAutoscalerExists(n string, ascaler *compute.Autoscaler) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No ID is set") - } - - config := testAccProvider.Meta().(*Config) - - idParts := strings.Split(rs.Primary.ID, "/") - zone, name := idParts[0], idParts[1] - found, err := config.clientCompute.Autoscalers.Get( - config.Project, zone, name).Do() - if err != nil { - return err - } - - if found.Name != name { - return fmt.Errorf("Autoscaler not found") - } - - *ascaler = *found - - return nil - } -} - -func testAccCheckComputeAutoscalerMultifunction(n string) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No ID is set") - } - - config := testAccProvider.Meta().(*Config) - - idParts := strings.Split(rs.Primary.ID, "/") - zone, name := idParts[0], idParts[1] - found, err := config.clientCompute.Autoscalers.Get( - config.Project, zone, name).Do() - if err != nil { - return err - } - - if found.Name != name { - return fmt.Errorf("Autoscaler not found") - } - - if found.AutoscalingPolicy.CpuUtilization.UtilizationTarget == 0.5 && found.AutoscalingPolicy.LoadBalancingUtilization.UtilizationTarget == 0.5 { - return nil - } - return fmt.Errorf("Util target for CPU: %f, for LB: %f - should have been 0.5 for each.", - found.AutoscalingPolicy.CpuUtilization.UtilizationTarget, - found.AutoscalingPolicy.LoadBalancingUtilization.UtilizationTarget) - - } -} - -func testAccCheckComputeAutoscalerUpdated(n string, max int64) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No ID is set") - } - - config := testAccProvider.Meta().(*Config) - - idParts := strings.Split(rs.Primary.ID, "/") - zone, name := idParts[0], idParts[1] - ascaler, err := config.clientCompute.Autoscalers.Get( - config.Project, zone, name).Do() - if err != nil { - return err - } - - if ascaler.AutoscalingPolicy.MaxNumReplicas != max { - return fmt.Errorf("maximum replicas incorrect") - } - - return nil - } -} - func testAccComputeAutoscaler_scaffolding(it_name, tp_name, igm_name string) string { return fmt.Sprintf(` data "google_compute_image" "my_image" { diff --git a/google-beta/resource_compute_backend_service_test.go b/google-beta/resource_compute_backend_service_test.go index 99f8c102ee..06c85dd564 100644 --- a/google-beta/resource_compute_backend_service_test.go +++ b/google-beta/resource_compute_backend_service_test.go @@ -2,13 +2,10 @@ package google import ( "fmt" - "regexp" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" - "google.golang.org/api/compute/v1" ) func TestAccComputeBackendService_basic(t *testing.T) { @@ -17,7 +14,6 @@ func TestAccComputeBackendService_basic(t *testing.T) { serviceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) extraCheckName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - var svc compute.BackendService resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -26,18 +22,15 @@ func TestAccComputeBackendService_basic(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccComputeBackendService_basic(serviceName, checkName), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.foobar", &svc), - ), + }, + { + ResourceName: "google_compute_backend_service.foobar", + ImportState: true, + ImportStateVerify: true, }, { Config: testAccComputeBackendService_basicModified( serviceName, checkName, extraCheckName), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.foobar", &svc), - ), }, { ResourceName: "google_compute_backend_service.foobar", @@ -55,7 +48,6 @@ func TestAccComputeBackendService_withBackend(t *testing.T) { igName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) itName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - var svc compute.BackendService resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -64,18 +56,15 @@ func TestAccComputeBackendService_withBackend(t *testing.T) { { Config: testAccComputeBackendService_withBackend( serviceName, igName, itName, checkName, 10), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.lipsum", &svc), - ), + }, + { + ResourceName: "google_compute_backend_service.lipsum", + ImportState: true, + ImportStateVerify: true, }, { Config: testAccComputeBackendService_withBackend( serviceName, igName, itName, checkName, 20), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.lipsum", &svc), - ), }, { ResourceName: "google_compute_backend_service.lipsum", @@ -84,16 +73,6 @@ func TestAccComputeBackendService_withBackend(t *testing.T) { }, }, }) - - if svc.TimeoutSec != 20 { - t.Errorf("Expected TimeoutSec == 20, got %d", svc.TimeoutSec) - } - if svc.Protocol != "HTTP" { - t.Errorf("Expected Protocol to be HTTP, got %q", svc.Protocol) - } - if len(svc.Backends) != 1 { - t.Errorf("Expected 1 backend, got %d", len(svc.Backends)) - } } func TestAccComputeBackendService_withBackendAndIAP(t *testing.T) { @@ -101,7 +80,6 @@ func TestAccComputeBackendService_withBackendAndIAP(t *testing.T) { igName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) itName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - var svc compute.BackendService resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -110,10 +88,6 @@ func TestAccComputeBackendService_withBackendAndIAP(t *testing.T) { { Config: testAccComputeBackendService_withBackendAndIAP( serviceName, igName, itName, checkName, 10), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExistsWithIAP("google_compute_backend_service.lipsum", &svc), - resource.TestCheckResourceAttr("google_compute_backend_service.lipsum", "iap.0.oauth2_client_secret", "test"), - ), }, { ResourceName: "google_compute_backend_service.lipsum", @@ -124,24 +98,14 @@ func TestAccComputeBackendService_withBackendAndIAP(t *testing.T) { { Config: testAccComputeBackendService_withBackend( serviceName, igName, itName, checkName, 10), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExistsWithoutIAP( - "google_compute_backend_service.lipsum", &svc), - ), + }, + { + ResourceName: "google_compute_backend_service.lipsum", + ImportState: true, + ImportStateVerify: true, }, }, }) - - if svc.TimeoutSec != 10 { - t.Errorf("Expected TimeoutSec == 10, got %d", svc.TimeoutSec) - } - if svc.Protocol != "HTTP" { - t.Errorf("Expected Protocol to be HTTP, got %q", svc.Protocol) - } - if len(svc.Backends) != 1 { - t.Errorf("Expected 1 backend, got %d", len(svc.Backends)) - } - } func TestAccComputeBackendService_updatePreservesOptionalParameters(t *testing.T) { @@ -149,7 +113,6 @@ func TestAccComputeBackendService_updatePreservesOptionalParameters(t *testing.T serviceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - var svc compute.BackendService resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -159,25 +122,23 @@ func TestAccComputeBackendService_updatePreservesOptionalParameters(t *testing.T { Config: testAccComputeBackendService_withSessionAffinity( serviceName, checkName, "initial-description", "GENERATED_COOKIE"), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.foobar", &svc), - ), + }, + { + ResourceName: "google_compute_backend_service.foobar", + ImportState: true, + ImportStateVerify: true, }, { Config: testAccComputeBackendService_withSessionAffinity( serviceName, checkName, "updated-description", "GENERATED_COOKIE"), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.foobar", &svc), - ), + }, + { + ResourceName: "google_compute_backend_service.foobar", + ImportState: true, + ImportStateVerify: true, }, }, }) - - if svc.SessionAffinity != "GENERATED_COOKIE" { - t.Errorf("Expected SessionAffinity == \"GENERATED_COOKIE\", got %s", svc.SessionAffinity) - } } func TestAccComputeBackendService_withConnectionDraining(t *testing.T) { @@ -185,7 +146,6 @@ func TestAccComputeBackendService_withConnectionDraining(t *testing.T) { serviceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - var svc compute.BackendService resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -194,10 +154,6 @@ func TestAccComputeBackendService_withConnectionDraining(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccComputeBackendService_withConnectionDraining(serviceName, checkName, 10), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.foobar", &svc), - ), }, { ResourceName: "google_compute_backend_service.foobar", @@ -206,10 +162,6 @@ func TestAccComputeBackendService_withConnectionDraining(t *testing.T) { }, }, }) - - if svc.ConnectionDraining.DrainingTimeoutSec != 10 { - t.Errorf("Expected ConnectionDraining.DrainingTimeoutSec == 10, got %d", svc.ConnectionDraining.DrainingTimeoutSec) - } } func TestAccComputeBackendService_withConnectionDrainingAndUpdate(t *testing.T) { @@ -217,7 +169,6 @@ func TestAccComputeBackendService_withConnectionDrainingAndUpdate(t *testing.T) serviceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - var svc compute.BackendService resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -226,24 +177,22 @@ func TestAccComputeBackendService_withConnectionDrainingAndUpdate(t *testing.T) Steps: []resource.TestStep{ { Config: testAccComputeBackendService_withConnectionDraining(serviceName, checkName, 10), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.foobar", &svc), - ), + }, + { + ResourceName: "google_compute_backend_service.foobar", + ImportState: true, + ImportStateVerify: true, }, { Config: testAccComputeBackendService_basic(serviceName, checkName), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.foobar", &svc), - ), + }, + { + ResourceName: "google_compute_backend_service.foobar", + ImportState: true, + ImportStateVerify: true, }, }, }) - - if svc.ConnectionDraining.DrainingTimeoutSec != 300 { - t.Errorf("Expected ConnectionDraining.DrainingTimeoutSec == 300, got %d", svc.ConnectionDraining.DrainingTimeoutSec) - } } func TestAccComputeBackendService_withHttpsHealthCheck(t *testing.T) { @@ -251,7 +200,6 @@ func TestAccComputeBackendService_withHttpsHealthCheck(t *testing.T) { serviceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - var svc compute.BackendService resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -260,10 +208,6 @@ func TestAccComputeBackendService_withHttpsHealthCheck(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccComputeBackendService_withHttpsHealthCheck(serviceName, checkName), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.foobar", &svc), - ), }, { ResourceName: "google_compute_backend_service.foobar", @@ -279,7 +223,6 @@ func TestAccComputeBackendService_withCdnPolicy(t *testing.T) { serviceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - var svc compute.BackendService resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -288,10 +231,6 @@ func TestAccComputeBackendService_withCdnPolicy(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccComputeBackendService_withCdnPolicy(serviceName, checkName), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.foobar", &svc), - ), }, { ResourceName: "google_compute_backend_service.foobar", @@ -308,7 +247,6 @@ func TestAccComputeBackendService_withSecurityPolicy(t *testing.T) { serviceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) polName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - var svc compute.BackendService resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -317,11 +255,6 @@ func TestAccComputeBackendService_withSecurityPolicy(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccComputeBackendService_withSecurityPolicy(serviceName, checkName, polName, "${google_compute_security_policy.policy.self_link}"), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.foobar", &svc), - resource.TestMatchResourceAttr("google_compute_backend_service.foobar", "security_policy", regexp.MustCompile(polName)), - ), }, { ResourceName: "google_compute_backend_service.foobar", @@ -340,106 +273,11 @@ func TestAccComputeBackendService_withSecurityPolicy(t *testing.T) { }) } -func testAccCheckComputeBackendServiceExists(n string, svc *compute.BackendService) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No ID is set") - } - - config := testAccProvider.Meta().(*Config) - - found, err := config.clientCompute.BackendServices.Get( - config.Project, rs.Primary.ID).Do() - if err != nil { - return err - } - - if found.Name != rs.Primary.ID { - return fmt.Errorf("Backend service %s not found", rs.Primary.ID) - } - - *svc = *found - - return nil - } -} - -func testAccCheckComputeBackendServiceExistsWithIAP(n string, svc *compute.BackendService) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No ID is set") - } - - config := testAccProvider.Meta().(*Config) - - found, err := config.clientCompute.BackendServices.Get( - config.Project, rs.Primary.ID).Do() - if err != nil { - return err - } - - if found.Name != rs.Primary.ID { - return fmt.Errorf("Backend service %s not found", rs.Primary.ID) - } - - if found.Iap == nil || found.Iap.Enabled == false { - return fmt.Errorf("IAP not found or not enabled. Saw %v", found.Iap) - } - - *svc = *found - - return nil - } -} - -func testAccCheckComputeBackendServiceExistsWithoutIAP(n string, svc *compute.BackendService) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No ID is set") - } - - config := testAccProvider.Meta().(*Config) - - found, err := config.clientCompute.BackendServices.Get( - config.Project, rs.Primary.ID).Do() - if err != nil { - return err - } - - if found.Name != rs.Primary.ID { - return fmt.Errorf("Backend service %s not found", rs.Primary.ID) - } - - if found.Iap != nil && found.Iap.Enabled == true { - return fmt.Errorf("IAP enabled when it should be disabled") - } - - *svc = *found - - return nil - } -} func TestAccComputeBackendService_withCDNEnabled(t *testing.T) { t.Parallel() serviceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - var svc compute.BackendService resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -449,17 +287,14 @@ func TestAccComputeBackendService_withCDNEnabled(t *testing.T) { { Config: testAccComputeBackendService_withCDNEnabled( serviceName, checkName), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.foobar", &svc), - ), + }, + { + ResourceName: "google_compute_backend_service.foobar", + ImportState: true, + ImportStateVerify: true, }, }, }) - - if svc.EnableCDN != true { - t.Errorf("Expected EnableCDN == true, got %t", svc.EnableCDN) - } } func TestAccComputeBackendService_withSessionAffinity(t *testing.T) { @@ -467,7 +302,6 @@ func TestAccComputeBackendService_withSessionAffinity(t *testing.T) { serviceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - var svc compute.BackendService resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -477,25 +311,23 @@ func TestAccComputeBackendService_withSessionAffinity(t *testing.T) { { Config: testAccComputeBackendService_withSessionAffinity( serviceName, checkName, "description", "CLIENT_IP"), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.foobar", &svc), - ), + }, + { + ResourceName: "google_compute_backend_service.foobar", + ImportState: true, + ImportStateVerify: true, }, { Config: testAccComputeBackendService_withSessionAffinity( serviceName, checkName, "description", "GENERATED_COOKIE"), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.foobar", &svc), - ), + }, + { + ResourceName: "google_compute_backend_service.foobar", + ImportState: true, + ImportStateVerify: true, }, }, }) - - if svc.SessionAffinity != "GENERATED_COOKIE" { - t.Errorf("Expected SessionAffinity == \"GENERATED_COOKIE\", got %s", svc.SessionAffinity) - } } func TestAccComputeBackendService_withAffinityCookieTtlSec(t *testing.T) { @@ -503,7 +335,6 @@ func TestAccComputeBackendService_withAffinityCookieTtlSec(t *testing.T) { serviceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - var svc compute.BackendService resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -513,21 +344,14 @@ func TestAccComputeBackendService_withAffinityCookieTtlSec(t *testing.T) { { Config: testAccComputeBackendService_withAffinityCookieTtlSec( serviceName, checkName, "description", "GENERATED_COOKIE", 300), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.foobar", &svc), - ), + }, + { + ResourceName: "google_compute_backend_service.foobar", + ImportState: true, + ImportStateVerify: true, }, }, }) - - if svc.SessionAffinity != "GENERATED_COOKIE" { - t.Errorf("Expected SessionAffinity == \"GENERATED_COOKIE\", got %s", svc.SessionAffinity) - } - - if svc.AffinityCookieTtlSec != 300 { - t.Errorf("Expected AffinityCookieTtlSec == 300, got %v", svc.AffinityCookieTtlSec) - } } func TestAccComputeBackendService_withMaxConnections(t *testing.T) { @@ -538,7 +362,6 @@ func TestAccComputeBackendService_withMaxConnections(t *testing.T) { itName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - var svc compute.BackendService resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -547,18 +370,15 @@ func TestAccComputeBackendService_withMaxConnections(t *testing.T) { { Config: testAccComputeBackendService_withMaxConnections( serviceName, igName, itName, checkName, 10), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.lipsum", &svc), - ), + }, + { + ResourceName: "google_compute_backend_service.lipsum", + ImportState: true, + ImportStateVerify: true, }, { Config: testAccComputeBackendService_withMaxConnections( serviceName, igName, itName, checkName, 20), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.lipsum", &svc), - ), }, { ResourceName: "google_compute_backend_service.lipsum", @@ -567,10 +387,6 @@ func TestAccComputeBackendService_withMaxConnections(t *testing.T) { }, }, }) - - if svc.Backends[0].MaxConnections != 20 { - t.Errorf("Expected MaxConnections == 20, got %d", svc.Backends[0].MaxConnections) - } } func TestAccComputeBackendService_withMaxConnectionsPerInstance(t *testing.T) { @@ -581,7 +397,6 @@ func TestAccComputeBackendService_withMaxConnectionsPerInstance(t *testing.T) { itName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - var svc compute.BackendService resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -590,18 +405,15 @@ func TestAccComputeBackendService_withMaxConnectionsPerInstance(t *testing.T) { { Config: testAccComputeBackendService_withMaxConnectionsPerInstance( serviceName, igName, itName, checkName, 10), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.lipsum", &svc), - ), + }, + { + ResourceName: "google_compute_backend_service.lipsum", + ImportState: true, + ImportStateVerify: true, }, { Config: testAccComputeBackendService_withMaxConnectionsPerInstance( serviceName, igName, itName, checkName, 20), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.lipsum", &svc), - ), }, { ResourceName: "google_compute_backend_service.lipsum", @@ -610,10 +422,6 @@ func TestAccComputeBackendService_withMaxConnectionsPerInstance(t *testing.T) { }, }, }) - - if svc.Backends[0].MaxConnectionsPerInstance != 20 { - t.Errorf("Expected MaxConnectionsPerInstance == 20, got %d", svc.Backends[0].MaxConnectionsPerInstance) - } } func TestAccComputeBackendService_withMaxRatePerEndpoint(t *testing.T) { diff --git a/google-beta/resource_compute_disk_test.go b/google-beta/resource_compute_disk_test.go index c3b3443ff7..557562406f 100644 --- a/google-beta/resource_compute_disk_test.go +++ b/google-beta/resource_compute_disk_test.go @@ -4,7 +4,6 @@ import ( "fmt" "os" "regexp" - "strconv" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" @@ -225,7 +224,6 @@ func TestAccComputeDisk_update(t *testing.T) { t.Parallel() diskName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - var disk compute.Disk resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -233,24 +231,19 @@ func TestAccComputeDisk_update(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccComputeDisk_basic(diskName), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeDiskExists( - "google_compute_disk.foobar", getTestProjectFromEnv(), &disk), - resource.TestCheckResourceAttr("google_compute_disk.foobar", "size", "50"), - testAccCheckComputeDiskHasLabel(&disk, "my-label", "my-label-value"), - testAccCheckComputeDiskHasLabelFingerprint(&disk, "google_compute_disk.foobar"), - ), + }, + { + ResourceName: "google_compute_disk.foobar", + ImportState: true, + ImportStateVerify: true, }, { Config: testAccComputeDisk_updated(diskName), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeDiskExists( - "google_compute_disk.foobar", getTestProjectFromEnv(), &disk), - resource.TestCheckResourceAttr("google_compute_disk.foobar", "size", "100"), - testAccCheckComputeDiskHasLabel(&disk, "my-label", "my-updated-label-value"), - testAccCheckComputeDiskHasLabel(&disk, "a-new-label", "a-new-label-value"), - testAccCheckComputeDiskHasLabelFingerprint(&disk, "google_compute_disk.foobar"), - ), + }, + { + ResourceName: "google_compute_disk.foobar", + ImportState: true, + ImportStateVerify: true, }, }, }) @@ -264,8 +257,6 @@ func TestAccComputeDisk_fromSnapshot(t *testing.T) { snapshotName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) projectName := getTestProjectFromEnv() - var disk compute.Disk - resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -273,17 +264,19 @@ func TestAccComputeDisk_fromSnapshot(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccComputeDisk_fromSnapshot(projectName, firstDiskName, snapshotName, diskName, "self_link"), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeDiskExists( - "google_compute_disk.seconddisk", getTestProjectFromEnv(), &disk), - ), + }, + { + ResourceName: "google_compute_disk.seconddisk", + ImportState: true, + ImportStateVerify: true, }, { Config: testAccComputeDisk_fromSnapshot(projectName, firstDiskName, snapshotName, diskName, "name"), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeDiskExists( - "google_compute_disk.seconddisk", getTestProjectFromEnv(), &disk), - ), + }, + { + ResourceName: "google_compute_disk.seconddisk", + ImportState: true, + ImportStateVerify: true, }, }, }) @@ -351,7 +344,6 @@ func TestAccComputeDisk_deleteDetach(t *testing.T) { diskName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) instanceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - var disk compute.Disk resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -360,10 +352,11 @@ func TestAccComputeDisk_deleteDetach(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccComputeDisk_deleteDetach(instanceName, diskName), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeDiskExists( - "google_compute_disk.foo", getTestProjectFromEnv(), &disk), - ), + }, + { + ResourceName: "google_compute_disk.foo", + ImportState: true, + ImportStateVerify: true, }, // this needs to be a second step so we refresh and see the instance // listed as attached to the disk; the instance is created after the @@ -371,12 +364,11 @@ func TestAccComputeDisk_deleteDetach(t *testing.T) { // another step { Config: testAccComputeDisk_deleteDetach(instanceName, diskName), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeDiskExists( - "google_compute_disk.foo", getTestProjectFromEnv(), &disk), - testAccCheckComputeDiskInstances( - "google_compute_disk.foo", &disk), - ), + }, + { + ResourceName: "google_compute_disk.foo", + ImportState: true, + ImportStateVerify: true, }, }, }) @@ -388,7 +380,6 @@ func TestAccComputeDisk_deleteDetachIGM(t *testing.T) { diskName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) diskName2 := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) mgrName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - var disk compute.Disk resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -397,10 +388,11 @@ func TestAccComputeDisk_deleteDetachIGM(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccComputeDisk_deleteDetachIGM(diskName, mgrName), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeDiskExists( - "google_compute_disk.foo", getTestProjectFromEnv(), &disk), - ), + }, + { + ResourceName: "google_compute_disk.foo", + ImportState: true, + ImportStateVerify: true, }, // this needs to be a second step so we refresh and see the instance // listed as attached to the disk; the instance is created after the @@ -408,30 +400,29 @@ func TestAccComputeDisk_deleteDetachIGM(t *testing.T) { // another step { Config: testAccComputeDisk_deleteDetachIGM(diskName, mgrName), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeDiskExists( - "google_compute_disk.foo", getTestProjectFromEnv(), &disk), - testAccCheckComputeDiskInstances( - "google_compute_disk.foo", &disk), - ), + }, + { + ResourceName: "google_compute_disk.foo", + ImportState: true, + ImportStateVerify: true, }, // Change the disk name to recreate the instances { Config: testAccComputeDisk_deleteDetachIGM(diskName2, mgrName), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeDiskExists( - "google_compute_disk.foo", getTestProjectFromEnv(), &disk), - ), + }, + { + ResourceName: "google_compute_disk.foo", + ImportState: true, + ImportStateVerify: true, }, // Add the extra step like before { Config: testAccComputeDisk_deleteDetachIGM(diskName2, mgrName), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeDiskExists( - "google_compute_disk.foo", getTestProjectFromEnv(), &disk), - testAccCheckComputeDiskInstances( - "google_compute_disk.foo", &disk), - ), + }, + { + ResourceName: "google_compute_disk.foo", + ImportState: true, + ImportStateVerify: true, }, }, }) @@ -488,37 +479,6 @@ func testAccCheckComputeDiskExists(n, p string, disk *compute.Disk) resource.Tes } } -func testAccCheckComputeDiskHasLabel(disk *compute.Disk, key, value string) resource.TestCheckFunc { - return func(s *terraform.State) error { - val, ok := disk.Labels[key] - if !ok { - return fmt.Errorf("Label with key %s not found", key) - } - - if val != value { - return fmt.Errorf("Label value did not match for key %s: expected %s but found %s", key, value, val) - } - return nil - } -} - -func testAccCheckComputeDiskHasLabelFingerprint(disk *compute.Disk, resourceName string) resource.TestCheckFunc { - return func(s *terraform.State) error { - state := s.RootModule().Resources[resourceName] - if state == nil { - return fmt.Errorf("Unable to find resource named %s", resourceName) - } - - labelFingerprint := state.Primary.Attributes["label_fingerprint"] - if labelFingerprint != disk.LabelFingerprint { - return fmt.Errorf("Label fingerprints do not match: api returned %s but state has %s", - disk.LabelFingerprint, labelFingerprint) - } - - return nil - } -} - func testAccCheckEncryptionKey(n string, disk *compute.Disk) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -537,28 +497,6 @@ func testAccCheckEncryptionKey(n string, disk *compute.Disk) resource.TestCheckF } } -func testAccCheckComputeDiskInstances(n string, disk *compute.Disk) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - - attr := rs.Primary.Attributes["users.#"] - if strconv.Itoa(len(disk.Users)) != attr { - return fmt.Errorf("Disk %s has mismatched users.\nTF State: %+v\nGCP State: %+v", n, rs.Primary.Attributes["users"], disk.Users) - } - - for pos, user := range disk.Users { - if rs.Primary.Attributes["users."+strconv.Itoa(pos)] != user { - return fmt.Errorf("Disk %s has mismatched users.\nTF State: %+v.\nGCP State: %+v", - n, rs.Primary.Attributes["users"], disk.Users) - } - } - return nil - } -} - func testAccComputeDisk_basic(diskName string) string { return fmt.Sprintf(` data "google_compute_image" "my_image" { diff --git a/google-beta/resource_compute_global_address_test.go b/google-beta/resource_compute_global_address_test.go index e1930c3c25..d58b37cc22 100644 --- a/google-beta/resource_compute_global_address_test.go +++ b/google-beta/resource_compute_global_address_test.go @@ -6,16 +6,11 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" - - "google.golang.org/api/compute/v1" ) func TestAccComputeGlobalAddress_ipv6(t *testing.T) { t.Parallel() - var addr compute.Address - resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -23,11 +18,6 @@ func TestAccComputeGlobalAddress_ipv6(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccComputeGlobalAddress_ipv6(), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeGlobalAddressExists( - "google_compute_global_address.foobar", &addr), - testAccCheckComputeGlobalAddressIpVersion("google_compute_global_address.foobar", "IPV6"), - ), }, { ResourceName: "google_compute_global_address.foobar", @@ -58,61 +48,6 @@ func TestAccComputeGlobalAddress_internal(t *testing.T) { }) } -func testAccCheckComputeGlobalAddressExists(n string, addr *compute.Address) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No ID is set") - } - - config := testAccProvider.Meta().(*Config) - - found, err := config.clientCompute.GlobalAddresses.Get( - config.Project, rs.Primary.ID).Do() - if err != nil { - return err - } - - if found.Name != rs.Primary.ID { - return fmt.Errorf("Addr not found") - } - - *addr = *found - - return nil - } -} - -func testAccCheckComputeGlobalAddressIpVersion(n, version string) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No ID is set") - } - - config := testAccProvider.Meta().(*Config) - - addr, err := config.clientCompute.GlobalAddresses.Get(config.Project, rs.Primary.ID).Do() - if err != nil { - return err - } - - if addr.IpVersion != version { - return fmt.Errorf("Expected IP version to be %s, got %s", version, addr.IpVersion) - } - - return nil - } -} - func testAccComputeGlobalAddress_ipv6() string { return fmt.Sprintf(` resource "google_compute_global_address" "foobar" { diff --git a/google-beta/resource_compute_https_health_check_test.go b/google-beta/resource_compute_https_health_check_test.go index 47edb4062f..fbb3646ce7 100644 --- a/google-beta/resource_compute_https_health_check_test.go +++ b/google-beta/resource_compute_https_health_check_test.go @@ -6,15 +6,11 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" - "google.golang.org/api/compute/v1" ) func TestAccComputeHttpsHealthCheck_update(t *testing.T) { t.Parallel() - var healthCheck compute.HttpsHealthCheck - hhckName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) resource.Test(t, resource.TestCase{ @@ -24,83 +20,24 @@ func TestAccComputeHttpsHealthCheck_update(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccComputeHttpsHealthCheck_update1(hhckName), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeHttpsHealthCheckExists( - "google_compute_https_health_check.foobar", &healthCheck), - testAccCheckComputeHttpsHealthCheckRequestPath( - "/not_default", &healthCheck), - testAccCheckComputeHttpsHealthCheckThresholds( - 2, 2, &healthCheck), - ), + }, + { + ResourceName: "google_compute_https_health_check.foobar", + ImportState: true, + ImportStateVerify: true, }, { Config: testAccComputeHttpsHealthCheck_update2(hhckName), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeHttpsHealthCheckExists( - "google_compute_https_health_check.foobar", &healthCheck), - testAccCheckComputeHttpsHealthCheckRequestPath( - "/", &healthCheck), - testAccCheckComputeHttpsHealthCheckThresholds( - 10, 10, &healthCheck), - ), + }, + { + ResourceName: "google_compute_https_health_check.foobar", + ImportState: true, + ImportStateVerify: true, }, }, }) } -func testAccCheckComputeHttpsHealthCheckExists(n string, healthCheck *compute.HttpsHealthCheck) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No ID is set") - } - - config := testAccProvider.Meta().(*Config) - - found, err := config.clientCompute.HttpsHealthChecks.Get( - config.Project, rs.Primary.ID).Do() - if err != nil { - return err - } - - if found.Name != rs.Primary.ID { - return fmt.Errorf("HttpsHealthCheck not found") - } - - *healthCheck = *found - - return nil - } -} - -func testAccCheckComputeHttpsHealthCheckRequestPath(path string, healthCheck *compute.HttpsHealthCheck) resource.TestCheckFunc { - return func(s *terraform.State) error { - if healthCheck.RequestPath != path { - return fmt.Errorf("RequestPath doesn't match: expected %s, got %s", path, healthCheck.RequestPath) - } - - return nil - } -} - -func testAccCheckComputeHttpsHealthCheckThresholds(healthy, unhealthy int64, healthCheck *compute.HttpsHealthCheck) resource.TestCheckFunc { - return func(s *terraform.State) error { - if healthCheck.HealthyThreshold != healthy { - return fmt.Errorf("HealthyThreshold doesn't match: expected %d, got %d", healthy, healthCheck.HealthyThreshold) - } - - if healthCheck.UnhealthyThreshold != unhealthy { - return fmt.Errorf("UnhealthyThreshold doesn't match: expected %d, got %d", unhealthy, healthCheck.UnhealthyThreshold) - } - - return nil - } -} - func testAccComputeHttpsHealthCheck_update1(hhckName string) string { return fmt.Sprintf(` resource "google_compute_https_health_check" "foobar" { diff --git a/google-beta/resource_google_service_account.go b/google-beta/resource_google_service_account.go index b367b1a501..75a348d7c6 100644 --- a/google-beta/resource_google_service_account.go +++ b/google-beta/resource_google_service_account.go @@ -3,6 +3,7 @@ package google import ( "fmt" "strings" + "time" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "google.golang.org/api/iam/v1" @@ -40,6 +41,10 @@ func resourceGoogleServiceAccount() *schema.Resource { Type: schema.TypeString, Optional: true, }, + "description": { + Type: schema.TypeString, + Optional: true, + }, "project": { Type: schema.TypeString, Computed: true, @@ -63,9 +68,11 @@ func resourceGoogleServiceAccountCreate(d *schema.ResourceData, meta interface{} } aid := d.Get("account_id").(string) displayName := d.Get("display_name").(string) + description := d.Get("description").(string) sa := &iam.ServiceAccount{ DisplayName: displayName, + Description: description, } r := &iam.CreateServiceAccountRequest{ @@ -79,6 +86,7 @@ func resourceGoogleServiceAccountCreate(d *schema.ResourceData, meta interface{} } d.SetId(sa.Name) + time.Sleep(time.Second) return resourceGoogleServiceAccountRead(d, meta) } @@ -98,6 +106,7 @@ func resourceGoogleServiceAccountRead(d *schema.ResourceData, meta interface{}) d.Set("account_id", strings.Split(sa.Email, "@")[0]) d.Set("name", sa.Name) d.Set("display_name", sa.DisplayName) + d.Set("description", sa.Description) return nil } @@ -114,7 +123,7 @@ func resourceGoogleServiceAccountDelete(d *schema.ResourceData, meta interface{} func resourceGoogleServiceAccountUpdate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - if ok := d.HasChange("display_name"); ok { + if d.HasChange("display_name") || d.HasChange("description") { sa, err := config.clientIAM.Projects.ServiceAccounts.Get(d.Id()).Do() if err != nil { return fmt.Errorf("Error retrieving service account %q: %s", d.Id(), err) @@ -122,11 +131,13 @@ func resourceGoogleServiceAccountUpdate(d *schema.ResourceData, meta interface{} _, err = config.clientIAM.Projects.ServiceAccounts.Update(d.Id(), &iam.ServiceAccount{ DisplayName: d.Get("display_name").(string), + Description: d.Get("description").(string), Etag: sa.Etag, }).Do() if err != nil { return fmt.Errorf("Error updating service account %q: %s", d.Id(), err) } + time.Sleep(time.Second) } return nil diff --git a/google-beta/resource_google_service_account_test.go b/google-beta/resource_google_service_account_test.go index 3b9c66a3ea..d44584bbbd 100644 --- a/google-beta/resource_google_service_account_test.go +++ b/google-beta/resource_google_service_account_test.go @@ -95,6 +95,7 @@ func testAccServiceAccountBasic(account, name string) string { resource "google_service_account" "acceptance" { account_id = "%v" display_name = "%v" + description = "foo" } `, account, name) } @@ -105,6 +106,7 @@ resource "google_service_account" "acceptance" { project = "%v" account_id = "%v" display_name = "%v" + description = "foo" } `, project, account, name) }