Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions mmv1/third_party/terraform/envvar/envvar_utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package envvar

import (
"fmt"
"log"
"os"
"testing"
Expand Down Expand Up @@ -196,3 +197,7 @@ func SkipIfEnvNotSet(t *testing.T, envs ...string) {
}
}
}

func ServiceAccountCanonicalEmail(account string) string {
return fmt.Sprintf("%s@%s.iam.gserviceaccount.com", account, GetTestProjectFromEnv())
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
<% autogen_exception -%>
package google
package fwprovider_test

import (
"fmt"
"regexp"
"strings"
"testing"

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

"github.com/hashicorp/terraform-provider-google/google/acctest"
"github.com/hashicorp/terraform-provider-google/google/fwtransport"
"github.com/hashicorp/terraform-provider-google/google/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
)

func TestAccFrameworkProviderMeta_setModuleName(t *testing.T) {
Expand Down Expand Up @@ -170,3 +176,111 @@ resource "google_dns_managed_zone" "foo" {
}
`, endpoint, name, name)
}


// Copy the function from the provider_test package to here
// as that function is in the _test.go file and not importable
func testAccProviderBasePath_setBasePath(endpoint, name string) string {
return fmt.Sprintf(`
provider "google" {
alias = "compute_custom_endpoint"
compute_custom_endpoint = "%s"
}

resource "google_compute_address" "default" {
provider = google.compute_custom_endpoint
name = "tf-test-address-%s"
}`, endpoint, name)
}

func testAccProviderMeta_setModuleName(key, name string) string {
return fmt.Sprintf(`
terraform {
provider_meta "google" {
module_name = "%s"
}
}

resource "google_compute_address" "default" {
name = "tf-test-address-%s"
}`, key, name)
}

// Copy the function testAccCheckComputeAddressDestroyProducer from the dns_test package to here,
// as that function is in the _test.go file and not importable.
//
// testAccCheckDNSManagedZoneDestroyProducerFramework is the framework version of the generated testAccCheckDNSManagedZoneDestroyProducer
// when we automate this, we'll use the automated version and can get rid of this
func testAccCheckDNSManagedZoneDestroyProducerFramework(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
if rs.Type != "google_dns_managed_zone" {
continue
}
if strings.HasPrefix(name, "data.") {
continue
}

p := acctest.GetFwTestProvider(t)

url, err := acctest.ReplaceVarsForFrameworkTest(&p.FrameworkProvider.FrameworkProviderConfig, rs, "{{DNSBasePath}}projects/{{project}}/managedZones/{{name}}")
if err != nil {
return err
}

billingProject := ""

if !p.BillingProject.IsNull() && p.BillingProject.String() != "" {
billingProject = p.BillingProject.String()
}

_, diags := fwtransport.SendFrameworkRequest(&p.FrameworkProvider.FrameworkProviderConfig, "GET", billingProject, url, p.UserAgent, nil)
if !diags.HasError() {
return fmt.Errorf("DNSManagedZone still exists at %s", url)
}
}

return nil
}
}

// Copy the Mmv1 generated function testAccCheckComputeAddressDestroyProducer from the compute_test package to here,
// as that function is in the _test.go file and not importable.
func testAccCheckComputeAddressDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
if rs.Type != "google_compute_address" {
continue
}
if strings.HasPrefix(name, "data.") {
continue
}

config := acctest.GoogleProviderConfig(t)

url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{ComputeBasePath}}projects/{{project}}/regions/{{region}}/addresses/{{name}}")
if err != nil {
return err
}

billingProject := ""

if config.BillingProject != "" {
billingProject = config.BillingProject
}

_, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Config: config,
Method: "GET",
Project: billingProject,
RawURL: url,
UserAgent: config.UserAgent,
})
if err == nil {
return fmt.Errorf("ComputeAddress still exists at %s", url)
}
}

return nil
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
<% autogen_exception -%>
package google
package provider_test

import (
"fmt"
"regexp"
"strings"
"testing"

"github.com/hashicorp/terraform-provider-google/google/acctest"
"github.com/hashicorp/terraform-provider-google/google/envvar"
"github.com/hashicorp/terraform-provider-google/google/provider"
"github.com/hashicorp/terraform-provider-google/google/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"

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

func TestProvider(t *testing.T) {
Expand Down Expand Up @@ -148,7 +152,7 @@ func TestAccProviderIndirectUserProjectOverride(t *testing.T) {
pid := "tf-test-" + acctest.RandString(t, 10)

config := acctest.BootstrapConfig(t)
accessToken, err := setupProjectsAndGetAccessToken(org, billing, pid, "cloudkms", config)
accessToken, err := acctest.SetupProjectsAndGetAccessToken(org, billing, pid, "cloudkms", config)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -276,4 +280,45 @@ provider "google" {
user_project_override = %v
}
`, accessToken, override)
}

// Copy the Mmv1 generated function testAccCheckComputeAddressDestroyProducer from the compute_test package to here,
// as that function is in the _test.go file and not importable.
func testAccCheckComputeAddressDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
if rs.Type != "google_compute_address" {
continue
}
if strings.HasPrefix(name, "data.") {
continue
}

config := acctest.GoogleProviderConfig(t)

url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{ComputeBasePath}}projects/{{project}}/regions/{{region}}/addresses/{{name}}")
if err != nil {
return err
}

billingProject := ""

if config.BillingProject != "" {
billingProject = config.BillingProject
}

_, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Config: config,
Method: "GET",
Project: billingProject,
RawURL: url,
UserAgent: config.UserAgent,
})
if err == nil {
return fmt.Errorf("ComputeAddress still exists at %s", url)
}
}

return nil
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package accessapproval_test

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package accessapproval_test

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package accessapproval_test

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package accessapproval_test

import (
"log"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package accessapproval_test

import (
"log"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package accessapproval_test

import (
"log"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package activedirectory_test

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package activedirectory_test

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package alloydb_test

import (
"errors"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package apigee_test

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package apigee_test

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package appengine_test

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package appengine_test

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package bigquery_test

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package bigquery_test

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package bigquery_test

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package bigquery_test

import (
"fmt"
Expand Down Expand Up @@ -62,7 +62,7 @@ func TestAccBigqueryDatasetIamMember(t *testing.T) {
envvar.GetTestProjectFromEnv(),
dataset,
role,
serviceAccountCanonicalEmail(account))
envvar.ServiceAccountCanonicalEmail(account))

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
Expand All @@ -75,7 +75,7 @@ func TestAccBigqueryDatasetIamMember(t *testing.T) {
resource.TestCheckResourceAttr(
"google_bigquery_dataset_iam_member.member", "role", role),
resource.TestCheckResourceAttr(
"google_bigquery_dataset_iam_member.member", "member", "serviceAccount:"+serviceAccountCanonicalEmail(account)),
"google_bigquery_dataset_iam_member.member", "member", "serviceAccount:"+envvar.ServiceAccountCanonicalEmail(account)),
),
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package bigquery_test

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package bigquerydatatransfer_test

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package bigtable_test

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package bigtable_test

import (
"fmt"
Expand Down Expand Up @@ -68,7 +68,7 @@ func TestAccBigtableInstanceIamMember(t *testing.T) {
envvar.GetTestProjectFromEnv(),
instance,
role,
serviceAccountCanonicalEmail(account))
envvar.ServiceAccountCanonicalEmail(account))

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
Expand All @@ -81,7 +81,7 @@ func TestAccBigtableInstanceIamMember(t *testing.T) {
resource.TestCheckResourceAttr(
"google_bigtable_instance_iam_member.member", "role", role),
resource.TestCheckResourceAttr(
"google_bigtable_instance_iam_member.member", "member", "serviceAccount:"+serviceAccountCanonicalEmail(account)),
"google_bigtable_instance_iam_member.member", "member", "serviceAccount:"+envvar.ServiceAccountCanonicalEmail(account)),
),
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package google
package bigtable_test

import (
"context"
Expand Down
Loading