-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add provider attribute universe_domain (#8657)
* Add provider attribute universe_domain * Replace universe domain field with env vars, added more tests for storage and pubsub * Extract universe domain from SA key file * Include JWT scoped flow for authentication * Add JWT Scoped flow in default application credentials * Add test for GDU, enhance logging * Resolve build issue * Create package for tests, resolve review discussions * Modify logic to copy test files to down-streams * Change test package name from universe_test to universe * Update indentation on framework_config.go.erb * Update indentation on framework_config.go.erb * Update credential logging message Co-authored-by: Riley Karson <[email protected]> * Remove universe_domain replacement in utils.go for long URL replacement * Update error message for conflicted universe_domain definition * Add basic description for universe_domain. * Modify error message when universe domain mismatches --------- Co-authored-by: Riley Karson <[email protected]>
- Loading branch information
1 parent
180e0a9
commit 340c76d
Showing
15 changed files
with
402 additions
and
11 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
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
109 changes: 109 additions & 0 deletions
109
mmv1/third_party/terraform/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,109 @@ | ||
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
mmv1/third_party/terraform/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.