-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1382 from cheftako/tpc
Backport Add provider attribute universe_domain
- Loading branch information
Showing
13 changed files
with
394 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
...raform-provider-google-beta/google-beta/provider/universe/universe_domain_compute_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package universe_test | ||
|
||
import ( | ||
"fmt" | ||
"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/envvar" | ||
"github.com/hashicorp/terraform-provider-google/google/tpgresource" | ||
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport" | ||
) | ||
|
||
func TestAccUniverseDomainDisk(t *testing.T) { | ||
// Skip this test in all env since this can only run in specific test project. | ||
t.Skip() | ||
|
||
universeDomain := envvar.GetTestUniverseDomainFromEnv(t) | ||
|
||
acctest.VcrTest(t, resource.TestCase{ | ||
PreCheck: func() { acctest.AccTestPreCheck(t) }, | ||
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), | ||
CheckDestroy: testAccCheckComputeDiskDestroyProducer(t), | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccUniverseDomain_basic_disk(universeDomain), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccDefaultUniverseDomainDisk(t *testing.T) { | ||
universeDomain := "googleapis.com" | ||
|
||
acctest.VcrTest(t, resource.TestCase{ | ||
PreCheck: func() { acctest.AccTestPreCheck(t) }, | ||
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), | ||
CheckDestroy: testAccCheckComputeDiskDestroyProducer(t), | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccUniverseDomain_basic_disk(universeDomain), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccUniverseDomain_basic_disk(universeDomain string) string { | ||
return fmt.Sprintf(` | ||
provider "google" { | ||
universe_domain = "%s" | ||
} | ||
resource "google_compute_instance_template" "instance_template" { | ||
name = "demo-this" | ||
machine_type = "n1-standard-1" | ||
// boot disk | ||
disk { | ||
disk_size_gb = 20 | ||
} | ||
network_interface { | ||
network = "default" | ||
} | ||
} | ||
`, universeDomain) | ||
} | ||
|
||
func testAccCheckComputeDiskDestroyProducer(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_disk" { | ||
continue | ||
} | ||
if strings.HasPrefix(name, "data.") { | ||
continue | ||
} | ||
|
||
config := acctest.GoogleProviderConfig(t) | ||
|
||
url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{ComputeBasePath}}projects/{{project}}/zones/{{zone}}/disks/{{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("ComputeDisk still exists at %s", url) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
...rraform-provider-google-beta/google-beta/provider/universe/universe_domain_pubsub_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package universe_test | ||
|
||
import ( | ||
"fmt" | ||
"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/envvar" | ||
"github.com/hashicorp/terraform-provider-google/google/tpgresource" | ||
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport" | ||
) | ||
|
||
func TestAccUniverseDomainPubSub(t *testing.T) { | ||
// Skip this test in all env since this can only run in specific test project. | ||
t.Skip() | ||
|
||
universeDomain := envvar.GetTestUniverseDomainFromEnv(t) | ||
topic := fmt.Sprintf("tf-test-topic-%s", acctest.RandString(t, 10)) | ||
subscription := fmt.Sprintf("tf-test-sub-%s", acctest.RandString(t, 10)) | ||
|
||
acctest.VcrTest(t, resource.TestCase{ | ||
PreCheck: func() { acctest.AccTestPreCheck(t) }, | ||
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), | ||
CheckDestroy: testAccCheckPubsubSubscriptionDestroyProducer(t), | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccUniverseDomain_basic_pubsub(universeDomain, topic, subscription), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccUniverseDomain_basic_pubsub(universeDomain, topic, subscription string) string { | ||
return fmt.Sprintf(` | ||
provider "google" { | ||
universe_domain = "%s" | ||
} | ||
resource "google_pubsub_topic" "foo" { | ||
name = "%s" | ||
} | ||
resource "google_pubsub_subscription" "foo" { | ||
name = "%s" | ||
topic = google_pubsub_topic.foo.id | ||
message_retention_duration = "1200s" | ||
retain_acked_messages = true | ||
ack_deadline_seconds = 20 | ||
expiration_policy { | ||
ttl = "" | ||
} | ||
enable_message_ordering = false | ||
} | ||
`, universeDomain, topic, subscription) | ||
} | ||
|
||
func testAccCheckPubsubSubscriptionDestroyProducer(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_pubsub_subscription" { | ||
continue | ||
} | ||
if strings.HasPrefix(name, "data.") { | ||
continue | ||
} | ||
|
||
config := acctest.GoogleProviderConfig(t) | ||
|
||
url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{PubsubBasePath}}projects/{{project}}/subscriptions/{{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("PubsubSubscription still exists at %s", url) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
} |
Oops, something went wrong.