blob: 735487dd20c37a7ed4ff84bdc8fcc52e8aa71fd9 [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 compute_test
import (
"fmt"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/envvar"
)
func TestAccComputeSnapshotIamBindingGenerated(t *testing.T) {
t.Parallel()
context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
"role": "roles/viewer",
}
acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
Steps: []resource.TestStep{
{
Config: testAccComputeSnapshotIamBinding_basicGenerated(context),
},
{
ResourceName: "google_compute_snapshot_iam_binding.foo",
ImportStateId: fmt.Sprintf("projects/%s/global/snapshots/%s roles/viewer", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-my-snapshot%s", context["random_suffix"])),
ImportState: true,
ImportStateVerify: true,
},
{
// Test Iam Binding update
Config: testAccComputeSnapshotIamBinding_updateGenerated(context),
},
{
ResourceName: "google_compute_snapshot_iam_binding.foo",
ImportStateId: fmt.Sprintf("projects/%s/global/snapshots/%s roles/viewer", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-my-snapshot%s", context["random_suffix"])),
ImportState: true,
ImportStateVerify: true,
},
},
})
}
func TestAccComputeSnapshotIamMemberGenerated(t *testing.T) {
t.Parallel()
context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
"role": "roles/viewer",
}
acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
Steps: []resource.TestStep{
{
// Test Iam Member creation (no update for member, no need to test)
Config: testAccComputeSnapshotIamMember_basicGenerated(context),
},
{
ResourceName: "google_compute_snapshot_iam_member.foo",
ImportStateId: fmt.Sprintf("projects/%s/global/snapshots/%s roles/viewer user:admin@hashicorptest.com", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-my-snapshot%s", context["random_suffix"])),
ImportState: true,
ImportStateVerify: true,
},
},
})
}
func TestAccComputeSnapshotIamPolicyGenerated(t *testing.T) {
t.Parallel()
context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
"role": "roles/viewer",
}
acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
Steps: []resource.TestStep{
{
Config: testAccComputeSnapshotIamPolicy_basicGenerated(context),
Check: resource.TestCheckResourceAttrSet("data.google_compute_snapshot_iam_policy.foo", "policy_data"),
},
{
ResourceName: "google_compute_snapshot_iam_policy.foo",
ImportStateId: fmt.Sprintf("projects/%s/global/snapshots/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-my-snapshot%s", context["random_suffix"])),
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccComputeSnapshotIamPolicy_emptyBinding(context),
},
{
ResourceName: "google_compute_snapshot_iam_policy.foo",
ImportStateId: fmt.Sprintf("projects/%s/global/snapshots/%s", envvar.GetTestProjectFromEnv(), fmt.Sprintf("tf-test-my-snapshot%s", context["random_suffix"])),
ImportState: true,
ImportStateVerify: true,
},
},
})
}
func testAccComputeSnapshotIamMember_basicGenerated(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_compute_snapshot" "snapshot" {
name = "tf-test-my-snapshot%{random_suffix}"
source_disk = google_compute_disk.persistent.id
zone = "us-central1-a"
labels = {
my_label = "value"
}
storage_locations = ["us-central1"]
}
data "google_compute_image" "debian" {
family = "debian-11"
project = "debian-cloud"
}
resource "google_compute_disk" "persistent" {
name = "tf-test-debian-disk%{random_suffix}"
image = data.google_compute_image.debian.self_link
size = 10
type = "pd-ssd"
zone = "us-central1-a"
}
resource "google_compute_snapshot_iam_member" "foo" {
project = google_compute_snapshot.snapshot.project
name = google_compute_snapshot.snapshot.name
role = "%{role}"
member = "user:admin@hashicorptest.com"
}
`, context)
}
func testAccComputeSnapshotIamPolicy_basicGenerated(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_compute_snapshot" "snapshot" {
name = "tf-test-my-snapshot%{random_suffix}"
source_disk = google_compute_disk.persistent.id
zone = "us-central1-a"
labels = {
my_label = "value"
}
storage_locations = ["us-central1"]
}
data "google_compute_image" "debian" {
family = "debian-11"
project = "debian-cloud"
}
resource "google_compute_disk" "persistent" {
name = "tf-test-debian-disk%{random_suffix}"
image = data.google_compute_image.debian.self_link
size = 10
type = "pd-ssd"
zone = "us-central1-a"
}
data "google_iam_policy" "foo" {
binding {
role = "%{role}"
members = ["user:admin@hashicorptest.com"]
}
}
resource "google_compute_snapshot_iam_policy" "foo" {
project = google_compute_snapshot.snapshot.project
name = google_compute_snapshot.snapshot.name
policy_data = data.google_iam_policy.foo.policy_data
}
data "google_compute_snapshot_iam_policy" "foo" {
project = google_compute_snapshot.snapshot.project
name = google_compute_snapshot.snapshot.name
depends_on = [
google_compute_snapshot_iam_policy.foo
]
}
`, context)
}
func testAccComputeSnapshotIamPolicy_emptyBinding(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_compute_snapshot" "snapshot" {
name = "tf-test-my-snapshot%{random_suffix}"
source_disk = google_compute_disk.persistent.id
zone = "us-central1-a"
labels = {
my_label = "value"
}
storage_locations = ["us-central1"]
}
data "google_compute_image" "debian" {
family = "debian-11"
project = "debian-cloud"
}
resource "google_compute_disk" "persistent" {
name = "tf-test-debian-disk%{random_suffix}"
image = data.google_compute_image.debian.self_link
size = 10
type = "pd-ssd"
zone = "us-central1-a"
}
data "google_iam_policy" "foo" {
}
resource "google_compute_snapshot_iam_policy" "foo" {
project = google_compute_snapshot.snapshot.project
name = google_compute_snapshot.snapshot.name
policy_data = data.google_iam_policy.foo.policy_data
}
`, context)
}
func testAccComputeSnapshotIamBinding_basicGenerated(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_compute_snapshot" "snapshot" {
name = "tf-test-my-snapshot%{random_suffix}"
source_disk = google_compute_disk.persistent.id
zone = "us-central1-a"
labels = {
my_label = "value"
}
storage_locations = ["us-central1"]
}
data "google_compute_image" "debian" {
family = "debian-11"
project = "debian-cloud"
}
resource "google_compute_disk" "persistent" {
name = "tf-test-debian-disk%{random_suffix}"
image = data.google_compute_image.debian.self_link
size = 10
type = "pd-ssd"
zone = "us-central1-a"
}
resource "google_compute_snapshot_iam_binding" "foo" {
project = google_compute_snapshot.snapshot.project
name = google_compute_snapshot.snapshot.name
role = "%{role}"
members = ["user:admin@hashicorptest.com"]
}
`, context)
}
func testAccComputeSnapshotIamBinding_updateGenerated(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_compute_snapshot" "snapshot" {
name = "tf-test-my-snapshot%{random_suffix}"
source_disk = google_compute_disk.persistent.id
zone = "us-central1-a"
labels = {
my_label = "value"
}
storage_locations = ["us-central1"]
}
data "google_compute_image" "debian" {
family = "debian-11"
project = "debian-cloud"
}
resource "google_compute_disk" "persistent" {
name = "tf-test-debian-disk%{random_suffix}"
image = data.google_compute_image.debian.self_link
size = 10
type = "pd-ssd"
zone = "us-central1-a"
}
resource "google_compute_snapshot_iam_binding" "foo" {
project = google_compute_snapshot.snapshot.project
name = google_compute_snapshot.snapshot.name
role = "%{role}"
members = ["user:admin@hashicorptest.com", "user:gterraformtest1@gmail.com"]
}
`, context)
}