mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-10-05 02:01:05 +00:00
30fe927df6
<!-- This change is generated by MagicModules. --> /cc @kierachell
44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package google
|
|
|
|
import (
|
|
"fmt"
|
|
"regexp"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
)
|
|
|
|
func TestAccDataSourceGoogleKmsCryptoKey_basic(t *testing.T) {
|
|
kms := BootstrapKMSKey(t)
|
|
|
|
// Name in the KMS client is in the format projects/<project>/locations/<location>/keyRings/<keyRingName>/cryptoKeys/<keyId>
|
|
keyParts := strings.Split(kms.CryptoKey.Name, "/")
|
|
cryptoKeyId := keyParts[len(keyParts)-1]
|
|
|
|
fmt.Println(testAccDataSourceGoogleKmsCryptoKey_basic(kms.KeyRing.Name, cryptoKeyId))
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
Steps: []resource.TestStep{
|
|
{
|
|
Config: testAccDataSourceGoogleKmsCryptoKey_basic(kms.KeyRing.Name, cryptoKeyId),
|
|
Check: resource.TestMatchResourceAttr("data.google_kms_crypto_key.kms_crypto_key", "self_link", regexp.MustCompile(kms.CryptoKey.Name)),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
/*
|
|
This test should run in its own project, because KMS key rings and crypto keys are not deletable
|
|
*/
|
|
func testAccDataSourceGoogleKmsCryptoKey_basic(keyRingName, cryptoKeyName string) string {
|
|
return fmt.Sprintf(`
|
|
data "google_kms_crypto_key" "kms_crypto_key" {
|
|
key_ring = "%s"
|
|
name = "%s"
|
|
}
|
|
`, keyRingName, cryptoKeyName)
|
|
}
|