Skip to content

Commit

Permalink
Versioned OiCS Examples / Generated tests (#486)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored and rileykarson committed Mar 4, 2019
1 parent b134997 commit c34fa6d
Show file tree
Hide file tree
Showing 14 changed files with 508 additions and 58 deletions.
9 changes: 9 additions & 0 deletions google-beta/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
)

var testAccProviders map[string]terraform.ResourceProvider
var testAccProvidersOiCS map[string]terraform.ResourceProvider
var testAccProvider *schema.Provider
var testAccRandomProvider *schema.Provider

Expand Down Expand Up @@ -64,6 +65,14 @@ func init() {
"google": testAccProvider,
"random": testAccRandomProvider,
}

// The OiCS provider map is used to ensure that OiCS examples use `google-beta`
// if the example is versioned as beta; normal beta tests should continue to
// use the standard provider map.
testAccProvidersOiCS = map[string]terraform.ResourceProvider{
"google-beta": testAccProvider,
"random": testAccRandomProvider,
}
}

func TestProvider(t *testing.T) {
Expand Down
47 changes: 26 additions & 21 deletions google-beta/resource_cloud_scheduler_job_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,27 @@ func TestAccCloudSchedulerJob_schedulerJobPubsubExample(t *testing.T) {

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Providers: testAccProvidersOiCS,
CheckDestroy: testAccCheckCloudSchedulerJobDestroy,
Steps: []resource.TestStep{
{
Config: testAccCloudSchedulerJob_schedulerJobPubsubExample(context),
},
{
ResourceName: "google_cloud_scheduler_job.job",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"region"},
},
},
})
}

func testAccCloudSchedulerJob_schedulerJobPubsubExample(context map[string]interface{}) string {
return Nprintf(`
resource "google_pubsub_topic" "topic" {
provider = "google-beta"
name = "job-topic-%{random_suffix}"
}
resource "google_cloud_scheduler_job" "job" {
provider = "google-beta"
name = "test-job-%{random_suffix}"
description = "test job"
schedule = "*/2 * * * *"
Expand All @@ -65,6 +63,11 @@ resource "google_cloud_scheduler_job" "job" {
data = "${base64encode("test")}"
}
}
provider "google-beta"{
region = "us-central1"
zone = "us-central1-a"
}
`, context)
}

Expand All @@ -77,25 +80,21 @@ func TestAccCloudSchedulerJob_schedulerJobHttpExample(t *testing.T) {

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Providers: testAccProvidersOiCS,
CheckDestroy: testAccCheckCloudSchedulerJobDestroy,
Steps: []resource.TestStep{
{
Config: testAccCloudSchedulerJob_schedulerJobHttpExample(context),
},
{
ResourceName: "google_cloud_scheduler_job.job",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"region"},
},
},
})
}

func testAccCloudSchedulerJob_schedulerJobHttpExample(context map[string]interface{}) string {
return Nprintf(`
resource "google_cloud_scheduler_job" "job" {
provider = "google-beta"
name = "test-job-%{random_suffix}"
description = "test http job"
schedule = "*/8 * * * *"
Expand All @@ -106,6 +105,11 @@ resource "google_cloud_scheduler_job" "job" {
uri = "https://example.com/ping"
}
}
provider "google-beta"{
region = "us-central1"
zone = "us-central1-a"
}
`, context)
}

Expand All @@ -118,25 +122,21 @@ func TestAccCloudSchedulerJob_schedulerJobAppEngineExample(t *testing.T) {

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Providers: testAccProvidersOiCS,
CheckDestroy: testAccCheckCloudSchedulerJobDestroy,
Steps: []resource.TestStep{
{
Config: testAccCloudSchedulerJob_schedulerJobAppEngineExample(context),
},
{
ResourceName: "google_cloud_scheduler_job.job",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"region"},
},
},
})
}

func testAccCloudSchedulerJob_schedulerJobAppEngineExample(context map[string]interface{}) string {
return Nprintf(`
resource "google_cloud_scheduler_job" "job" {
provider = "google-beta"
name = "test-job-%{random_suffix}"
schedule = "*/4 * * * *"
description = "test app engine job"
Expand All @@ -154,6 +154,11 @@ resource "google_cloud_scheduler_job" "job" {
relative_uri = "/ping"
}
}
provider "google-beta"{
region = "us-central1"
zone = "us-central1-a"
}
`, context)
}

Expand Down
106 changes: 102 additions & 4 deletions google-beta/resource_compute_autoscaler_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,106 @@ import (
"github.com/hashicorp/terraform/terraform"
)

func TestAccComputeAutoscaler_autoscalerBetaExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": acctest.RandString(10),
}

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProvidersOiCS,
CheckDestroy: testAccCheckComputeAutoscalerDestroy,
Steps: []resource.TestStep{
{
Config: testAccComputeAutoscaler_autoscalerBetaExample(context),
},
},
})
}

func testAccComputeAutoscaler_autoscalerBetaExample(context map[string]interface{}) string {
return Nprintf(`
resource "google_compute_autoscaler" "foobar" {
provider = "google-beta"
name = "my-autoscaler-%{random_suffix}"
zone = "us-central1-f"
target = "${google_compute_instance_group_manager.foobar.self_link}"
autoscaling_policy {
max_replicas = 5
min_replicas = 1
cooldown_period = 60
cpu_utilization {
target = 0.5
}
}
}
resource "google_compute_instance_template" "foobar" {
provider = "google-beta"
name = "my-instance-template-%{random_suffix}"
machine_type = "n1-standard-1"
can_ip_forward = false
tags = ["foo", "bar"]
disk {
source_image = "${data.google_compute_image.debian_9.self_link}"
}
network_interface {
network = "default"
}
metadata = {
foo = "bar"
}
service_account {
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
}
}
resource "google_compute_target_pool" "foobar" {
provider = "google-beta"
name = "my-target-pool-%{random_suffix}"
}
resource "google_compute_instance_group_manager" "foobar" {
provider = "google-beta"
name = "my-igm-%{random_suffix}"
zone = "us-central1-f"
version {
instance_template = "${google_compute_instance_template.foobar.self_link}"
name = "primary"
}
target_pools = ["${google_compute_target_pool.foobar.self_link}"]
base_instance_name = "foobar"
}
data "google_compute_image" "debian_9" {
provider = "google-beta"
family = "debian-9"
project = "debian-cloud"
}
provider "google-beta"{
region = "us-central1"
zone = "us-central1-a"
}
`, context)
}

func TestAccComputeAutoscaler_autoscalerBasicExample(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -98,10 +198,8 @@ resource "google_compute_instance_group_manager" "foobar" {
name = "my-igm-%{random_suffix}"
zone = "us-central1-f"
version {
instance_template = "${google_compute_instance_template.foobar.self_link}"
name = "primary"
}
instance_template = "${google_compute_instance_template.foobar.self_link}"
target_pools = ["${google_compute_target_pool.foobar.self_link}"]
base_instance_name = "foobar"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,21 @@ func TestAccComputeManagedSslCertificate_managedSslCertificateBasicExample(t *te

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Providers: testAccProvidersOiCS,
CheckDestroy: testAccCheckComputeManagedSslCertificateDestroy,
Steps: []resource.TestStep{
{
Config: testAccComputeManagedSslCertificate_managedSslCertificateBasicExample(context),
},
{
ResourceName: "google_compute_managed_ssl_certificate.default",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccComputeManagedSslCertificate_managedSslCertificateBasicExample(context map[string]interface{}) string {
return Nprintf(`
resource "google_compute_managed_ssl_certificate" "default" {
provider = "google-beta"
name = "test-cert-%{random_suffix}"
managed {
Expand All @@ -59,12 +56,16 @@ resource "google_compute_managed_ssl_certificate" "default" {
}
resource "google_compute_target_https_proxy" "default" {
provider = "google-beta"
name = "test-proxy-%{random_suffix}"
url_map = "${google_compute_url_map.default.self_link}"
ssl_certificates = ["${google_compute_managed_ssl_certificate.default.self_link}"]
}
resource "google_compute_url_map" "default" {
provider = "google-beta"
name = "url-map-%{random_suffix}"
description = "a description"
Expand All @@ -87,6 +88,8 @@ resource "google_compute_url_map" "default" {
}
resource "google_compute_backend_service" "default" {
provider = "google-beta"
name = "backend-service-%{random_suffix}"
port_name = "http"
protocol = "HTTP"
Expand All @@ -96,30 +99,43 @@ resource "google_compute_backend_service" "default" {
}
resource "google_compute_http_health_check" "default" {
provider = "google-beta"
name = "http-health-check-%{random_suffix}"
request_path = "/"
check_interval_sec = 1
timeout_sec = 1
}
resource "google_dns_managed_zone" "zone" {
provider = "google-beta"
name = "dnszone-%{random_suffix}"
dns_name = "sslcert.tf-test.club."
}
resource "google_compute_global_forwarding_rule" "default" {
provider = "google-beta"
name = "forwarding-rule-%{random_suffix}"
target = "${google_compute_target_https_proxy.default.self_link}"
port_range = 443
}
resource "google_dns_record_set" "set" {
provider = "google-beta"
name = "sslcert.tf-test.club."
type = "A"
ttl = 3600
managed_zone = "${google_dns_managed_zone.zone.name}"
rrdatas = ["${google_compute_global_forwarding_rule.default.ip_address}"]
}
provider "google-beta"{
region = "us-central1"
zone = "us-central1-a"
}
`, context)
}

Expand Down
Loading

0 comments on commit c34fa6d

Please sign in to comment.