Skip to content

Commit

Permalink
add dns keys datasource (#7186) (#5179)
Browse files Browse the repository at this point in the history
* initial commit for muxer and framework provider

* minor changes to new provider and muxer

* add provider model, provider schema, defaults in config

* initial commit to upgrading the provider

* match schema to sdk provider

* remove duplicates

* add dns record set, test and provider schema update

* add dcl custom endpoints, custom endpoint validator and credentials validator

* mv sdk provider defaults to config, fix up other small issues

* add changes from merging with main

* working with provider meta

* move MultiEnvDefault function so it will hopefully be picked up by the validator

* don't need to downgrade the provider

* fix beta build issue

* remove redundant dcl generated custom endpoint

* strange org policy issue - only needed in ga

* fix failures in beta

* fix vcr tests

* fix vcr tests for real hopefully

* fix provider meta error

* Update record set data source test to compare muxed provider to v4.50.0

This includes copying useful test util functions from terraform-provider-random (https://github.com/hashicorp/terraform-provider-random/blob/main/internal/provider/resource_integer_test.go#L1006)

* Fix error in `providerVersion450`

* add framework_test_utils

* add functionality to configure the test framework provider and get check destroys working

* add managed zone check destroy

* add tflog to framework files

* review comment changes

* use version.ProviderVersion

* add comment for test provider configure function

* remove redundant Cloudbuildv2CustomEndpoint endpoint on framework provider

* adding data source dns keys

* fix providermeta errors

* add sdk upgrade tests and check destroy to dns keys tests

* add descriptions

* formatting changes

* add check attribute values equal

* remove diffsuppress comment, add other test checks

---------

Signed-off-by: Modular Magician <magic-modules@google.com>
Co-authored-by: Sarah French <sarah.french@hashicorp.com>
  • Loading branch information
modular-magician and SarahFrench authored Feb 6, 2023
1 parent 9d02521 commit 0680a77
Show file tree
Hide file tree
Showing 6 changed files with 455 additions and 168 deletions.
3 changes: 3 additions & 0 deletions .changelog/7186.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:none

```
44 changes: 36 additions & 8 deletions google-beta/data_source_dns_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,41 @@ import (
func TestAccDataSourceDNSKeys_basic(t *testing.T) {
t.Parallel()

dnsZoneName := fmt.Sprintf("data-dnskey-test-%s", randString(t, 10))
dnsZoneName := fmt.Sprintf("tf-dnskey-test-%s", randString(t, 10))

var kskDigest1, kskDigest2, zskPubKey1, zskPubKey2, kskAlg1, kskAlg2 string

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckDNSManagedZoneDestroyProducer(t),
CheckDestroy: testAccCheckDNSManagedZoneDestroyProducerFramework(t),
Steps: []resource.TestStep{
{
Config: testAccDataSourceDNSKeysConfig(dnsZoneName, "on"),
ExternalProviders: providerVersion450(),
Config: testAccDataSourceDNSKeysConfig(dnsZoneName, "on"),
Check: resource.ComposeTestCheckFunc(
testAccDataSourceDNSKeysDSRecordCheck("data.google_dns_keys.foo_dns_key"),
resource.TestCheckResourceAttr("data.google_dns_keys.foo_dns_key", "key_signing_keys.#", "1"),
resource.TestCheckResourceAttr("data.google_dns_keys.foo_dns_key", "zone_signing_keys.#", "1"),
resource.TestCheckResourceAttr("data.google_dns_keys.foo_dns_key_id", "key_signing_keys.#", "1"),
resource.TestCheckResourceAttr("data.google_dns_keys.foo_dns_key_id", "zone_signing_keys.#", "1"),
testExtractResourceAttr("data.google_dns_keys.foo_dns_key", "key_signing_keys.0.digests.0.digest", &kskDigest1),
testExtractResourceAttr("data.google_dns_keys.foo_dns_key_id", "zone_signing_keys.0.public_key", &zskPubKey1),
testExtractResourceAttr("data.google_dns_keys.foo_dns_key_id", "key_signing_keys.0.algorithm", &kskAlg1),
),
},
{
ProtoV5ProviderFactories: protoV5ProviderFactories(t),
Config: testAccDataSourceDNSKeysConfig(dnsZoneName, "on"),
Check: resource.ComposeTestCheckFunc(
testAccDataSourceDNSKeysDSRecordCheck("data.google_dns_keys.foo_dns_key"),
resource.TestCheckResourceAttr("data.google_dns_keys.foo_dns_key", "key_signing_keys.#", "1"),
resource.TestCheckResourceAttr("data.google_dns_keys.foo_dns_key", "zone_signing_keys.#", "1"),
testExtractResourceAttr("data.google_dns_keys.foo_dns_key", "key_signing_keys.0.digests.0.digest", &kskDigest2),
testExtractResourceAttr("data.google_dns_keys.foo_dns_key_id", "zone_signing_keys.0.public_key", &zskPubKey2),
testExtractResourceAttr("data.google_dns_keys.foo_dns_key_id", "key_signing_keys.0.algorithm", &kskAlg2),
testCheckAttributeValuesEqual(&kskDigest1, &kskDigest2),
testCheckAttributeValuesEqual(&zskPubKey1, &zskPubKey2),
testCheckAttributeValuesEqual(&kskAlg1, &kskAlg2),
),
},
},
Expand All @@ -35,15 +55,23 @@ func TestAccDataSourceDNSKeys_basic(t *testing.T) {
func TestAccDataSourceDNSKeys_noDnsSec(t *testing.T) {
t.Parallel()

dnsZoneName := fmt.Sprintf("data-dnskey-test-%s", randString(t, 10))
dnsZoneName := fmt.Sprintf("tf-dnskey-test-%s", randString(t, 10))

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckDNSManagedZoneDestroyProducer(t),
CheckDestroy: testAccCheckDNSManagedZoneDestroyProducerFramework(t),
Steps: []resource.TestStep{
{
Config: testAccDataSourceDNSKeysConfig(dnsZoneName, "off"),
ExternalProviders: providerVersion450(),
Config: testAccDataSourceDNSKeysConfig(dnsZoneName, "off"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.google_dns_keys.foo_dns_key", "key_signing_keys.#", "0"),
resource.TestCheckResourceAttr("data.google_dns_keys.foo_dns_key", "zone_signing_keys.#", "0"),
),
},
{
ProtoV5ProviderFactories: protoV5ProviderFactories(t),
Config: testAccDataSourceDNSKeysConfig(dnsZoneName, "off"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.google_dns_keys.foo_dns_key", "key_signing_keys.#", "0"),
resource.TestCheckResourceAttr("data.google_dns_keys.foo_dns_key", "zone_signing_keys.#", "0"),
Expand Down
Loading

0 comments on commit 0680a77

Please sign in to comment.