From 1132208be73bdd6618c537cb6d6e6ce1cebcf2e0 Mon Sep 17 00:00:00 2001
From: Alessio Buraggina <28165200+tdbhacks@users.noreply.github.com>
Date: Mon, 12 Aug 2024 17:32:56 -0400
Subject: [PATCH] Run CryptoKey key_access_justification test only in beta
 (#11419)

---
 ...go => resource_kms_crypto_key_test.go.erb} | 44 +++++++++++++++++--
 1 file changed, 40 insertions(+), 4 deletions(-)
 rename mmv1/third_party/terraform/services/kms/{resource_kms_crypto_key_test.go => resource_kms_crypto_key_test.go.erb} (97%)

diff --git a/mmv1/third_party/terraform/services/kms/resource_kms_crypto_key_test.go b/mmv1/third_party/terraform/services/kms/resource_kms_crypto_key_test.go.erb
similarity index 97%
rename from mmv1/third_party/terraform/services/kms/resource_kms_crypto_key_test.go
rename to mmv1/third_party/terraform/services/kms/resource_kms_crypto_key_test.go.erb
index 1d2488d15140..4af4569dcdf4 100644
--- a/mmv1/third_party/terraform/services/kms/resource_kms_crypto_key_test.go
+++ b/mmv1/third_party/terraform/services/kms/resource_kms_crypto_key_test.go.erb
@@ -1,3 +1,4 @@
+<% autogen_exception -%>
 package kms_test
 
 import (
@@ -317,6 +318,7 @@ func TestAccKmsCryptoKey_destroyDuration(t *testing.T) {
 	})
 }
 
+<% unless version == 'ga' -%>
 func TestAccKmsCryptoKey_keyAccessJustificationsPolicy(t *testing.T) {
 	t.Parallel()
 
@@ -331,7 +333,7 @@ func TestAccKmsCryptoKey_keyAccessJustificationsPolicy(t *testing.T) {
 
 	acctest.VcrTest(t, resource.TestCase{
 		PreCheck:                 func() { acctest.AccTestPreCheck(t) },
-		ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
+		ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
 		Steps: []resource.TestStep{
 			{
 				Config: testGoogleKmsCryptoKey_keyAccessJustificationsPolicy(projectId, projectOrg, projectBillingAccount, keyRingName, cryptoKeyName, allowedAccessReason),
@@ -353,7 +355,7 @@ func TestAccKmsCryptoKey_keyAccessJustificationsPolicy(t *testing.T) {
 			},
 			// Use a separate TestStep rather than a CheckDestroy because we need the project to still exist.
 			{
-				Config: testGoogleKmsCryptoKey_removed(projectId, projectOrg, projectBillingAccount, keyRingName),
+				Config: testGoogleKmsCryptoKey_removedBeta(projectId, projectOrg, projectBillingAccount, keyRingName),
 				Check: resource.ComposeTestCheckFunc(
 					testAccCheckGoogleKmsCryptoKeyWasRemovedFromState("google_kms_crypto_key.crypto_key"),
 					testAccCheckGoogleKmsCryptoKeyVersionsDestroyed(t, projectId, location, keyRingName, cryptoKeyName),
@@ -363,6 +365,7 @@ func TestAccKmsCryptoKey_keyAccessJustificationsPolicy(t *testing.T) {
 		},
 	})
 }
+<% end -%>
 
 func TestAccKmsCryptoKey_importOnly(t *testing.T) {
 	t.Parallel()
@@ -805,6 +808,33 @@ resource "google_kms_key_ring" "key_ring" {
 `, projectId, projectId, projectOrg, projectBillingAccount, keyRingName)
 }
 
+<% unless version == 'ga' -%>
+func testGoogleKmsCryptoKey_removedBeta(projectId, projectOrg, projectBillingAccount, keyRingName string) string {
+	return fmt.Sprintf(`
+resource "google_project" "acceptance" {
+  provider        = google-beta
+  name            = "%s"
+  project_id      = "%s"
+  org_id          = "%s"
+  billing_account = "%s"
+}
+
+resource "google_project_service" "acceptance" {
+  provider = google-beta
+  project  = google_project.acceptance.project_id
+  service  = "cloudkms.googleapis.com"
+}
+
+resource "google_kms_key_ring" "key_ring" {
+  provider = google-beta
+  project  = google_project_service.acceptance.project
+  name     = "%s"
+  location = "us-central1"
+}
+`, projectId, projectId, projectOrg, projectBillingAccount, keyRingName)
+}
+<% end -%>
+
 func testGoogleKmsCryptoKey_destroyDuration(projectId, projectOrg, projectBillingAccount, keyRingName, cryptoKeyName string) string {
 	return fmt.Sprintf(`
 resource "google_project" "acceptance" {
@@ -836,9 +866,11 @@ resource "google_kms_crypto_key" "crypto_key" {
 `, projectId, projectId, projectOrg, projectBillingAccount, keyRingName, cryptoKeyName)
 }
 
+<% unless version == 'ga' -%>
 func testGoogleKmsCryptoKey_keyAccessJustificationsPolicy(projectId, projectOrg, projectBillingAccount, keyRingName, cryptoKeyName, allowed_access_reason string) string {
 	return fmt.Sprintf(`
 resource "google_project" "acceptance" {
+  provider        = google-beta
   name            = "%s"
   project_id      = "%s"
   org_id          = "%s"
@@ -846,17 +878,20 @@ resource "google_project" "acceptance" {
 }
 
 resource "google_project_service" "acceptance" {
-  project = google_project.acceptance.project_id
-  service = "cloudkms.googleapis.com"
+  provider = google-beta
+  project  = google_project.acceptance.project_id
+  service  = "cloudkms.googleapis.com"
 }
 
 resource "google_kms_key_ring" "key_ring" {
+  provider = google-beta
   project  = google_project_service.acceptance.project
   name     = "%s"
   location = "us-central1"
 }
 
 resource "google_kms_crypto_key" "crypto_key" {
+  provider = google-beta
   name     = "%s"
   key_ring = google_kms_key_ring.key_ring.id
   labels = {
@@ -868,6 +903,7 @@ resource "google_kms_crypto_key" "crypto_key" {
 }
 `, projectId, projectId, projectOrg, projectBillingAccount, keyRingName, cryptoKeyName, allowed_access_reason)
 }
+<% end -%>
 
 func testGoogleKmsCryptoKey_importOnly(projectId, projectOrg, projectBillingAccount, keyRingName, cryptoKeyName string) string {
 	return fmt.Sprintf(`