Skip to content

Commit

Permalink
Run CryptoKey key_access_justification test only in beta (GoogleCloud…
Browse files Browse the repository at this point in the history
  • Loading branch information
tdbhacks authored Aug 12, 2024
1 parent 59fa585 commit 1132208
Showing 1 changed file with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<% autogen_exception -%>
package kms_test

import (
Expand Down Expand Up @@ -317,6 +318,7 @@ func TestAccKmsCryptoKey_destroyDuration(t *testing.T) {
})
}

<% unless version == 'ga' -%>
func TestAccKmsCryptoKey_keyAccessJustificationsPolicy(t *testing.T) {
t.Parallel()

Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -363,6 +365,7 @@ func TestAccKmsCryptoKey_keyAccessJustificationsPolicy(t *testing.T) {
},
})
}
<% end -%>

func TestAccKmsCryptoKey_importOnly(t *testing.T) {
t.Parallel()
Expand Down Expand Up @@ -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" {
Expand Down Expand Up @@ -836,27 +866,32 @@ 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"
billing_account = "%s"
}

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 = {
Expand All @@ -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(`
Expand Down

0 comments on commit 1132208

Please sign in to comment.