From 8951bb7999fe36789fb843cdf9b384f6e2df61f1 Mon Sep 17 00:00:00 2001 From: Dana Hoffman Date: Thu, 16 Aug 2018 19:09:00 +0000 Subject: [PATCH] Add Policy, Attestor, and Note resources for Binary Authorization --- google/provider_binaryauthorization_gen.go | 22 + google/provider_containeranalysis_gen.go | 21 + .../resource_binaryauthorization_attestor.go | 398 +++++++++++++ ...ource_binaryauthorization_attestor_test.go | 178 ++++++ google/resource_binaryauthorization_policy.go | 557 ++++++++++++++++++ ...esource_binaryauthorization_policy_test.go | 215 +++++++ google/resource_compute_address.go | 39 +- google/resource_compute_autoscaler.go | 30 +- google/resource_compute_backend_bucket.go | 30 +- google/resource_compute_disk.go | 50 +- google/resource_compute_forwarding_rule.go | 48 +- google/resource_compute_global_address.go | 39 +- google/resource_compute_http_health_check.go | 30 +- google/resource_compute_https_health_check.go | 30 +- google/resource_compute_region_autoscaler.go | 30 +- google/resource_compute_region_disk.go | 50 +- google/resource_compute_route.go | 21 +- google/resource_compute_router.go | 30 +- google/resource_compute_ssl_policy.go | 30 +- google/resource_compute_subnetwork.go | 57 +- google/resource_compute_target_http_proxy.go | 39 +- google/resource_compute_target_https_proxy.go | 66 ++- google/resource_compute_target_ssl_proxy.go | 66 ++- google/resource_compute_target_tcp_proxy.go | 48 +- google/resource_compute_vpn_gateway.go | 21 +- google/resource_compute_vpn_tunnel.go | 39 +- google/resource_containeranalysis_note.go | 292 +++++++++ .../resource_containeranalysis_note_test.go | 102 ++++ google/resource_redis_instance.go | 30 +- google/resource_resourcemanager_lien.go | 3 +- ...binaryauthorization_attestor.html.markdown | 158 +++++ .../binaryauthorization_policy.html.markdown | 165 ++++++ website/docs/r/compute_address.html.markdown | 1 + .../docs/r/compute_autoscaler.html.markdown | 15 +- .../r/compute_backend_bucket.html.markdown | 1 + website/docs/r/compute_disk.html.markdown | 7 +- .../r/compute_forwarding_rule.html.markdown | 1 + .../r/compute_global_address.html.markdown | 1 + .../r/compute_http_health_check.html.markdown | 1 + .../compute_https_health_check.html.markdown | 1 + .../r/compute_region_autoscaler.html.markdown | 15 +- .../docs/r/compute_region_disk.html.markdown | 5 +- website/docs/r/compute_route.html.markdown | 1 + website/docs/r/compute_router.html.markdown | 7 +- .../docs/r/compute_ssl_policy.html.markdown | 1 + .../docs/r/compute_subnetwork.html.markdown | 3 +- .../r/compute_target_http_proxy.html.markdown | 1 + .../compute_target_https_proxy.html.markdown | 1 + .../r/compute_target_ssl_proxy.html.markdown | 1 + .../r/compute_target_tcp_proxy.html.markdown | 1 + .../docs/r/compute_vpn_gateway.html.markdown | 1 + .../docs/r/compute_vpn_tunnel.html.markdown | 1 + .../r/containeranalysis_note.html.markdown | 104 ++++ website/docs/r/redis_instance.html.markdown | 1 + .../docs/r/resourcemanager_lien.html.markdown | 1 + 55 files changed, 2667 insertions(+), 439 deletions(-) create mode 100644 google/provider_binaryauthorization_gen.go create mode 100644 google/provider_containeranalysis_gen.go create mode 100644 google/resource_binaryauthorization_attestor.go create mode 100644 google/resource_binaryauthorization_attestor_test.go create mode 100644 google/resource_binaryauthorization_policy.go create mode 100644 google/resource_binaryauthorization_policy_test.go create mode 100644 google/resource_containeranalysis_note.go create mode 100644 google/resource_containeranalysis_note_test.go create mode 100644 website/docs/r/binaryauthorization_attestor.html.markdown create mode 100644 website/docs/r/binaryauthorization_policy.html.markdown create mode 100644 website/docs/r/containeranalysis_note.html.markdown diff --git a/google/provider_binaryauthorization_gen.go b/google/provider_binaryauthorization_gen.go new file mode 100644 index 00000000000..c3cae345480 --- /dev/null +++ b/google/provider_binaryauthorization_gen.go @@ -0,0 +1,22 @@ +// ---------------------------------------------------------------------------- +// +// *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +// +// ---------------------------------------------------------------------------- +// +// This file is automatically generated by Magic Modules and manual +// changes will be clobbered when the file is regenerated. +// +// Please read more about how to change this file in +// .github/CONTRIBUTING.md. +// +// ---------------------------------------------------------------------------- + +package google + +import "github.com/hashicorp/terraform/helper/schema" + +var GeneratedBinaryauthorizationResourcesMap = map[string]*schema.Resource{ + "google_binaryauthorization_attestor": resourceBinaryauthorizationAttestor(), + "google_binaryauthorization_policy": resourceBinaryauthorizationPolicy(), +} diff --git a/google/provider_containeranalysis_gen.go b/google/provider_containeranalysis_gen.go new file mode 100644 index 00000000000..f4fe038c0b4 --- /dev/null +++ b/google/provider_containeranalysis_gen.go @@ -0,0 +1,21 @@ +// ---------------------------------------------------------------------------- +// +// *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +// +// ---------------------------------------------------------------------------- +// +// This file is automatically generated by Magic Modules and manual +// changes will be clobbered when the file is regenerated. +// +// Please read more about how to change this file in +// .github/CONTRIBUTING.md. +// +// ---------------------------------------------------------------------------- + +package google + +import "github.com/hashicorp/terraform/helper/schema" + +var GeneratedContaineranalysisResourcesMap = map[string]*schema.Resource{ + "google_containeranalysis_note": resourceContaineranalysisNote(), +} diff --git a/google/resource_binaryauthorization_attestor.go b/google/resource_binaryauthorization_attestor.go new file mode 100644 index 00000000000..2a2c16851f1 --- /dev/null +++ b/google/resource_binaryauthorization_attestor.go @@ -0,0 +1,398 @@ +// ---------------------------------------------------------------------------- +// +// *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +// +// ---------------------------------------------------------------------------- +// +// This file is automatically generated by Magic Modules and manual +// changes will be clobbered when the file is regenerated. +// +// Please read more about how to change this file in +// .github/CONTRIBUTING.md. +// +// ---------------------------------------------------------------------------- + +package google + +import ( + "fmt" + "log" + "reflect" + "regexp" + + "github.com/hashicorp/terraform/helper/schema" +) + +func resourceBinaryauthorizationAttestor() *schema.Resource { + return &schema.Resource{ + Create: resourceBinaryauthorizationAttestorCreate, + Read: resourceBinaryauthorizationAttestorRead, + Update: resourceBinaryauthorizationAttestorUpdate, + Delete: resourceBinaryauthorizationAttestorDelete, + + Importer: &schema.ResourceImporter{ + State: resourceBinaryauthorizationAttestorImport, + }, + + Schema: map[string]*schema.Schema{ + "attestation_authority_note": { + Type: schema.TypeList, + Required: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "note_reference": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + DiffSuppressFunc: compareSelfLinkOrResourceName, + }, + "public_keys": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ascii_armored_pgp_public_key": { + Type: schema.TypeString, + Required: true, + }, + "comment": { + Type: schema.TypeString, + Optional: true, + }, + "id": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "delegation_service_account_email": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "description": { + Type: schema.TypeString, + Optional: true, + }, + "project": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, + }, + } +} + +func resourceBinaryauthorizationAttestorCreate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + obj := make(map[string]interface{}) + nameProp, err := expandBinaryauthorizationAttestorName(d.Get("name"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("name"); !isEmptyValue(reflect.ValueOf(nameProp)) && (ok || !reflect.DeepEqual(v, nameProp)) { + obj["name"] = nameProp + } + descriptionProp, err := expandBinaryauthorizationAttestorDescription(d.Get("description"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("description"); !isEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) { + obj["description"] = descriptionProp + } + userOwnedDrydockNoteProp, err := expandBinaryauthorizationAttestorAttestationAuthorityNote(d.Get("attestation_authority_note"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("attestation_authority_note"); !isEmptyValue(reflect.ValueOf(userOwnedDrydockNoteProp)) && (ok || !reflect.DeepEqual(v, userOwnedDrydockNoteProp)) { + obj["userOwnedDrydockNote"] = userOwnedDrydockNoteProp + } + + url, err := replaceVars(d, config, "https://binaryauthorization.googleapis.com/v1beta1/projects/{{project}}/attestors?attestorId={{name}}") + if err != nil { + return err + } + + log.Printf("[DEBUG] Creating new Attestor: %#v", obj) + res, err := sendRequest(config, "POST", url, obj) + if err != nil { + return fmt.Errorf("Error creating Attestor: %s", err) + } + + // Store the ID now + id, err := replaceVars(d, config, "{{name}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + log.Printf("[DEBUG] Finished creating Attestor %q: %#v", d.Id(), res) + + return resourceBinaryauthorizationAttestorRead(d, meta) +} + +func resourceBinaryauthorizationAttestorRead(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + project, err := getProject(d, config) + if err != nil { + return err + } + + url, err := replaceVars(d, config, "https://binaryauthorization.googleapis.com/v1beta1/projects/{{project}}/attestors/{{name}}") + if err != nil { + return err + } + + res, err := sendRequest(config, "GET", url, nil) + if err != nil { + return handleNotFoundError(err, d, fmt.Sprintf("BinaryauthorizationAttestor %q", d.Id())) + } + + if err := d.Set("name", flattenBinaryauthorizationAttestorName(res["name"])); err != nil { + return fmt.Errorf("Error reading Attestor: %s", err) + } + if err := d.Set("description", flattenBinaryauthorizationAttestorDescription(res["description"])); err != nil { + return fmt.Errorf("Error reading Attestor: %s", err) + } + if err := d.Set("attestation_authority_note", flattenBinaryauthorizationAttestorAttestationAuthorityNote(res["userOwnedDrydockNote"])); err != nil { + return fmt.Errorf("Error reading Attestor: %s", err) + } + if err := d.Set("project", project); err != nil { + return fmt.Errorf("Error reading Attestor: %s", err) + } + + return nil +} + +func resourceBinaryauthorizationAttestorUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + obj := make(map[string]interface{}) + nameProp, err := expandBinaryauthorizationAttestorName(d.Get("name"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("name"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, nameProp)) { + obj["name"] = nameProp + } + descriptionProp, err := expandBinaryauthorizationAttestorDescription(d.Get("description"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("description"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, descriptionProp)) { + obj["description"] = descriptionProp + } + userOwnedDrydockNoteProp, err := expandBinaryauthorizationAttestorAttestationAuthorityNote(d.Get("attestation_authority_note"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("attestation_authority_note"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, userOwnedDrydockNoteProp)) { + obj["userOwnedDrydockNote"] = userOwnedDrydockNoteProp + } + + url, err := replaceVars(d, config, "https://binaryauthorization.googleapis.com/v1beta1/projects/{{project}}/attestors/{{name}}") + if err != nil { + return err + } + + log.Printf("[DEBUG] Updating Attestor %q: %#v", d.Id(), obj) + _, err = sendRequest(config, "PUT", url, obj) + + if err != nil { + return fmt.Errorf("Error updating Attestor %q: %s", d.Id(), err) + } + + return resourceBinaryauthorizationAttestorRead(d, meta) +} + +func resourceBinaryauthorizationAttestorDelete(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + url, err := replaceVars(d, config, "https://binaryauthorization.googleapis.com/v1beta1/projects/{{project}}/attestors/{{name}}") + if err != nil { + return err + } + + var obj map[string]interface{} + log.Printf("[DEBUG] Deleting Attestor %q", d.Id()) + res, err := sendRequest(config, "DELETE", url, obj) + if err != nil { + return handleNotFoundError(err, d, "Attestor") + } + + log.Printf("[DEBUG] Finished deleting Attestor %q: %#v", d.Id(), res) + return nil +} + +func resourceBinaryauthorizationAttestorImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + config := meta.(*Config) + parseImportId([]string{"projects/(?P[^/]+)/attestors/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)"}, d, config) + + // Replace import id for the resource id + id, err := replaceVars(d, config, "{{name}}") + if err != nil { + return nil, fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + return []*schema.ResourceData{d}, nil +} + +func flattenBinaryauthorizationAttestorName(v interface{}) interface{} { + if v == nil { + return v + } + return NameFromSelfLinkStateFunc(v) +} + +func flattenBinaryauthorizationAttestorDescription(v interface{}) interface{} { + return v +} + +func flattenBinaryauthorizationAttestorAttestationAuthorityNote(v interface{}) interface{} { + if v == nil { + return nil + } + original := v.(map[string]interface{}) + transformed := make(map[string]interface{}) + transformed["note_reference"] = + flattenBinaryauthorizationAttestorAttestationAuthorityNoteNoteReference(original["noteReference"]) + transformed["public_keys"] = + flattenBinaryauthorizationAttestorAttestationAuthorityNotePublicKeys(original["publicKeys"]) + transformed["delegation_service_account_email"] = + flattenBinaryauthorizationAttestorAttestationAuthorityNoteDelegationServiceAccountEmail(original["delegationServiceAccountEmail"]) + return []interface{}{transformed} +} +func flattenBinaryauthorizationAttestorAttestationAuthorityNoteNoteReference(v interface{}) interface{} { + return v +} + +func flattenBinaryauthorizationAttestorAttestationAuthorityNotePublicKeys(v interface{}) interface{} { + if v == nil { + return v + } + l := v.([]interface{}) + transformed := make([]interface{}, 0, len(l)) + for _, raw := range l { + original := raw.(map[string]interface{}) + transformed = append(transformed, map[string]interface{}{ + "comment": flattenBinaryauthorizationAttestorAttestationAuthorityNotePublicKeysComment(original["comment"]), + "id": flattenBinaryauthorizationAttestorAttestationAuthorityNotePublicKeysId(original["id"]), + "ascii_armored_pgp_public_key": flattenBinaryauthorizationAttestorAttestationAuthorityNotePublicKeysAsciiArmoredPgpPublicKey(original["asciiArmoredPgpPublicKey"]), + }) + } + return transformed +} +func flattenBinaryauthorizationAttestorAttestationAuthorityNotePublicKeysComment(v interface{}) interface{} { + return v +} + +func flattenBinaryauthorizationAttestorAttestationAuthorityNotePublicKeysId(v interface{}) interface{} { + return v +} + +func flattenBinaryauthorizationAttestorAttestationAuthorityNotePublicKeysAsciiArmoredPgpPublicKey(v interface{}) interface{} { + return v +} + +func flattenBinaryauthorizationAttestorAttestationAuthorityNoteDelegationServiceAccountEmail(v interface{}) interface{} { + return v +} + +func expandBinaryauthorizationAttestorName(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandBinaryauthorizationAttestorDescription(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandBinaryauthorizationAttestorAttestationAuthorityNote(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + l := v.([]interface{}) + if len(l) == 0 { + return nil, nil + } + raw := l[0] + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedNoteReference, err := expandBinaryauthorizationAttestorAttestationAuthorityNoteNoteReference(original["note_reference"], d, config) + if err != nil { + return nil, err + } + transformed["noteReference"] = transformedNoteReference + transformedPublicKeys, err := expandBinaryauthorizationAttestorAttestationAuthorityNotePublicKeys(original["public_keys"], d, config) + if err != nil { + return nil, err + } + transformed["publicKeys"] = transformedPublicKeys + transformedDelegationServiceAccountEmail, err := expandBinaryauthorizationAttestorAttestationAuthorityNoteDelegationServiceAccountEmail(original["delegation_service_account_email"], d, config) + if err != nil { + return nil, err + } + transformed["delegationServiceAccountEmail"] = transformedDelegationServiceAccountEmail + return transformed, nil +} + +func expandBinaryauthorizationAttestorAttestationAuthorityNoteNoteReference(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + r := regexp.MustCompile("projects/(.+)/notes/(.+)") + if r.MatchString(v.(string)) { + return v.(string), nil + } + + project, err := getProject(d, config) + if err != nil { + return nil, err + } + + return fmt.Sprintf("projects/%s/notes/%s", project, v.(string)), nil +} + +func expandBinaryauthorizationAttestorAttestationAuthorityNotePublicKeys(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + l := v.([]interface{}) + req := make([]interface{}, 0, len(l)) + for _, raw := range l { + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedComment, err := expandBinaryauthorizationAttestorAttestationAuthorityNotePublicKeysComment(original["comment"], d, config) + if err != nil { + return nil, err + } + transformed["comment"] = transformedComment + transformedId, err := expandBinaryauthorizationAttestorAttestationAuthorityNotePublicKeysId(original["id"], d, config) + if err != nil { + return nil, err + } + transformed["id"] = transformedId + transformedAsciiArmoredPgpPublicKey, err := expandBinaryauthorizationAttestorAttestationAuthorityNotePublicKeysAsciiArmoredPgpPublicKey(original["ascii_armored_pgp_public_key"], d, config) + if err != nil { + return nil, err + } + transformed["asciiArmoredPgpPublicKey"] = transformedAsciiArmoredPgpPublicKey + req = append(req, transformed) + } + return req, nil +} + +func expandBinaryauthorizationAttestorAttestationAuthorityNotePublicKeysComment(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandBinaryauthorizationAttestorAttestationAuthorityNotePublicKeysId(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandBinaryauthorizationAttestorAttestationAuthorityNotePublicKeysAsciiArmoredPgpPublicKey(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandBinaryauthorizationAttestorAttestationAuthorityNoteDelegationServiceAccountEmail(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} diff --git a/google/resource_binaryauthorization_attestor_test.go b/google/resource_binaryauthorization_attestor_test.go new file mode 100644 index 00000000000..9a53cbec270 --- /dev/null +++ b/google/resource_binaryauthorization_attestor_test.go @@ -0,0 +1,178 @@ +package google + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" +) + +func TestAccBinaryAuthorizationAttestor_basic(t *testing.T) { + t.Parallel() + + name := acctest.RandString(10) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckBinaryAuthorizationAttestorDestroy, + Steps: []resource.TestStep{ + { + Config: testAccBinaryAuthorizationAttestorBasic(name), + }, + { + ResourceName: "google_binaryauthorization_attestor.attestor", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccBinaryAuthorizationAttestor_full(t *testing.T) { + t.Parallel() + + name := acctest.RandString(10) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckBinaryAuthorizationAttestorDestroy, + Steps: []resource.TestStep{ + { + Config: testAccBinaryAuthorizationAttestorFull(name), + }, + { + ResourceName: "google_binaryauthorization_attestor.attestor", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccBinaryAuthorizationAttestor_update(t *testing.T) { + t.Parallel() + + name := acctest.RandString(10) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckBinaryAuthorizationAttestorDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccBinaryAuthorizationAttestorBasic(name), + }, + { + ResourceName: "google_binaryauthorization_attestor.attestor", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccBinaryAuthorizationAttestorFull(name), + }, + { + ResourceName: "google_binaryauthorization_attestor.attestor", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccBinaryAuthorizationAttestorBasic(name), + }, + { + ResourceName: "google_binaryauthorization_attestor.attestor", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccCheckBinaryAuthorizationAttestorDestroy(s *terraform.State) error { + config := testAccProvider.Meta().(*Config) + + for _, rs := range s.RootModule().Resources { + if rs.Type != "google_binaryauthorization_attestor" { + continue + } + + project, err := getTestProject(rs.Primary, config) + if err != nil { + return err + } + + name := rs.Primary.Attributes["name"] + + url := fmt.Sprintf("https://binaryauthorization.googleapis.com/v1beta1/projects/%s/attestors/%s", project, name) + _, err = sendRequest(config, "GET", url, nil) + + if err == nil { + return fmt.Errorf("Error, attestor %s still exists", name) + } + } + + return nil +} + +func testAccBinaryAuthorizationAttestorBasic(name string) string { + return fmt.Sprintf(` +resource "google_containeranalysis_note" "note" { + name = "tf-test-%s" + attestation_authority { + hint { + human_readable_name = "My Attestor" + } + } +} + +resource "google_binaryauthorization_attestor" "attestor" { + name = "tf-test-%s" + attestation_authority_note { + note_reference = "${google_containeranalysis_note.note.name}" + } +} +`, name, name) +} + +func testAccBinaryAuthorizationAttestorFull(name string) string { + return fmt.Sprintf(` +resource "google_containeranalysis_note" "note" { + name = "tf-test-%s" + attestation_authority { + hint { + human_readable_name = "My Attestor" + } + } +} + +resource "google_binaryauthorization_attestor" "attestor" { + name = "tf-test-%s" + description = "my description" + attestation_authority_note { + note_reference = "${google_containeranalysis_note.note.name}" + public_keys { + ascii_armored_pgp_public_key = <[^/]+)", "(?P[^/]+)"}, d, config) + + // Replace import id for the resource id + id, err := replaceVars(d, config, "{{project}}") + if err != nil { + return nil, fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + return []*schema.ResourceData{d}, nil +} + +func flattenBinaryauthorizationPolicyDescription(v interface{}) interface{} { + return v +} + +func flattenBinaryauthorizationPolicyAdmissionWhitelistPatterns(v interface{}) interface{} { + if v == nil { + return v + } + l := v.([]interface{}) + transformed := make([]interface{}, 0, len(l)) + for _, raw := range l { + original := raw.(map[string]interface{}) + transformed = append(transformed, map[string]interface{}{ + "name_pattern": flattenBinaryauthorizationPolicyAdmissionWhitelistPatternsNamePattern(original["namePattern"]), + }) + } + return transformed +} +func flattenBinaryauthorizationPolicyAdmissionWhitelistPatternsNamePattern(v interface{}) interface{} { + return v +} + +func flattenBinaryauthorizationPolicyClusterAdmissionRules(v interface{}) interface{} { + if v == nil { + return v + } + l := v.(map[string]interface{}) + transformed := make([]interface{}, 0, len(l)) + for k, raw := range l { + original := raw.(map[string]interface{}) + transformed = append(transformed, map[string]interface{}{ + "cluster": k, + "evaluation_mode": flattenBinaryauthorizationPolicyClusterAdmissionRulesEvaluationMode(original["evaluationMode"]), + "require_attestations_by": flattenBinaryauthorizationPolicyClusterAdmissionRulesRequireAttestationsBy(original["requireAttestationsBy"]), + "enforcement_mode": flattenBinaryauthorizationPolicyClusterAdmissionRulesEnforcementMode(original["enforcementMode"]), + }) + } + return transformed +} +func flattenBinaryauthorizationPolicyClusterAdmissionRulesEvaluationMode(v interface{}) interface{} { + return v +} + +func flattenBinaryauthorizationPolicyClusterAdmissionRulesRequireAttestationsBy(v interface{}) interface{} { + if v == nil { + return v + } + return schema.NewSet(selfLinkNameHash, v.([]interface{})) +} + +func flattenBinaryauthorizationPolicyClusterAdmissionRulesEnforcementMode(v interface{}) interface{} { + return v +} + +func flattenBinaryauthorizationPolicyDefaultAdmissionRule(v interface{}) interface{} { + if v == nil { + return nil + } + original := v.(map[string]interface{}) + transformed := make(map[string]interface{}) + transformed["evaluation_mode"] = + flattenBinaryauthorizationPolicyDefaultAdmissionRuleEvaluationMode(original["evaluationMode"]) + transformed["require_attestations_by"] = + flattenBinaryauthorizationPolicyDefaultAdmissionRuleRequireAttestationsBy(original["requireAttestationsBy"]) + transformed["enforcement_mode"] = + flattenBinaryauthorizationPolicyDefaultAdmissionRuleEnforcementMode(original["enforcementMode"]) + return []interface{}{transformed} +} +func flattenBinaryauthorizationPolicyDefaultAdmissionRuleEvaluationMode(v interface{}) interface{} { + return v +} + +func flattenBinaryauthorizationPolicyDefaultAdmissionRuleRequireAttestationsBy(v interface{}) interface{} { + if v == nil { + return v + } + return schema.NewSet(selfLinkNameHash, v.([]interface{})) +} + +func flattenBinaryauthorizationPolicyDefaultAdmissionRuleEnforcementMode(v interface{}) interface{} { + return v +} + +func expandBinaryauthorizationPolicyDescription(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandBinaryauthorizationPolicyAdmissionWhitelistPatterns(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + l := v.([]interface{}) + req := make([]interface{}, 0, len(l)) + for _, raw := range l { + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedNamePattern, err := expandBinaryauthorizationPolicyAdmissionWhitelistPatternsNamePattern(original["name_pattern"], d, config) + if err != nil { + return nil, err + } + transformed["namePattern"] = transformedNamePattern + req = append(req, transformed) + } + return req, nil +} + +func expandBinaryauthorizationPolicyAdmissionWhitelistPatternsNamePattern(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandBinaryauthorizationPolicyClusterAdmissionRules(v interface{}, d *schema.ResourceData, config *Config) (map[string]interface{}, error) { + if v == nil { + return map[string]interface{}{}, nil + } + m := make(map[string]interface{}) + for _, raw := range v.(*schema.Set).List() { + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedEvaluationMode, err := expandBinaryauthorizationPolicyClusterAdmissionRulesEvaluationMode(original["evaluation_mode"], d, config) + if err != nil { + return nil, err + } + transformed["evaluationMode"] = transformedEvaluationMode + transformedRequireAttestationsBy, err := expandBinaryauthorizationPolicyClusterAdmissionRulesRequireAttestationsBy(original["require_attestations_by"], d, config) + if err != nil { + return nil, err + } + transformed["requireAttestationsBy"] = transformedRequireAttestationsBy + transformedEnforcementMode, err := expandBinaryauthorizationPolicyClusterAdmissionRulesEnforcementMode(original["enforcement_mode"], d, config) + if err != nil { + return nil, err + } + transformed["enforcementMode"] = transformedEnforcementMode + + m[original["cluster"].(string)] = transformed + } + return m, nil +} + +func expandBinaryauthorizationPolicyClusterAdmissionRulesEvaluationMode(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandBinaryauthorizationPolicyClusterAdmissionRulesRequireAttestationsBy(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + r := regexp.MustCompile("projects/(.+)/attestors/(.+)") + + // It's possible that all entries in the list will specify a project, in + // which case the user wouldn't necessarily have to specify a provider + // project. + var project string + var err error + for _, s := range v.(*schema.Set).List() { + if !r.MatchString(s.(string)) { + project, err = getProject(d, config) + if err != nil { + return []interface{}{}, err + } + break + } + } + + return convertAndMapStringArr(v.(*schema.Set).List(), func(s string) string { + if r.MatchString(s) { + return s + } + + return fmt.Sprintf("projects/%s/attestors/%s", project, s) + }), nil +} + +func expandBinaryauthorizationPolicyClusterAdmissionRulesEnforcementMode(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandBinaryauthorizationPolicyDefaultAdmissionRule(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + l := v.([]interface{}) + if len(l) == 0 { + return nil, nil + } + raw := l[0] + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedEvaluationMode, err := expandBinaryauthorizationPolicyDefaultAdmissionRuleEvaluationMode(original["evaluation_mode"], d, config) + if err != nil { + return nil, err + } + transformed["evaluationMode"] = transformedEvaluationMode + transformedRequireAttestationsBy, err := expandBinaryauthorizationPolicyDefaultAdmissionRuleRequireAttestationsBy(original["require_attestations_by"], d, config) + if err != nil { + return nil, err + } + transformed["requireAttestationsBy"] = transformedRequireAttestationsBy + transformedEnforcementMode, err := expandBinaryauthorizationPolicyDefaultAdmissionRuleEnforcementMode(original["enforcement_mode"], d, config) + if err != nil { + return nil, err + } + transformed["enforcementMode"] = transformedEnforcementMode + return transformed, nil +} + +func expandBinaryauthorizationPolicyDefaultAdmissionRuleEvaluationMode(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandBinaryauthorizationPolicyDefaultAdmissionRuleRequireAttestationsBy(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + r := regexp.MustCompile("projects/(.+)/attestors/(.+)") + + // It's possible that all entries in the list will specify a project, in + // which case the user wouldn't necessarily have to specify a provider + // project. + var project string + var err error + for _, s := range v.(*schema.Set).List() { + if !r.MatchString(s.(string)) { + project, err = getProject(d, config) + if err != nil { + return []interface{}{}, err + } + break + } + } + + return convertAndMapStringArr(v.(*schema.Set).List(), func(s string) string { + if r.MatchString(s) { + return s + } + + return fmt.Sprintf("projects/%s/attestors/%s", project, s) + }), nil +} + +func expandBinaryauthorizationPolicyDefaultAdmissionRuleEnforcementMode(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} diff --git a/google/resource_binaryauthorization_policy_test.go b/google/resource_binaryauthorization_policy_test.go new file mode 100644 index 00000000000..927b10a2b16 --- /dev/null +++ b/google/resource_binaryauthorization_policy_test.go @@ -0,0 +1,215 @@ +package google + +import ( + "fmt" + "reflect" + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" +) + +func TestAccBinaryAuthorizationPolicy_basic(t *testing.T) { + t.Parallel() + + org := getTestOrgFromEnv(t) + pid := "tf-test-" + acctest.RandString(10) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccBinaryAuthorizationPolicyBasic(pid, pname, org), + }, + { + ResourceName: "google_binaryauthorization_policy.policy", + ImportState: true, + ImportStateVerify: true, + }, + // Destroy the policy without destroying the project so we can check + // that it was restored to the default. + { + Config: testAccBinaryAuthorizationPolicyDefault(pid, pname, org), + Check: testAccCheckBinaryAuthorizationPolicyDefault(pid), + }, + }, + }) +} + +func TestAccBinaryAuthorizationPolicy_full(t *testing.T) { + t.Parallel() + + org := getTestOrgFromEnv(t) + pid := "tf-test-" + acctest.RandString(10) + note := acctest.RandString(10) + attestor := acctest.RandString(10) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccBinaryAuthorizationPolicyFull(pid, pname, org, note, attestor), + }, + { + ResourceName: "google_binaryauthorization_policy.policy", + ImportState: true, + ImportStateVerify: true, + }, + // Destroy the policy without destroying the project so we can check + // that it was restored to the default. + { + Config: testAccBinaryAuthorizationPolicyDefault(pid, pname, org), + Check: testAccCheckBinaryAuthorizationPolicyDefault(pid), + }, + }, + }) +} + +func TestAccBinaryAuthorizationPolicy_update(t *testing.T) { + t.Parallel() + + org := getTestOrgFromEnv(t) + pid := "tf-test-" + acctest.RandString(10) + note := acctest.RandString(10) + attestor := acctest.RandString(10) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccBinaryAuthorizationPolicyBasic(pid, pname, org), + }, + { + ResourceName: "google_binaryauthorization_policy.policy", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccBinaryAuthorizationPolicyFull(pid, pname, org, note, attestor), + }, + { + ResourceName: "google_binaryauthorization_policy.policy", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccBinaryAuthorizationPolicyBasic(pid, pname, org), + }, + { + ResourceName: "google_binaryauthorization_policy.policy", + ImportState: true, + ImportStateVerify: true, + }, + // Destroy the policy without destroying the project so we can check + // that it was restored to the default. + { + Config: testAccBinaryAuthorizationPolicyDefault(pid, pname, org), + Check: testAccCheckBinaryAuthorizationPolicyDefault(pid), + }, + }, + }) +} + +func testAccCheckBinaryAuthorizationPolicyDefault(pid string) resource.TestCheckFunc { + return func(s *terraform.State) error { + config := testAccProvider.Meta().(*Config) + url := fmt.Sprintf("https://binaryauthorization.googleapis.com/v1beta1/projects/%s/policy", pid) + pol, err := sendRequest(config, "GET", url, nil) + if err != nil { + return err + } + + if !reflect.DeepEqual(pol, defaultBinaryAuthorizationPolicy) { + return fmt.Errorf("Policy for project %s was %v, expected default policy %v", pid, pol, defaultBinaryAuthorizationPolicy) + } + return nil + } +} + +func testAccBinaryAuthorizationPolicyDefault(pid, pname, org string) string { + return fmt.Sprintf(` +// Use a separate project since each project can only have one policy +resource "google_project" "project" { + project_id = "%s" + name = "%s" + org_id = "%s" +} +`, pid, pname, org) +} + +func testAccBinaryAuthorizationPolicyBasic(pid, pname, org string) string { + return fmt.Sprintf(` +// Use a separate project since each project can only have one policy +resource "google_project" "project" { + project_id = "%s" + name = "%s" + org_id = "%s" +} + +resource "google_binaryauthorization_policy" "policy" { + project = "${google_project.project.project_id}" + + admission_whitelist_patterns { + name_pattern= "gcr.io/google_containers/*" + } + + default_admission_rule { + evaluation_mode = "ALWAYS_DENY" + enforcement_mode = "ENFORCED_BLOCK_AND_AUDIT_LOG" + } +} +`, pid, pname, org) +} + +func testAccBinaryAuthorizationPolicyFull(pid, pname, org, note, attestor string) string { + return fmt.Sprintf(` +// Use a separate project since each project can only have one policy +resource "google_project" "project" { + project_id = "%s" + name = "%s" + org_id = "%s" +} + +resource "google_containeranalysis_note" "note" { + project = "${google_project.project.project_id}" + + name = "tf-test-%s" + attestation_authority { + hint { + human_readable_name = "My attestor" + } + } +} + +resource "google_binaryauthorization_attestor" "attestor" { + project = "${google_project.project.project_id}" + + name = "tf-test-%s" + description = "my description" + attestation_authority_note { + note_reference = "${google_containeranalysis_note.note.name}" + } +} + +resource "google_binaryauthorization_policy" "policy" { + project = "${google_project.project.project_id}" + + admission_whitelist_patterns { + name_pattern= "gcr.io/google_containers/*" + } + + default_admission_rule { + evaluation_mode = "ALWAYS_ALLOW" + enforcement_mode = "ENFORCED_BLOCK_AND_AUDIT_LOG" + } + + cluster_admission_rules { + cluster = "us-central1-a.prod-cluster" + evaluation_mode = "REQUIRE_ATTESTATION" + enforcement_mode = "ENFORCED_BLOCK_AND_AUDIT_LOG" + require_attestations_by = ["${google_binaryauthorization_attestor.attestor.name}"] + } +} +`, pid, pname, org, note, attestor) +} diff --git a/google/resource_compute_address.go b/google/resource_compute_address.go index cc4f92276d6..14e7a6c7e7a 100644 --- a/google/resource_compute_address.go +++ b/google/resource_compute_address.go @@ -125,11 +125,6 @@ func resourceComputeAddress() *schema.Resource { func resourceComputeAddressCreate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - obj := make(map[string]interface{}) addressProp, err := expandComputeAddressAddress(d.Get("address"), d, config) if err != nil { @@ -198,6 +193,10 @@ func resourceComputeAddressCreate(d *schema.ResourceData, meta interface{}) erro } d.SetId(id) + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { @@ -321,15 +320,6 @@ func resourceComputeAddressRead(d *schema.ResourceData, meta interface{}) error func resourceComputeAddressUpdate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - - var url string - var res map[string]interface{} - op := &compute.Operation{} - d.Partial(true) if d.HasChange("labels") || d.HasChange("label_fingerprint") { @@ -343,15 +333,20 @@ func resourceComputeAddressUpdate(d *schema.ResourceData, meta interface{}) erro labelFingerprintProp := d.Get("label_fingerprint") obj["labelFingerprint"] = labelFingerprintProp - url, err = replaceVars(d, config, "https://www.googleapis.com/compute/beta/projects/{{project}}/regions/{{region}}/addresses/{{name}}/setLabels") + url, err := replaceVars(d, config, "https://www.googleapis.com/compute/beta/projects/{{project}}/regions/{{region}}/addresses/{{name}}/setLabels") if err != nil { return err } - res, err = sendRequest(config, "POST", url, obj) + res, err := sendRequest(config, "POST", url, obj) if err != nil { return fmt.Errorf("Error updating Address %q: %s", d.Id(), err) } + project, err := getProject(d, config) + if err != nil { + return err + } + op := &compute.Operation{} err = Convert(res, op) if err != nil { return err @@ -377,22 +372,22 @@ func resourceComputeAddressUpdate(d *schema.ResourceData, meta interface{}) erro func resourceComputeAddressDelete(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - url, err := replaceVars(d, config, "https://www.googleapis.com/compute/beta/projects/{{project}}/regions/{{region}}/addresses/{{name}}") if err != nil { return err } + var obj map[string]interface{} log.Printf("[DEBUG] Deleting Address %q", d.Id()) - res, err := sendRequest(config, "DELETE", url, nil) + res, err := sendRequest(config, "DELETE", url, obj) if err != nil { return handleNotFoundError(err, d, "Address") } + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { diff --git a/google/resource_compute_autoscaler.go b/google/resource_compute_autoscaler.go index f82efdd3f55..81d1a8e2dbe 100644 --- a/google/resource_compute_autoscaler.go +++ b/google/resource_compute_autoscaler.go @@ -157,11 +157,6 @@ func resourceComputeAutoscaler() *schema.Resource { func resourceComputeAutoscalerCreate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - obj := make(map[string]interface{}) nameProp, err := expandComputeAutoscalerName(d.Get("name"), d, config) if err != nil { @@ -212,6 +207,10 @@ func resourceComputeAutoscalerCreate(d *schema.ResourceData, meta interface{}) e } d.SetId(id) + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { @@ -282,11 +281,6 @@ func resourceComputeAutoscalerRead(d *schema.ResourceData, meta interface{}) err func resourceComputeAutoscalerUpdate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - obj := make(map[string]interface{}) nameProp, err := expandComputeAutoscalerName(d.Get("name"), d, config) if err != nil { @@ -331,6 +325,10 @@ func resourceComputeAutoscalerUpdate(d *schema.ResourceData, meta interface{}) e return fmt.Errorf("Error updating Autoscaler %q: %s", d.Id(), err) } + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { @@ -351,22 +349,22 @@ func resourceComputeAutoscalerUpdate(d *schema.ResourceData, meta interface{}) e func resourceComputeAutoscalerDelete(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/zones/{{zone}}/autoscalers/{{name}}") if err != nil { return err } + var obj map[string]interface{} log.Printf("[DEBUG] Deleting Autoscaler %q", d.Id()) - res, err := sendRequest(config, "DELETE", url, nil) + res, err := sendRequest(config, "DELETE", url, obj) if err != nil { return handleNotFoundError(err, d, "Autoscaler") } + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { diff --git a/google/resource_compute_backend_bucket.go b/google/resource_compute_backend_bucket.go index b612c8a11cd..6f6930a683a 100644 --- a/google/resource_compute_backend_bucket.go +++ b/google/resource_compute_backend_bucket.go @@ -81,11 +81,6 @@ func resourceComputeBackendBucket() *schema.Resource { func resourceComputeBackendBucketCreate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - obj := make(map[string]interface{}) bucketNameProp, err := expandComputeBackendBucketBucketName(d.Get("bucket_name"), d, config) if err != nil { @@ -130,6 +125,10 @@ func resourceComputeBackendBucketCreate(d *schema.ResourceData, meta interface{} } d.SetId(id) + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { @@ -197,11 +196,6 @@ func resourceComputeBackendBucketRead(d *schema.ResourceData, meta interface{}) func resourceComputeBackendBucketUpdate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - obj := make(map[string]interface{}) bucketNameProp, err := expandComputeBackendBucketBucketName(d.Get("bucket_name"), d, config) if err != nil { @@ -240,6 +234,10 @@ func resourceComputeBackendBucketUpdate(d *schema.ResourceData, meta interface{} return fmt.Errorf("Error updating BackendBucket %q: %s", d.Id(), err) } + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { @@ -260,22 +258,22 @@ func resourceComputeBackendBucketUpdate(d *schema.ResourceData, meta interface{} func resourceComputeBackendBucketDelete(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/backendBuckets/{{name}}") if err != nil { return err } + var obj map[string]interface{} log.Printf("[DEBUG] Deleting BackendBucket %q", d.Id()) - res, err := sendRequest(config, "DELETE", url, nil) + res, err := sendRequest(config, "DELETE", url, obj) if err != nil { return handleNotFoundError(err, d, "BackendBucket") } + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { diff --git a/google/resource_compute_disk.go b/google/resource_compute_disk.go index 502d5e2134c..ea34376e251 100644 --- a/google/resource_compute_disk.go +++ b/google/resource_compute_disk.go @@ -439,11 +439,6 @@ func resourceComputeDisk() *schema.Resource { func resourceComputeDiskCreate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - obj := make(map[string]interface{}) descriptionProp, err := expandComputeDiskDescription(d.Get("description"), d, config) if err != nil { @@ -535,6 +530,10 @@ func resourceComputeDiskCreate(d *schema.ResourceData, meta interface{}) error { } d.SetId(id) + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { @@ -646,15 +645,6 @@ func resourceComputeDiskRead(d *schema.ResourceData, meta interface{}) error { func resourceComputeDiskUpdate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - - var url string - var res map[string]interface{} - op := &compute.Operation{} - d.Partial(true) if d.HasChange("label_fingerprint") || d.HasChange("labels") { @@ -668,15 +658,20 @@ func resourceComputeDiskUpdate(d *schema.ResourceData, meta interface{}) error { obj["labels"] = labelsProp } - url, err = replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/zones/{{zone}}/disks/{{name}}/setLabels") + url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/zones/{{zone}}/disks/{{name}}/setLabels") if err != nil { return err } - res, err = sendRequest(config, "POST", url, obj) + res, err := sendRequest(config, "POST", url, obj) if err != nil { return fmt.Errorf("Error updating Disk %q: %s", d.Id(), err) } + project, err := getProject(d, config) + if err != nil { + return err + } + op := &compute.Operation{} err = Convert(res, op) if err != nil { return err @@ -702,15 +697,20 @@ func resourceComputeDiskUpdate(d *schema.ResourceData, meta interface{}) error { obj["sizeGb"] = sizeGbProp } - url, err = replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/zones/{{zone}}/disks/{{name}}/resize") + url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/zones/{{zone}}/disks/{{name}}/resize") if err != nil { return err } - res, err = sendRequest(config, "POST", url, obj) + res, err := sendRequest(config, "POST", url, obj) if err != nil { return fmt.Errorf("Error updating Disk %q: %s", d.Id(), err) } + project, err := getProject(d, config) + if err != nil { + return err + } + op := &compute.Operation{} err = Convert(res, op) if err != nil { return err @@ -735,16 +735,12 @@ func resourceComputeDiskUpdate(d *schema.ResourceData, meta interface{}) error { func resourceComputeDiskDelete(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/zones/{{zone}}/disks/{{name}}") if err != nil { return err } + var obj map[string]interface{} // if disks are attached, they must be detached before the disk can be deleted if instances, ok := d.Get("users").([]interface{}); ok { type detachArgs struct{ project, zone, instance, deviceName string } @@ -769,7 +765,7 @@ func resourceComputeDiskDelete(d *schema.ResourceData, meta interface{}) error { for _, disk := range i.Disks { if disk.Source == self { detachCalls = append(detachCalls, detachArgs{ - project: project, + project: instanceProject, zone: GetResourceNameFromSelfLink(i.Zone), instance: i.Name, deviceName: disk.DeviceName, @@ -795,11 +791,15 @@ func resourceComputeDiskDelete(d *schema.ResourceData, meta interface{}) error { } } log.Printf("[DEBUG] Deleting Disk %q", d.Id()) - res, err := sendRequest(config, "DELETE", url, nil) + res, err := sendRequest(config, "DELETE", url, obj) if err != nil { return handleNotFoundError(err, d, "Disk") } + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { diff --git a/google/resource_compute_forwarding_rule.go b/google/resource_compute_forwarding_rule.go index 2c762455e39..86a7e3a9597 100644 --- a/google/resource_compute_forwarding_rule.go +++ b/google/resource_compute_forwarding_rule.go @@ -176,11 +176,6 @@ func resourceComputeForwardingRule() *schema.Resource { func resourceComputeForwardingRuleCreate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - obj := make(map[string]interface{}) descriptionProp, err := expandComputeForwardingRuleDescription(d.Get("description"), d, config) if err != nil { @@ -297,6 +292,10 @@ func resourceComputeForwardingRuleCreate(d *schema.ResourceData, meta interface{ } d.SetId(id) + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { @@ -444,15 +443,6 @@ func resourceComputeForwardingRuleRead(d *schema.ResourceData, meta interface{}) func resourceComputeForwardingRuleUpdate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - - var url string - var res map[string]interface{} - op := &compute.Operation{} - d.Partial(true) if d.HasChange("target") { @@ -464,15 +454,20 @@ func resourceComputeForwardingRuleUpdate(d *schema.ResourceData, meta interface{ obj["target"] = targetProp } - url, err = replaceVars(d, config, "https://www.googleapis.com/compute/beta/projects/{{project}}/regions/{{region}}/forwardingRules/{{name}}/setTarget") + url, err := replaceVars(d, config, "https://www.googleapis.com/compute/beta/projects/{{project}}/regions/{{region}}/forwardingRules/{{name}}/setTarget") if err != nil { return err } - res, err = sendRequest(config, "POST", url, obj) + res, err := sendRequest(config, "POST", url, obj) if err != nil { return fmt.Errorf("Error updating ForwardingRule %q: %s", d.Id(), err) } + project, err := getProject(d, config) + if err != nil { + return err + } + op := &compute.Operation{} err = Convert(res, op) if err != nil { return err @@ -499,15 +494,20 @@ func resourceComputeForwardingRuleUpdate(d *schema.ResourceData, meta interface{ labelFingerprintProp := d.Get("label_fingerprint") obj["labelFingerprint"] = labelFingerprintProp - url, err = replaceVars(d, config, "https://www.googleapis.com/compute/beta/projects/{{project}}/regions/{{region}}/forwardingRules/{{name}}/setLabels") + url, err := replaceVars(d, config, "https://www.googleapis.com/compute/beta/projects/{{project}}/regions/{{region}}/forwardingRules/{{name}}/setLabels") if err != nil { return err } - res, err = sendRequest(config, "POST", url, obj) + res, err := sendRequest(config, "POST", url, obj) if err != nil { return fmt.Errorf("Error updating ForwardingRule %q: %s", d.Id(), err) } + project, err := getProject(d, config) + if err != nil { + return err + } + op := &compute.Operation{} err = Convert(res, op) if err != nil { return err @@ -533,22 +533,22 @@ func resourceComputeForwardingRuleUpdate(d *schema.ResourceData, meta interface{ func resourceComputeForwardingRuleDelete(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - url, err := replaceVars(d, config, "https://www.googleapis.com/compute/beta/projects/{{project}}/regions/{{region}}/forwardingRules/{{name}}") if err != nil { return err } + var obj map[string]interface{} log.Printf("[DEBUG] Deleting ForwardingRule %q", d.Id()) - res, err := sendRequest(config, "DELETE", url, nil) + res, err := sendRequest(config, "DELETE", url, obj) if err != nil { return handleNotFoundError(err, d, "ForwardingRule") } + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { diff --git a/google/resource_compute_global_address.go b/google/resource_compute_global_address.go index 219b8d8b906..a33588f230a 100644 --- a/google/resource_compute_global_address.go +++ b/google/resource_compute_global_address.go @@ -94,11 +94,6 @@ func resourceComputeGlobalAddress() *schema.Resource { func resourceComputeGlobalAddressCreate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - obj := make(map[string]interface{}) descriptionProp, err := expandComputeGlobalAddressDescription(d.Get("description"), d, config) if err != nil { @@ -143,6 +138,10 @@ func resourceComputeGlobalAddressCreate(d *schema.ResourceData, meta interface{} } d.SetId(id) + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { @@ -254,15 +253,6 @@ func resourceComputeGlobalAddressRead(d *schema.ResourceData, meta interface{}) func resourceComputeGlobalAddressUpdate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - - var url string - var res map[string]interface{} - op := &compute.Operation{} - d.Partial(true) if d.HasChange("labels") || d.HasChange("label_fingerprint") { @@ -276,15 +266,20 @@ func resourceComputeGlobalAddressUpdate(d *schema.ResourceData, meta interface{} labelFingerprintProp := d.Get("label_fingerprint") obj["labelFingerprint"] = labelFingerprintProp - url, err = replaceVars(d, config, "https://www.googleapis.com/compute/beta/projects/{{project}}/global/addresses/{{name}}/setLabels") + url, err := replaceVars(d, config, "https://www.googleapis.com/compute/beta/projects/{{project}}/global/addresses/{{name}}/setLabels") if err != nil { return err } - res, err = sendRequest(config, "POST", url, obj) + res, err := sendRequest(config, "POST", url, obj) if err != nil { return fmt.Errorf("Error updating GlobalAddress %q: %s", d.Id(), err) } + project, err := getProject(d, config) + if err != nil { + return err + } + op := &compute.Operation{} err = Convert(res, op) if err != nil { return err @@ -310,22 +305,22 @@ func resourceComputeGlobalAddressUpdate(d *schema.ResourceData, meta interface{} func resourceComputeGlobalAddressDelete(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - url, err := replaceVars(d, config, "https://www.googleapis.com/compute/beta/projects/{{project}}/global/addresses/{{name}}") if err != nil { return err } + var obj map[string]interface{} log.Printf("[DEBUG] Deleting GlobalAddress %q", d.Id()) - res, err := sendRequest(config, "DELETE", url, nil) + res, err := sendRequest(config, "DELETE", url, obj) if err != nil { return handleNotFoundError(err, d, "GlobalAddress") } + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { diff --git a/google/resource_compute_http_health_check.go b/google/resource_compute_http_health_check.go index 154f2c136a6..663981d7e8e 100644 --- a/google/resource_compute_http_health_check.go +++ b/google/resource_compute_http_health_check.go @@ -107,11 +107,6 @@ func resourceComputeHttpHealthCheck() *schema.Resource { func resourceComputeHttpHealthCheckCreate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - obj := make(map[string]interface{}) checkIntervalSecProp, err := expandComputeHttpHealthCheckCheckIntervalSec(d.Get("check_interval_sec"), d, config) if err != nil { @@ -186,6 +181,10 @@ func resourceComputeHttpHealthCheckCreate(d *schema.ResourceData, meta interface } d.SetId(id) + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { @@ -268,11 +267,6 @@ func resourceComputeHttpHealthCheckRead(d *schema.ResourceData, meta interface{} func resourceComputeHttpHealthCheckUpdate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - obj := make(map[string]interface{}) checkIntervalSecProp, err := expandComputeHttpHealthCheckCheckIntervalSec(d.Get("check_interval_sec"), d, config) if err != nil { @@ -341,6 +335,10 @@ func resourceComputeHttpHealthCheckUpdate(d *schema.ResourceData, meta interface return fmt.Errorf("Error updating HttpHealthCheck %q: %s", d.Id(), err) } + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { @@ -361,22 +359,22 @@ func resourceComputeHttpHealthCheckUpdate(d *schema.ResourceData, meta interface func resourceComputeHttpHealthCheckDelete(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/httpHealthChecks/{{name}}") if err != nil { return err } + var obj map[string]interface{} log.Printf("[DEBUG] Deleting HttpHealthCheck %q", d.Id()) - res, err := sendRequest(config, "DELETE", url, nil) + res, err := sendRequest(config, "DELETE", url, obj) if err != nil { return handleNotFoundError(err, d, "HttpHealthCheck") } + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { diff --git a/google/resource_compute_https_health_check.go b/google/resource_compute_https_health_check.go index a0a9e47753c..1f8aed0dd6f 100644 --- a/google/resource_compute_https_health_check.go +++ b/google/resource_compute_https_health_check.go @@ -107,11 +107,6 @@ func resourceComputeHttpsHealthCheck() *schema.Resource { func resourceComputeHttpsHealthCheckCreate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - obj := make(map[string]interface{}) checkIntervalSecProp, err := expandComputeHttpsHealthCheckCheckIntervalSec(d.Get("check_interval_sec"), d, config) if err != nil { @@ -186,6 +181,10 @@ func resourceComputeHttpsHealthCheckCreate(d *schema.ResourceData, meta interfac } d.SetId(id) + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { @@ -268,11 +267,6 @@ func resourceComputeHttpsHealthCheckRead(d *schema.ResourceData, meta interface{ func resourceComputeHttpsHealthCheckUpdate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - obj := make(map[string]interface{}) checkIntervalSecProp, err := expandComputeHttpsHealthCheckCheckIntervalSec(d.Get("check_interval_sec"), d, config) if err != nil { @@ -341,6 +335,10 @@ func resourceComputeHttpsHealthCheckUpdate(d *schema.ResourceData, meta interfac return fmt.Errorf("Error updating HttpsHealthCheck %q: %s", d.Id(), err) } + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { @@ -361,22 +359,22 @@ func resourceComputeHttpsHealthCheckUpdate(d *schema.ResourceData, meta interfac func resourceComputeHttpsHealthCheckDelete(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/httpsHealthChecks/{{name}}") if err != nil { return err } + var obj map[string]interface{} log.Printf("[DEBUG] Deleting HttpsHealthCheck %q", d.Id()) - res, err := sendRequest(config, "DELETE", url, nil) + res, err := sendRequest(config, "DELETE", url, obj) if err != nil { return handleNotFoundError(err, d, "HttpsHealthCheck") } + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { diff --git a/google/resource_compute_region_autoscaler.go b/google/resource_compute_region_autoscaler.go index e69054b5691..e1536bfb377 100644 --- a/google/resource_compute_region_autoscaler.go +++ b/google/resource_compute_region_autoscaler.go @@ -156,11 +156,6 @@ func resourceComputeRegionAutoscaler() *schema.Resource { func resourceComputeRegionAutoscalerCreate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - obj := make(map[string]interface{}) nameProp, err := expandComputeRegionAutoscalerName(d.Get("name"), d, config) if err != nil { @@ -211,6 +206,10 @@ func resourceComputeRegionAutoscalerCreate(d *schema.ResourceData, meta interfac } d.SetId(id) + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { @@ -281,11 +280,6 @@ func resourceComputeRegionAutoscalerRead(d *schema.ResourceData, meta interface{ func resourceComputeRegionAutoscalerUpdate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - obj := make(map[string]interface{}) nameProp, err := expandComputeRegionAutoscalerName(d.Get("name"), d, config) if err != nil { @@ -330,6 +324,10 @@ func resourceComputeRegionAutoscalerUpdate(d *schema.ResourceData, meta interfac return fmt.Errorf("Error updating RegionAutoscaler %q: %s", d.Id(), err) } + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { @@ -350,22 +348,22 @@ func resourceComputeRegionAutoscalerUpdate(d *schema.ResourceData, meta interfac func resourceComputeRegionAutoscalerDelete(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/regions/{{region}}/autoscalers/{{name}}") if err != nil { return err } + var obj map[string]interface{} log.Printf("[DEBUG] Deleting RegionAutoscaler %q", d.Id()) - res, err := sendRequest(config, "DELETE", url, nil) + res, err := sendRequest(config, "DELETE", url, obj) if err != nil { return handleNotFoundError(err, d, "RegionAutoscaler") } + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { diff --git a/google/resource_compute_region_disk.go b/google/resource_compute_region_disk.go index f241880d85c..a08a924c9c2 100644 --- a/google/resource_compute_region_disk.go +++ b/google/resource_compute_region_disk.go @@ -182,11 +182,6 @@ func resourceComputeRegionDisk() *schema.Resource { func resourceComputeRegionDiskCreate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - obj := make(map[string]interface{}) descriptionProp, err := expandComputeRegionDiskDescription(d.Get("description"), d, config) if err != nil { @@ -272,6 +267,10 @@ func resourceComputeRegionDiskCreate(d *schema.ResourceData, meta interface{}) e } d.SetId(id) + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { @@ -377,15 +376,6 @@ func resourceComputeRegionDiskRead(d *schema.ResourceData, meta interface{}) err func resourceComputeRegionDiskUpdate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - - var url string - var res map[string]interface{} - op := &compute.Operation{} - d.Partial(true) if d.HasChange("label_fingerprint") || d.HasChange("labels") { @@ -399,15 +389,20 @@ func resourceComputeRegionDiskUpdate(d *schema.ResourceData, meta interface{}) e obj["labels"] = labelsProp } - url, err = replaceVars(d, config, "https://www.googleapis.com/compute/beta/projects/{{project}}/regions/{{region}}/disks/{{name}}/setLabels") + url, err := replaceVars(d, config, "https://www.googleapis.com/compute/beta/projects/{{project}}/regions/{{region}}/disks/{{name}}/setLabels") if err != nil { return err } - res, err = sendRequest(config, "POST", url, obj) + res, err := sendRequest(config, "POST", url, obj) if err != nil { return fmt.Errorf("Error updating RegionDisk %q: %s", d.Id(), err) } + project, err := getProject(d, config) + if err != nil { + return err + } + op := &compute.Operation{} err = Convert(res, op) if err != nil { return err @@ -433,15 +428,20 @@ func resourceComputeRegionDiskUpdate(d *schema.ResourceData, meta interface{}) e obj["sizeGb"] = sizeGbProp } - url, err = replaceVars(d, config, "https://www.googleapis.com/compute/beta/projects/{{project}}/regions/{{region}}/disks/{{name}}/resize") + url, err := replaceVars(d, config, "https://www.googleapis.com/compute/beta/projects/{{project}}/regions/{{region}}/disks/{{name}}/resize") if err != nil { return err } - res, err = sendRequest(config, "POST", url, obj) + res, err := sendRequest(config, "POST", url, obj) if err != nil { return fmt.Errorf("Error updating RegionDisk %q: %s", d.Id(), err) } + project, err := getProject(d, config) + if err != nil { + return err + } + op := &compute.Operation{} err = Convert(res, op) if err != nil { return err @@ -466,16 +466,12 @@ func resourceComputeRegionDiskUpdate(d *schema.ResourceData, meta interface{}) e func resourceComputeRegionDiskDelete(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - url, err := replaceVars(d, config, "https://www.googleapis.com/compute/beta/projects/{{project}}/regions/{{region}}/disks/{{name}}") if err != nil { return err } + var obj map[string]interface{} // if disks are attached, they must be detached before the disk can be deleted if instances, ok := d.Get("users").([]interface{}); ok { type detachArgs struct{ project, zone, instance, deviceName string } @@ -500,7 +496,7 @@ func resourceComputeRegionDiskDelete(d *schema.ResourceData, meta interface{}) e for _, disk := range i.Disks { if disk.Source == self { detachCalls = append(detachCalls, detachArgs{ - project: project, + project: instanceProject, zone: GetResourceNameFromSelfLink(i.Zone), instance: i.Name, deviceName: disk.DeviceName, @@ -526,11 +522,15 @@ func resourceComputeRegionDiskDelete(d *schema.ResourceData, meta interface{}) e } } log.Printf("[DEBUG] Deleting RegionDisk %q", d.Id()) - res, err := sendRequest(config, "DELETE", url, nil) + res, err := sendRequest(config, "DELETE", url, obj) if err != nil { return handleNotFoundError(err, d, "RegionDisk") } + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { diff --git a/google/resource_compute_route.go b/google/resource_compute_route.go index 5a86ebd2269..ac596f801a4 100644 --- a/google/resource_compute_route.go +++ b/google/resource_compute_route.go @@ -126,11 +126,6 @@ func resourceComputeRoute() *schema.Resource { func resourceComputeRouteCreate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - obj := make(map[string]interface{}) destRangeProp, err := expandComputeRouteDestRange(d.Get("dest_range"), d, config) if err != nil { @@ -211,6 +206,10 @@ func resourceComputeRouteCreate(d *schema.ResourceData, meta interface{}) error } d.SetId(id) + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { @@ -301,22 +300,22 @@ func resourceComputeRouteRead(d *schema.ResourceData, meta interface{}) error { func resourceComputeRouteDelete(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/routes/{{name}}") if err != nil { return err } + var obj map[string]interface{} log.Printf("[DEBUG] Deleting Route %q", d.Id()) - res, err := sendRequest(config, "DELETE", url, nil) + res, err := sendRequest(config, "DELETE", url, obj) if err != nil { return handleNotFoundError(err, d, "Route") } + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { diff --git a/google/resource_compute_router.go b/google/resource_compute_router.go index 9ee9fff311c..0db9f4e46d4 100644 --- a/google/resource_compute_router.go +++ b/google/resource_compute_router.go @@ -130,11 +130,6 @@ func resourceComputeRouter() *schema.Resource { func resourceComputeRouterCreate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - obj := make(map[string]interface{}) nameProp, err := expandComputeRouterName(d.Get("name"), d, config) if err != nil { @@ -192,6 +187,10 @@ func resourceComputeRouterCreate(d *schema.ResourceData, meta interface{}) error } d.SetId(id) + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { @@ -262,11 +261,6 @@ func resourceComputeRouterRead(d *schema.ResourceData, meta interface{}) error { func resourceComputeRouterUpdate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - obj := make(map[string]interface{}) nameProp, err := expandComputeRouterName(d.Get("name"), d, config) if err != nil { @@ -318,6 +312,10 @@ func resourceComputeRouterUpdate(d *schema.ResourceData, meta interface{}) error return fmt.Errorf("Error updating Router %q: %s", d.Id(), err) } + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { @@ -338,11 +336,6 @@ func resourceComputeRouterUpdate(d *schema.ResourceData, meta interface{}) error func resourceComputeRouterDelete(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - lockName, err := replaceVars(d, config, "router/{{region}}/{{name}}") if err != nil { return err @@ -355,12 +348,17 @@ func resourceComputeRouterDelete(d *schema.ResourceData, meta interface{}) error return err } + var obj map[string]interface{} log.Printf("[DEBUG] Deleting Router %q", d.Id()) - res, err := sendRequest(config, "DELETE", url, nil) + res, err := sendRequest(config, "DELETE", url, obj) if err != nil { return handleNotFoundError(err, d, "Router") } + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { diff --git a/google/resource_compute_ssl_policy.go b/google/resource_compute_ssl_policy.go index 2c41e9216cd..9caed40a84a 100644 --- a/google/resource_compute_ssl_policy.go +++ b/google/resource_compute_ssl_policy.go @@ -128,11 +128,6 @@ func resourceComputeSslPolicy() *schema.Resource { func resourceComputeSslPolicyCreate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - obj := make(map[string]interface{}) descriptionProp, err := expandComputeSslPolicyDescription(d.Get("description"), d, config) if err != nil { @@ -183,6 +178,10 @@ func resourceComputeSslPolicyCreate(d *schema.ResourceData, meta interface{}) er } d.SetId(id) + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { @@ -259,11 +258,6 @@ func resourceComputeSslPolicyRead(d *schema.ResourceData, meta interface{}) erro func resourceComputeSslPolicyUpdate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - obj := make(map[string]interface{}) descriptionProp, err := expandComputeSslPolicyDescription(d.Get("description"), d, config) if err != nil { @@ -310,6 +304,10 @@ func resourceComputeSslPolicyUpdate(d *schema.ResourceData, meta interface{}) er return fmt.Errorf("Error updating SslPolicy %q: %s", d.Id(), err) } + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { @@ -330,22 +328,22 @@ func resourceComputeSslPolicyUpdate(d *schema.ResourceData, meta interface{}) er func resourceComputeSslPolicyDelete(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/sslPolicies/{{name}}") if err != nil { return err } + var obj map[string]interface{} log.Printf("[DEBUG] Deleting SslPolicy %q", d.Id()) - res, err := sendRequest(config, "DELETE", url, nil) + res, err := sendRequest(config, "DELETE", url, obj) if err != nil { return handleNotFoundError(err, d, "SslPolicy") } + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { diff --git a/google/resource_compute_subnetwork.go b/google/resource_compute_subnetwork.go index 2ef5c249e1e..e61f7c00747 100644 --- a/google/resource_compute_subnetwork.go +++ b/google/resource_compute_subnetwork.go @@ -203,11 +203,6 @@ func resourceComputeSubnetworkSecondaryIpRangeSetStyleDiff(diff *schema.Resource func resourceComputeSubnetworkCreate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - obj := make(map[string]interface{}) descriptionProp, err := expandComputeSubnetworkDescription(d.Get("description"), d, config) if err != nil { @@ -276,6 +271,10 @@ func resourceComputeSubnetworkCreate(d *schema.ResourceData, meta interface{}) e } d.SetId(id) + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { @@ -361,15 +360,6 @@ func resourceComputeSubnetworkRead(d *schema.ResourceData, meta interface{}) err func resourceComputeSubnetworkUpdate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - - var url string - var res map[string]interface{} - op := &compute.Operation{} - d.Partial(true) if d.HasChange("ip_cidr_range") { @@ -381,15 +371,20 @@ func resourceComputeSubnetworkUpdate(d *schema.ResourceData, meta interface{}) e obj["ipCidrRange"] = ipCidrRangeProp } - url, err = replaceVars(d, config, "https://www.googleapis.com/compute/beta/projects/{{project}}/regions/{{region}}/subnetworks/{{name}}/expandIpCidrRange") + url, err := replaceVars(d, config, "https://www.googleapis.com/compute/beta/projects/{{project}}/regions/{{region}}/subnetworks/{{name}}/expandIpCidrRange") if err != nil { return err } - res, err = sendRequest(config, "POST", url, obj) + res, err := sendRequest(config, "POST", url, obj) if err != nil { return fmt.Errorf("Error updating Subnetwork %q: %s", d.Id(), err) } + project, err := getProject(d, config) + if err != nil { + return err + } + op := &compute.Operation{} err = Convert(res, op) if err != nil { return err @@ -422,15 +417,20 @@ func resourceComputeSubnetworkUpdate(d *schema.ResourceData, meta interface{}) e obj["secondaryIpRanges"] = secondaryIpRangesProp } - url, err = replaceVars(d, config, "https://www.googleapis.com/compute/beta/projects/{{project}}/regions/{{region}}/subnetworks/{{name}}") + url, err := replaceVars(d, config, "https://www.googleapis.com/compute/beta/projects/{{project}}/regions/{{region}}/subnetworks/{{name}}") if err != nil { return err } - res, err = sendRequest(config, "PATCH", url, obj) + res, err := sendRequest(config, "PATCH", url, obj) if err != nil { return fmt.Errorf("Error updating Subnetwork %q: %s", d.Id(), err) } + project, err := getProject(d, config) + if err != nil { + return err + } + op := &compute.Operation{} err = Convert(res, op) if err != nil { return err @@ -457,15 +457,20 @@ func resourceComputeSubnetworkUpdate(d *schema.ResourceData, meta interface{}) e obj["privateIpGoogleAccess"] = privateIpGoogleAccessProp } - url, err = replaceVars(d, config, "https://www.googleapis.com/compute/beta/projects/{{project}}/regions/{{region}}/subnetworks/{{name}}/setPrivateIpGoogleAccess") + url, err := replaceVars(d, config, "https://www.googleapis.com/compute/beta/projects/{{project}}/regions/{{region}}/subnetworks/{{name}}/setPrivateIpGoogleAccess") if err != nil { return err } - res, err = sendRequest(config, "POST", url, obj) + res, err := sendRequest(config, "POST", url, obj) if err != nil { return fmt.Errorf("Error updating Subnetwork %q: %s", d.Id(), err) } + project, err := getProject(d, config) + if err != nil { + return err + } + op := &compute.Operation{} err = Convert(res, op) if err != nil { return err @@ -490,22 +495,22 @@ func resourceComputeSubnetworkUpdate(d *schema.ResourceData, meta interface{}) e func resourceComputeSubnetworkDelete(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - url, err := replaceVars(d, config, "https://www.googleapis.com/compute/beta/projects/{{project}}/regions/{{region}}/subnetworks/{{name}}") if err != nil { return err } + var obj map[string]interface{} log.Printf("[DEBUG] Deleting Subnetwork %q", d.Id()) - res, err := sendRequest(config, "DELETE", url, nil) + res, err := sendRequest(config, "DELETE", url, obj) if err != nil { return handleNotFoundError(err, d, "Subnetwork") } + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { diff --git a/google/resource_compute_target_http_proxy.go b/google/resource_compute_target_http_proxy.go index 08af56b9a02..2a365613432 100644 --- a/google/resource_compute_target_http_proxy.go +++ b/google/resource_compute_target_http_proxy.go @@ -83,11 +83,6 @@ func resourceComputeTargetHttpProxy() *schema.Resource { func resourceComputeTargetHttpProxyCreate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - obj := make(map[string]interface{}) descriptionProp, err := expandComputeTargetHttpProxyDescription(d.Get("description"), d, config) if err != nil { @@ -126,6 +121,10 @@ func resourceComputeTargetHttpProxyCreate(d *schema.ResourceData, meta interface } d.SetId(id) + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { @@ -193,15 +192,6 @@ func resourceComputeTargetHttpProxyRead(d *schema.ResourceData, meta interface{} func resourceComputeTargetHttpProxyUpdate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - - var url string - var res map[string]interface{} - op := &compute.Operation{} - d.Partial(true) if d.HasChange("url_map") { @@ -213,15 +203,20 @@ func resourceComputeTargetHttpProxyUpdate(d *schema.ResourceData, meta interface obj["urlMap"] = urlMapProp } - url, err = replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/targetHttpProxies/{{name}}/setUrlMap") + url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/targetHttpProxies/{{name}}/setUrlMap") if err != nil { return err } - res, err = sendRequest(config, "POST", url, obj) + res, err := sendRequest(config, "POST", url, obj) if err != nil { return fmt.Errorf("Error updating TargetHttpProxy %q: %s", d.Id(), err) } + project, err := getProject(d, config) + if err != nil { + return err + } + op := &compute.Operation{} err = Convert(res, op) if err != nil { return err @@ -246,22 +241,22 @@ func resourceComputeTargetHttpProxyUpdate(d *schema.ResourceData, meta interface func resourceComputeTargetHttpProxyDelete(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/targetHttpProxies/{{name}}") if err != nil { return err } + var obj map[string]interface{} log.Printf("[DEBUG] Deleting TargetHttpProxy %q", d.Id()) - res, err := sendRequest(config, "DELETE", url, nil) + res, err := sendRequest(config, "DELETE", url, obj) if err != nil { return handleNotFoundError(err, d, "TargetHttpProxy") } + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { diff --git a/google/resource_compute_target_https_proxy.go b/google/resource_compute_target_https_proxy.go index 700b65b5126..4bcfa2ea47e 100644 --- a/google/resource_compute_target_https_proxy.go +++ b/google/resource_compute_target_https_proxy.go @@ -102,11 +102,6 @@ func resourceComputeTargetHttpsProxy() *schema.Resource { func resourceComputeTargetHttpsProxyCreate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - obj := make(map[string]interface{}) descriptionProp, err := expandComputeTargetHttpsProxyDescription(d.Get("description"), d, config) if err != nil { @@ -163,6 +158,10 @@ func resourceComputeTargetHttpsProxyCreate(d *schema.ResourceData, meta interfac } d.SetId(id) + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { @@ -239,15 +238,6 @@ func resourceComputeTargetHttpsProxyRead(d *schema.ResourceData, meta interface{ func resourceComputeTargetHttpsProxyUpdate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - - var url string - var res map[string]interface{} - op := &compute.Operation{} - d.Partial(true) if d.HasChange("quic_override") { @@ -259,15 +249,20 @@ func resourceComputeTargetHttpsProxyUpdate(d *schema.ResourceData, meta interfac obj["quicOverride"] = quicOverrideProp } - url, err = replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/targetHttpsProxies/{{name}}/setQuicOverride") + url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/targetHttpsProxies/{{name}}/setQuicOverride") if err != nil { return err } - res, err = sendRequest(config, "POST", url, obj) + res, err := sendRequest(config, "POST", url, obj) if err != nil { return fmt.Errorf("Error updating TargetHttpsProxy %q: %s", d.Id(), err) } + project, err := getProject(d, config) + if err != nil { + return err + } + op := &compute.Operation{} err = Convert(res, op) if err != nil { return err @@ -292,15 +287,20 @@ func resourceComputeTargetHttpsProxyUpdate(d *schema.ResourceData, meta interfac obj["sslCertificates"] = sslCertificatesProp } - url, err = replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/targetHttpsProxies/{{name}}/setSslCertificates") + url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/targetHttpsProxies/{{name}}/setSslCertificates") if err != nil { return err } - res, err = sendRequest(config, "POST", url, obj) + res, err := sendRequest(config, "POST", url, obj) if err != nil { return fmt.Errorf("Error updating TargetHttpsProxy %q: %s", d.Id(), err) } + project, err := getProject(d, config) + if err != nil { + return err + } + op := &compute.Operation{} err = Convert(res, op) if err != nil { return err @@ -325,15 +325,20 @@ func resourceComputeTargetHttpsProxyUpdate(d *schema.ResourceData, meta interfac obj["sslPolicy"] = sslPolicyProp } - url, err = replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/targetHttpsProxies/{{name}}/setSslPolicy") + url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/targetHttpsProxies/{{name}}/setSslPolicy") if err != nil { return err } - res, err = sendRequest(config, "POST", url, obj) + res, err := sendRequest(config, "POST", url, obj) if err != nil { return fmt.Errorf("Error updating TargetHttpsProxy %q: %s", d.Id(), err) } + project, err := getProject(d, config) + if err != nil { + return err + } + op := &compute.Operation{} err = Convert(res, op) if err != nil { return err @@ -358,15 +363,20 @@ func resourceComputeTargetHttpsProxyUpdate(d *schema.ResourceData, meta interfac obj["urlMap"] = urlMapProp } - url, err = replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/targetHttpsProxies/{{name}}/setUrlMap") + url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/targetHttpsProxies/{{name}}/setUrlMap") if err != nil { return err } - res, err = sendRequest(config, "POST", url, obj) + res, err := sendRequest(config, "POST", url, obj) if err != nil { return fmt.Errorf("Error updating TargetHttpsProxy %q: %s", d.Id(), err) } + project, err := getProject(d, config) + if err != nil { + return err + } + op := &compute.Operation{} err = Convert(res, op) if err != nil { return err @@ -391,22 +401,22 @@ func resourceComputeTargetHttpsProxyUpdate(d *schema.ResourceData, meta interfac func resourceComputeTargetHttpsProxyDelete(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/targetHttpsProxies/{{name}}") if err != nil { return err } + var obj map[string]interface{} log.Printf("[DEBUG] Deleting TargetHttpsProxy %q", d.Id()) - res, err := sendRequest(config, "DELETE", url, nil) + res, err := sendRequest(config, "DELETE", url, obj) if err != nil { return handleNotFoundError(err, d, "TargetHttpsProxy") } + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { diff --git a/google/resource_compute_target_ssl_proxy.go b/google/resource_compute_target_ssl_proxy.go index 082132e34a2..75ec3a4bbf7 100644 --- a/google/resource_compute_target_ssl_proxy.go +++ b/google/resource_compute_target_ssl_proxy.go @@ -104,11 +104,6 @@ func resourceComputeTargetSslProxy() *schema.Resource { func resourceComputeTargetSslProxyCreate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - obj := make(map[string]interface{}) descriptionProp, err := expandComputeTargetSslProxyDescription(d.Get("description"), d, config) if err != nil { @@ -165,6 +160,10 @@ func resourceComputeTargetSslProxyCreate(d *schema.ResourceData, meta interface{ } d.SetId(id) + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { @@ -241,15 +240,6 @@ func resourceComputeTargetSslProxyRead(d *schema.ResourceData, meta interface{}) func resourceComputeTargetSslProxyUpdate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - - var url string - var res map[string]interface{} - op := &compute.Operation{} - d.Partial(true) if d.HasChange("proxy_header") { @@ -261,15 +251,20 @@ func resourceComputeTargetSslProxyUpdate(d *schema.ResourceData, meta interface{ obj["proxyHeader"] = proxyHeaderProp } - url, err = replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/targetSslProxies/{{name}}/setProxyHeader") + url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/targetSslProxies/{{name}}/setProxyHeader") if err != nil { return err } - res, err = sendRequest(config, "POST", url, obj) + res, err := sendRequest(config, "POST", url, obj) if err != nil { return fmt.Errorf("Error updating TargetSslProxy %q: %s", d.Id(), err) } + project, err := getProject(d, config) + if err != nil { + return err + } + op := &compute.Operation{} err = Convert(res, op) if err != nil { return err @@ -294,15 +289,20 @@ func resourceComputeTargetSslProxyUpdate(d *schema.ResourceData, meta interface{ obj["service"] = serviceProp } - url, err = replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/targetSslProxies/{{name}}/setBackendService") + url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/targetSslProxies/{{name}}/setBackendService") if err != nil { return err } - res, err = sendRequest(config, "POST", url, obj) + res, err := sendRequest(config, "POST", url, obj) if err != nil { return fmt.Errorf("Error updating TargetSslProxy %q: %s", d.Id(), err) } + project, err := getProject(d, config) + if err != nil { + return err + } + op := &compute.Operation{} err = Convert(res, op) if err != nil { return err @@ -327,15 +327,20 @@ func resourceComputeTargetSslProxyUpdate(d *schema.ResourceData, meta interface{ obj["sslCertificates"] = sslCertificatesProp } - url, err = replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/targetSslProxies/{{name}}/setSslCertificates") + url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/targetSslProxies/{{name}}/setSslCertificates") if err != nil { return err } - res, err = sendRequest(config, "POST", url, obj) + res, err := sendRequest(config, "POST", url, obj) if err != nil { return fmt.Errorf("Error updating TargetSslProxy %q: %s", d.Id(), err) } + project, err := getProject(d, config) + if err != nil { + return err + } + op := &compute.Operation{} err = Convert(res, op) if err != nil { return err @@ -360,15 +365,20 @@ func resourceComputeTargetSslProxyUpdate(d *schema.ResourceData, meta interface{ obj["sslPolicy"] = sslPolicyProp } - url, err = replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/targetSslProxies/{{name}}/setSslPolicy") + url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/targetSslProxies/{{name}}/setSslPolicy") if err != nil { return err } - res, err = sendRequest(config, "POST", url, obj) + res, err := sendRequest(config, "POST", url, obj) if err != nil { return fmt.Errorf("Error updating TargetSslProxy %q: %s", d.Id(), err) } + project, err := getProject(d, config) + if err != nil { + return err + } + op := &compute.Operation{} err = Convert(res, op) if err != nil { return err @@ -393,22 +403,22 @@ func resourceComputeTargetSslProxyUpdate(d *schema.ResourceData, meta interface{ func resourceComputeTargetSslProxyDelete(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/targetSslProxies/{{name}}") if err != nil { return err } + var obj map[string]interface{} log.Printf("[DEBUG] Deleting TargetSslProxy %q", d.Id()) - res, err := sendRequest(config, "DELETE", url, nil) + res, err := sendRequest(config, "DELETE", url, obj) if err != nil { return handleNotFoundError(err, d, "TargetSslProxy") } + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { diff --git a/google/resource_compute_target_tcp_proxy.go b/google/resource_compute_target_tcp_proxy.go index b42767510ce..c2017ce2712 100644 --- a/google/resource_compute_target_tcp_proxy.go +++ b/google/resource_compute_target_tcp_proxy.go @@ -90,11 +90,6 @@ func resourceComputeTargetTcpProxy() *schema.Resource { func resourceComputeTargetTcpProxyCreate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - obj := make(map[string]interface{}) descriptionProp, err := expandComputeTargetTcpProxyDescription(d.Get("description"), d, config) if err != nil { @@ -139,6 +134,10 @@ func resourceComputeTargetTcpProxyCreate(d *schema.ResourceData, meta interface{ } d.SetId(id) + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { @@ -209,15 +208,6 @@ func resourceComputeTargetTcpProxyRead(d *schema.ResourceData, meta interface{}) func resourceComputeTargetTcpProxyUpdate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - - var url string - var res map[string]interface{} - op := &compute.Operation{} - d.Partial(true) if d.HasChange("proxy_header") { @@ -229,15 +219,20 @@ func resourceComputeTargetTcpProxyUpdate(d *schema.ResourceData, meta interface{ obj["proxyHeader"] = proxyHeaderProp } - url, err = replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/targetTcpProxies/{{name}}/setProxyHeader") + url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/targetTcpProxies/{{name}}/setProxyHeader") if err != nil { return err } - res, err = sendRequest(config, "POST", url, obj) + res, err := sendRequest(config, "POST", url, obj) if err != nil { return fmt.Errorf("Error updating TargetTcpProxy %q: %s", d.Id(), err) } + project, err := getProject(d, config) + if err != nil { + return err + } + op := &compute.Operation{} err = Convert(res, op) if err != nil { return err @@ -262,15 +257,20 @@ func resourceComputeTargetTcpProxyUpdate(d *schema.ResourceData, meta interface{ obj["service"] = serviceProp } - url, err = replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/targetTcpProxies/{{name}}/setBackendService") + url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/targetTcpProxies/{{name}}/setBackendService") if err != nil { return err } - res, err = sendRequest(config, "POST", url, obj) + res, err := sendRequest(config, "POST", url, obj) if err != nil { return fmt.Errorf("Error updating TargetTcpProxy %q: %s", d.Id(), err) } + project, err := getProject(d, config) + if err != nil { + return err + } + op := &compute.Operation{} err = Convert(res, op) if err != nil { return err @@ -295,22 +295,22 @@ func resourceComputeTargetTcpProxyUpdate(d *schema.ResourceData, meta interface{ func resourceComputeTargetTcpProxyDelete(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/targetTcpProxies/{{name}}") if err != nil { return err } + var obj map[string]interface{} log.Printf("[DEBUG] Deleting TargetTcpProxy %q", d.Id()) - res, err := sendRequest(config, "DELETE", url, nil) + res, err := sendRequest(config, "DELETE", url, obj) if err != nil { return handleNotFoundError(err, d, "TargetTcpProxy") } + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { diff --git a/google/resource_compute_vpn_gateway.go b/google/resource_compute_vpn_gateway.go index 988b5b497f0..e015e3354d9 100644 --- a/google/resource_compute_vpn_gateway.go +++ b/google/resource_compute_vpn_gateway.go @@ -84,11 +84,6 @@ func resourceComputeVpnGateway() *schema.Resource { func resourceComputeVpnGatewayCreate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - obj := make(map[string]interface{}) descriptionProp, err := expandComputeVpnGatewayDescription(d.Get("description"), d, config) if err != nil { @@ -133,6 +128,10 @@ func resourceComputeVpnGatewayCreate(d *schema.ResourceData, meta interface{}) e } d.SetId(id) + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { @@ -200,22 +199,22 @@ func resourceComputeVpnGatewayRead(d *schema.ResourceData, meta interface{}) err func resourceComputeVpnGatewayDelete(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/regions/{{region}}/targetVpnGateways/{{name}}") if err != nil { return err } + var obj map[string]interface{} log.Printf("[DEBUG] Deleting VpnGateway %q", d.Id()) - res, err := sendRequest(config, "DELETE", url, nil) + res, err := sendRequest(config, "DELETE", url, obj) if err != nil { return handleNotFoundError(err, d, "VpnGateway") } + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { diff --git a/google/resource_compute_vpn_tunnel.go b/google/resource_compute_vpn_tunnel.go index 451867f2ecc..ef199bc0352 100644 --- a/google/resource_compute_vpn_tunnel.go +++ b/google/resource_compute_vpn_tunnel.go @@ -251,11 +251,6 @@ func resourceComputeVpnTunnel() *schema.Resource { func resourceComputeVpnTunnelCreate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - obj := make(map[string]interface{}) nameProp, err := expandComputeVpnTunnelName(d.Get("name"), d, config) if err != nil { @@ -342,6 +337,10 @@ func resourceComputeVpnTunnelCreate(d *schema.ResourceData, meta interface{}) er } d.SetId(id) + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { @@ -436,15 +435,6 @@ func resourceComputeVpnTunnelRead(d *schema.ResourceData, meta interface{}) erro func resourceComputeVpnTunnelUpdate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - - var url string - var res map[string]interface{} - op := &compute.Operation{} - d.Partial(true) if d.HasChange("labels") || d.HasChange("label_fingerprint") { @@ -458,15 +448,20 @@ func resourceComputeVpnTunnelUpdate(d *schema.ResourceData, meta interface{}) er labelFingerprintProp := d.Get("label_fingerprint") obj["labelFingerprint"] = labelFingerprintProp - url, err = replaceVars(d, config, "https://www.googleapis.com/compute/beta/projects/{{project}}/regions/{{region}}/vpnTunnels/{{name}}/setLabels") + url, err := replaceVars(d, config, "https://www.googleapis.com/compute/beta/projects/{{project}}/regions/{{region}}/vpnTunnels/{{name}}/setLabels") if err != nil { return err } - res, err = sendRequest(config, "POST", url, obj) + res, err := sendRequest(config, "POST", url, obj) if err != nil { return fmt.Errorf("Error updating VpnTunnel %q: %s", d.Id(), err) } + project, err := getProject(d, config) + if err != nil { + return err + } + op := &compute.Operation{} err = Convert(res, op) if err != nil { return err @@ -492,22 +487,22 @@ func resourceComputeVpnTunnelUpdate(d *schema.ResourceData, meta interface{}) er func resourceComputeVpnTunnelDelete(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - url, err := replaceVars(d, config, "https://www.googleapis.com/compute/beta/projects/{{project}}/regions/{{region}}/vpnTunnels/{{name}}") if err != nil { return err } + var obj map[string]interface{} log.Printf("[DEBUG] Deleting VpnTunnel %q", d.Id()) - res, err := sendRequest(config, "DELETE", url, nil) + res, err := sendRequest(config, "DELETE", url, obj) if err != nil { return handleNotFoundError(err, d, "VpnTunnel") } + project, err := getProject(d, config) + if err != nil { + return err + } op := &compute.Operation{} err = Convert(res, op) if err != nil { diff --git a/google/resource_containeranalysis_note.go b/google/resource_containeranalysis_note.go new file mode 100644 index 00000000000..cf9f39ab38a --- /dev/null +++ b/google/resource_containeranalysis_note.go @@ -0,0 +1,292 @@ +// ---------------------------------------------------------------------------- +// +// *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +// +// ---------------------------------------------------------------------------- +// +// This file is automatically generated by Magic Modules and manual +// changes will be clobbered when the file is regenerated. +// +// Please read more about how to change this file in +// .github/CONTRIBUTING.md. +// +// ---------------------------------------------------------------------------- + +package google + +import ( + "fmt" + "log" + "reflect" + "strings" + + "github.com/hashicorp/terraform/helper/schema" +) + +func resourceContaineranalysisNote() *schema.Resource { + return &schema.Resource{ + Create: resourceContaineranalysisNoteCreate, + Read: resourceContaineranalysisNoteRead, + Update: resourceContaineranalysisNoteUpdate, + Delete: resourceContaineranalysisNoteDelete, + + Importer: &schema.ResourceImporter{ + State: resourceContaineranalysisNoteImport, + }, + + Schema: map[string]*schema.Schema{ + "attestation_authority": { + Type: schema.TypeList, + Required: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "hint": { + Type: schema.TypeList, + Required: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "human_readable_name": { + Type: schema.TypeString, + Required: true, + }, + }, + }, + }, + }, + }, + }, + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "project": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, + }, + } +} + +func resourceContaineranalysisNoteCreate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + obj := make(map[string]interface{}) + nameProp, err := expandContaineranalysisNoteName(d.Get("name"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("name"); !isEmptyValue(reflect.ValueOf(nameProp)) && (ok || !reflect.DeepEqual(v, nameProp)) { + obj["name"] = nameProp + } + attestationAuthorityProp, err := expandContaineranalysisNoteAttestationAuthority(d.Get("attestation_authority"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("attestation_authority"); !isEmptyValue(reflect.ValueOf(attestationAuthorityProp)) && (ok || !reflect.DeepEqual(v, attestationAuthorityProp)) { + obj["attestationAuthority"] = attestationAuthorityProp + } + + url, err := replaceVars(d, config, "https://containeranalysis.googleapis.com/v1alpha1/projects/{{project}}/notes?noteId={{name}}") + if err != nil { + return err + } + + log.Printf("[DEBUG] Creating new Note: %#v", obj) + res, err := sendRequest(config, "POST", url, obj) + if err != nil { + return fmt.Errorf("Error creating Note: %s", err) + } + + // Store the ID now + id, err := replaceVars(d, config, "{{name}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + log.Printf("[DEBUG] Finished creating Note %q: %#v", d.Id(), res) + + return resourceContaineranalysisNoteRead(d, meta) +} + +func resourceContaineranalysisNoteRead(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + project, err := getProject(d, config) + if err != nil { + return err + } + + url, err := replaceVars(d, config, "https://containeranalysis.googleapis.com/v1alpha1/projects/{{project}}/notes/{{name}}") + if err != nil { + return err + } + + res, err := sendRequest(config, "GET", url, nil) + if err != nil { + return handleNotFoundError(err, d, fmt.Sprintf("ContaineranalysisNote %q", d.Id())) + } + + if err := d.Set("name", flattenContaineranalysisNoteName(res["name"])); err != nil { + return fmt.Errorf("Error reading Note: %s", err) + } + if err := d.Set("attestation_authority", flattenContaineranalysisNoteAttestationAuthority(res["attestationAuthority"])); err != nil { + return fmt.Errorf("Error reading Note: %s", err) + } + if err := d.Set("project", project); err != nil { + return fmt.Errorf("Error reading Note: %s", err) + } + + return nil +} + +func resourceContaineranalysisNoteUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + obj := make(map[string]interface{}) + nameProp, err := expandContaineranalysisNoteName(d.Get("name"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("name"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, nameProp)) { + obj["name"] = nameProp + } + attestationAuthorityProp, err := expandContaineranalysisNoteAttestationAuthority(d.Get("attestation_authority"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("attestation_authority"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, attestationAuthorityProp)) { + obj["attestationAuthority"] = attestationAuthorityProp + } + + url, err := replaceVars(d, config, "https://containeranalysis.googleapis.com/v1alpha1/projects/{{project}}/notes/{{name}}") + if err != nil { + return err + } + + log.Printf("[DEBUG] Updating Note %q: %#v", d.Id(), obj) + updateMask := []string{} + if d.HasChange("attestation_authority.0.hint.0.human_readable_name") { + updateMask = append(updateMask, "attestationAuthority.hint.humanReadableName") + } + // updateMask is a URL parameter but not present in the schema, so replaceVars + // won't set it + url, err = addQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")}) + if err != nil { + return err + } + _, err = sendRequest(config, "PATCH", url, obj) + + if err != nil { + return fmt.Errorf("Error updating Note %q: %s", d.Id(), err) + } + + return resourceContaineranalysisNoteRead(d, meta) +} + +func resourceContaineranalysisNoteDelete(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + url, err := replaceVars(d, config, "https://containeranalysis.googleapis.com/v1alpha1/projects/{{project}}/notes/{{name}}") + if err != nil { + return err + } + + var obj map[string]interface{} + log.Printf("[DEBUG] Deleting Note %q", d.Id()) + res, err := sendRequest(config, "DELETE", url, obj) + if err != nil { + return handleNotFoundError(err, d, "Note") + } + + log.Printf("[DEBUG] Finished deleting Note %q: %#v", d.Id(), res) + return nil +} + +func resourceContaineranalysisNoteImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + config := meta.(*Config) + parseImportId([]string{"projects/(?P[^/]+)/notes/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)"}, d, config) + + // Replace import id for the resource id + id, err := replaceVars(d, config, "{{name}}") + if err != nil { + return nil, fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + return []*schema.ResourceData{d}, nil +} + +func flattenContaineranalysisNoteName(v interface{}) interface{} { + if v == nil { + return v + } + return NameFromSelfLinkStateFunc(v) +} + +func flattenContaineranalysisNoteAttestationAuthority(v interface{}) interface{} { + if v == nil { + return nil + } + original := v.(map[string]interface{}) + transformed := make(map[string]interface{}) + transformed["hint"] = + flattenContaineranalysisNoteAttestationAuthorityHint(original["hint"]) + return []interface{}{transformed} +} +func flattenContaineranalysisNoteAttestationAuthorityHint(v interface{}) interface{} { + if v == nil { + return nil + } + original := v.(map[string]interface{}) + transformed := make(map[string]interface{}) + transformed["human_readable_name"] = + flattenContaineranalysisNoteAttestationAuthorityHintHumanReadableName(original["humanReadableName"]) + return []interface{}{transformed} +} +func flattenContaineranalysisNoteAttestationAuthorityHintHumanReadableName(v interface{}) interface{} { + return v +} + +func expandContaineranalysisNoteName(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandContaineranalysisNoteAttestationAuthority(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + l := v.([]interface{}) + if len(l) == 0 { + return nil, nil + } + raw := l[0] + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedHint, err := expandContaineranalysisNoteAttestationAuthorityHint(original["hint"], d, config) + if err != nil { + return nil, err + } + transformed["hint"] = transformedHint + return transformed, nil +} + +func expandContaineranalysisNoteAttestationAuthorityHint(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + l := v.([]interface{}) + if len(l) == 0 { + return nil, nil + } + raw := l[0] + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedHumanReadableName, err := expandContaineranalysisNoteAttestationAuthorityHintHumanReadableName(original["human_readable_name"], d, config) + if err != nil { + return nil, err + } + transformed["humanReadableName"] = transformedHumanReadableName + return transformed, nil +} + +func expandContaineranalysisNoteAttestationAuthorityHintHumanReadableName(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} diff --git a/google/resource_containeranalysis_note_test.go b/google/resource_containeranalysis_note_test.go new file mode 100644 index 00000000000..9be3277d861 --- /dev/null +++ b/google/resource_containeranalysis_note_test.go @@ -0,0 +1,102 @@ +package google + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" +) + +func TestAccContainerAnalysisNote_basic(t *testing.T) { + t.Parallel() + + name := acctest.RandString(10) + readableName := acctest.RandString(10) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckContainerAnalysisNoteDestroy, + Steps: []resource.TestStep{ + { + Config: testAccContainerAnalysisNoteBasic(name, readableName), + }, + { + ResourceName: "google_containeranalysis_note.note", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccContainerAnalysisNote_update(t *testing.T) { + t.Parallel() + + name := acctest.RandString(10) + readableName := acctest.RandString(10) + readableName2 := acctest.RandString(10) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckContainerAnalysisNoteDestroy, + Steps: []resource.TestStep{ + { + Config: testAccContainerAnalysisNoteBasic(name, readableName), + }, + { + ResourceName: "google_containeranalysis_note.note", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccContainerAnalysisNoteBasic(name, readableName2), + }, + { + ResourceName: "google_containeranalysis_note.note", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccCheckContainerAnalysisNoteDestroy(s *terraform.State) error { + config := testAccProvider.Meta().(*Config) + + for _, rs := range s.RootModule().Resources { + if rs.Type != "google_containeranalysis_note" { + continue + } + + project, err := getTestProject(rs.Primary, config) + if err != nil { + return err + } + + name := rs.Primary.Attributes["name"] + + url := fmt.Sprintf("https://containeranalysis.googleapis.com/v1alpha1/projects/%s/notes/%s", project, name) + _, err = sendRequest(config, "GET", url, nil) + + if err == nil { + return fmt.Errorf("Error, container analysis note %s still exists", name) + } + } + + return nil +} + +func testAccContainerAnalysisNoteBasic(name, readableName string) string { + return fmt.Sprintf(` +resource "google_containeranalysis_note" "note" { + name = "tf-test-%s" + attestation_authority { + hint { + human_readable_name = "My Attestor %s" + } + } +} +`, name, readableName) +} diff --git a/google/resource_redis_instance.go b/google/resource_redis_instance.go index 91360f3f459..88cfb6ef802 100644 --- a/google/resource_redis_instance.go +++ b/google/resource_redis_instance.go @@ -141,11 +141,6 @@ func resourceRedisInstance() *schema.Resource { func resourceRedisInstanceCreate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - obj := make(map[string]interface{}) alternativeLocationIdProp, err := expandRedisInstanceAlternativeLocationId(d.Get("alternative_location_id"), d, config) if err != nil { @@ -243,6 +238,10 @@ func resourceRedisInstanceCreate(d *schema.ResourceData, meta interface{}) error } d.SetId(id) + project, err := getProject(d, config) + if err != nil { + return err + } op := &redis.Operation{} err = Convert(res, op) if err != nil { @@ -345,11 +344,6 @@ func resourceRedisInstanceRead(d *schema.ResourceData, meta interface{}) error { func resourceRedisInstanceUpdate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - obj := make(map[string]interface{}) alternativeLocationIdProp, err := expandRedisInstanceAlternativeLocationId(d.Get("alternative_location_id"), d, config) if err != nil { @@ -457,6 +451,10 @@ func resourceRedisInstanceUpdate(d *schema.ResourceData, meta interface{}) error return fmt.Errorf("Error updating Instance %q: %s", d.Id(), err) } + project, err := getProject(d, config) + if err != nil { + return err + } op := &redis.Operation{} err = Convert(res, op) if err != nil { @@ -477,22 +475,22 @@ func resourceRedisInstanceUpdate(d *schema.ResourceData, meta interface{}) error func resourceRedisInstanceDelete(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - project, err := getProject(d, config) - if err != nil { - return err - } - url, err := replaceVars(d, config, "https://redis.googleapis.com/v1beta1/projects/{{project}}/locations/{{region}}/instances/{{name}}") if err != nil { return err } + var obj map[string]interface{} log.Printf("[DEBUG] Deleting Instance %q", d.Id()) - res, err := sendRequest(config, "DELETE", url, nil) + res, err := sendRequest(config, "DELETE", url, obj) if err != nil { return handleNotFoundError(err, d, "Instance") } + project, err := getProject(d, config) + if err != nil { + return err + } op := &redis.Operation{} err = Convert(res, op) if err != nil { diff --git a/google/resource_resourcemanager_lien.go b/google/resource_resourcemanager_lien.go index 07048009d18..1323f169513 100644 --- a/google/resource_resourcemanager_lien.go +++ b/google/resource_resourcemanager_lien.go @@ -207,12 +207,13 @@ func resourceResourceManagerLienDelete(d *schema.ResourceData, meta interface{}) return err } + var obj map[string]interface{} url, err = replaceVars(d, config, "https://cloudresourcemanager.googleapis.com/v1/liens/{{name}}") if err != nil { return err } log.Printf("[DEBUG] Deleting Lien %q", d.Id()) - res, err := sendRequest(config, "DELETE", url, nil) + res, err := sendRequest(config, "DELETE", url, obj) if err != nil { return handleNotFoundError(err, d, "Lien") } diff --git a/website/docs/r/binaryauthorization_attestor.html.markdown b/website/docs/r/binaryauthorization_attestor.html.markdown new file mode 100644 index 00000000000..8b40f27b9fc --- /dev/null +++ b/website/docs/r/binaryauthorization_attestor.html.markdown @@ -0,0 +1,158 @@ +--- +# ---------------------------------------------------------------------------- +# +# *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +# +# ---------------------------------------------------------------------------- +# +# This file is automatically generated by Magic Modules and manual +# changes will be clobbered when the file is regenerated. +# +# Please read more about how to change this file in +# .github/CONTRIBUTING.md. +# +# ---------------------------------------------------------------------------- +layout: "google" +page_title: "Google: google_binaryauthorization_attestor" +sidebar_current: "docs-google-binaryauthorization-attestor" +description: |- + An attestor that attests to container image artifacts. +--- + +# google\_binaryauthorization\_attestor + +An attestor that attests to container image artifacts. + +To get more information about Attestor, see: + +* [API documentation](https://cloud.google.com/binary-authorization/docs/reference/rest/) +* How-to Guides + * [Official Documentation](https://cloud.google.com/binary-authorization/) + +## Example Usage + +```hcl +resource "google_containeranalysis_note" "note" { + name = "test-attestor-note" + attestation_authority { + hint { + human_readable_name = "Attestor Note" + } + } +} + +resource "google_binaryauthorization_attestor" "attestor" { + name = "test-attestor" + attestation_authority_note { + note_reference = "${google_containeranalysis_note.note.name}" + public_keys { + ascii_armored_pgp_public_key = <