blob: df66c1b84b01232c50314104308e105ead6db6a1 [file] [log] [blame]
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** Type: MMv1 ***
//
// ----------------------------------------------------------------------------
//
// 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 clouddeploy_test
import (
"fmt"
"strings"
"testing"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/envvar"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
)
func TestAccClouddeployAutomation_clouddeployAutomationBasicExample(t *testing.T) {
t.Parallel()
context := map[string]interface{}{
"service_account": envvar.GetTestServiceAccountFromEnv(t),
"random_suffix": acctest.RandString(t, 10),
}
acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckClouddeployAutomationDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccClouddeployAutomation_clouddeployAutomationBasicExample(context),
},
{
ResourceName: "google_clouddeploy_automation.b-automation",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"annotations", "delivery_pipeline", "labels", "location", "name", "terraform_labels"},
},
},
})
}
func testAccClouddeployAutomation_clouddeployAutomationBasicExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_clouddeploy_automation" "b-automation" {
name = "tf-test-cd-automation%{random_suffix}"
project = google_clouddeploy_delivery_pipeline.pipeline.project
location = google_clouddeploy_delivery_pipeline.pipeline.location
delivery_pipeline = google_clouddeploy_delivery_pipeline.pipeline.name
service_account = "%{service_account}"
selector {
targets {
id = "*"
}
}
suspended = false
rules {
promote_release_rule {
id = "promote-release"
}
}
}
resource "google_clouddeploy_delivery_pipeline" "pipeline" {
name = "tf-test-cd-pipeline%{random_suffix}"
location = "us-central1"
serial_pipeline {
stages {
target_id = "test"
profiles = []
}
}
}
`, context)
}
func TestAccClouddeployAutomation_clouddeployAutomationFullExample(t *testing.T) {
t.Parallel()
context := map[string]interface{}{
"service_account": envvar.GetTestServiceAccountFromEnv(t),
"random_suffix": acctest.RandString(t, 10),
}
acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckClouddeployAutomationDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccClouddeployAutomation_clouddeployAutomationFullExample(context),
},
{
ResourceName: "google_clouddeploy_automation.f-automation",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"annotations", "delivery_pipeline", "labels", "location", "name", "terraform_labels"},
},
},
})
}
func testAccClouddeployAutomation_clouddeployAutomationFullExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_clouddeploy_automation" "f-automation" {
name = "tf-test-cd-automation%{random_suffix}"
location = "us-central1"
delivery_pipeline = google_clouddeploy_delivery_pipeline.pipeline.name
service_account = "%{service_account}"
annotations = {
my_first_annotation = "example-annotation-1"
my_second_annotation = "example-annotation-2"
}
labels = {
my_first_label = "example-label-1"
my_second_label = "example-label-2"
}
description = "automation resource"
selector {
targets {
id = "test"
labels = {
foo = "bar"
}
}
}
suspended = true
rules {
promote_release_rule{
id = "promote-release"
wait = "200s"
destination_target_id = "@next"
destination_phase = "stable"
}
}
rules {
advance_rollout_rule {
id = "advance-rollout"
source_phases = ["deploy"]
wait = "200s"
}
}
}
resource "google_clouddeploy_delivery_pipeline" "pipeline" {
name = "tf-test-cd-pipeline%{random_suffix}"
location = "us-central1"
serial_pipeline {
stages {
target_id = "test"
profiles = ["test-profile"]
}
}
}
`, context)
}
func testAccCheckClouddeployAutomationDestroyProducer(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_clouddeploy_automation" {
continue
}
if strings.HasPrefix(name, "data.") {
continue
}
config := acctest.GoogleProviderConfig(t)
url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{ClouddeployBasePath}}projects/{{project}}/locations/{{location}}/deliveryPipelines/{{delivery_pipeline}}/automations/{{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("ClouddeployAutomation still exists at %s", url)
}
}
return nil
}
}