@@ -12,88 +12,46 @@ import (
12
12
)
13
13
14
14
func TestAccDataSourceDNSKeys_basic (t * testing.T ) {
15
- // TODO: https://github.com/hashicorp/terraform-provider-google/issues/14158
16
- acctest .SkipIfVcr (t )
17
15
t .Parallel ()
18
16
19
17
dnsZoneName := fmt .Sprintf ("tf-test-dnskey-test-%s" , acctest .RandString (t , 10 ))
20
18
21
- var kskDigest1 , kskDigest2 , zskPubKey1 , zskPubKey2 , kskAlg1 , kskAlg2 string
22
-
23
19
acctest .VcrTest (t , resource.TestCase {
24
- PreCheck : func () { acctest .AccTestPreCheck (t ) },
25
- CheckDestroy : testAccCheckDNSManagedZoneDestroyProducerFramework (t ),
20
+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
21
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
22
+ CheckDestroy : testAccCheckDNSManagedZoneDestroyProducer (t ),
26
23
Steps : []resource.TestStep {
27
24
{
28
- ExternalProviders : map [string ]resource.ExternalProvider {
29
- "google" : {
30
- VersionConstraint : "4.58.0" ,
31
- Source : "hashicorp/google" ,
32
- },
33
- },
34
- Config : testAccDataSourceDNSKeysConfigWithOutputs (dnsZoneName , "on" ),
25
+ Config : testAccDataSourceDNSKeysConfig (dnsZoneName , "on" ),
35
26
Check : resource .ComposeTestCheckFunc (
36
27
testAccDataSourceDNSKeysDSRecordCheck ("data.google_dns_keys.foo_dns_key" ),
37
28
resource .TestCheckResourceAttr ("data.google_dns_keys.foo_dns_key" , "key_signing_keys.#" , "1" ),
38
29
resource .TestCheckResourceAttr ("data.google_dns_keys.foo_dns_key" , "zone_signing_keys.#" , "1" ),
39
30
resource .TestCheckResourceAttr ("data.google_dns_keys.foo_dns_key_id" , "key_signing_keys.#" , "1" ),
40
31
resource .TestCheckResourceAttr ("data.google_dns_keys.foo_dns_key_id" , "zone_signing_keys.#" , "1" ),
41
- acctest .TestExtractResourceAttr ("data.google_dns_keys.foo_dns_key" , "key_signing_keys.0.digests.0.digest" , & kskDigest1 ),
42
- acctest .TestExtractResourceAttr ("data.google_dns_keys.foo_dns_key_id" , "zone_signing_keys.0.public_key" , & zskPubKey1 ),
43
- acctest .TestExtractResourceAttr ("data.google_dns_keys.foo_dns_key_id" , "key_signing_keys.0.algorithm" , & kskAlg1 ),
44
- ),
45
- },
46
- {
47
- ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
48
- Config : testAccDataSourceDNSKeysConfigWithOutputs (dnsZoneName , "on" ),
49
- Check : resource .ComposeTestCheckFunc (
50
- testAccDataSourceDNSKeysDSRecordCheck ("data.google_dns_keys.foo_dns_key" ),
51
- resource .TestCheckResourceAttr ("data.google_dns_keys.foo_dns_key" , "key_signing_keys.#" , "1" ),
52
- resource .TestCheckResourceAttr ("data.google_dns_keys.foo_dns_key" , "zone_signing_keys.#" , "1" ),
53
- acctest .TestExtractResourceAttr ("data.google_dns_keys.foo_dns_key" , "key_signing_keys.0.digests.0.digest" , & kskDigest2 ),
54
- acctest .TestExtractResourceAttr ("data.google_dns_keys.foo_dns_key_id" , "zone_signing_keys.0.public_key" , & zskPubKey2 ),
55
- acctest .TestExtractResourceAttr ("data.google_dns_keys.foo_dns_key_id" , "key_signing_keys.0.algorithm" , & kskAlg2 ),
56
- acctest .TestCheckAttributeValuesEqual (& kskDigest1 , & kskDigest2 ),
57
- acctest .TestCheckAttributeValuesEqual (& zskPubKey1 , & zskPubKey2 ),
58
- acctest .TestCheckAttributeValuesEqual (& kskAlg1 , & kskAlg2 ),
59
32
),
60
33
},
61
34
},
62
35
})
63
36
}
64
37
65
38
func TestAccDataSourceDNSKeys_noDnsSec (t * testing.T ) {
66
- // TODO: https://github.com/hashicorp/terraform-provider-google/issues/14158
67
- acctest .SkipIfVcr (t )
68
39
t .Parallel ()
69
40
70
41
dnsZoneName := fmt .Sprintf ("tf-test-dnskey-test-%s" , acctest .RandString (t , 10 ))
71
42
72
43
acctest .VcrTest (t , resource.TestCase {
73
- PreCheck : func () { acctest .AccTestPreCheck (t ) },
74
- CheckDestroy : testAccCheckDNSManagedZoneDestroyProducerFramework (t ),
44
+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
45
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
46
+ CheckDestroy : testAccCheckDNSManagedZoneDestroyProducer (t ),
75
47
Steps : []resource.TestStep {
76
48
{
77
- ExternalProviders : map [string ]resource.ExternalProvider {
78
- "google" : {
79
- VersionConstraint : "4.58.0" ,
80
- Source : "hashicorp/google" ,
81
- },
82
- },
83
49
Config : testAccDataSourceDNSKeysConfig (dnsZoneName , "off" ),
84
50
Check : resource .ComposeTestCheckFunc (
85
51
resource .TestCheckResourceAttr ("data.google_dns_keys.foo_dns_key" , "key_signing_keys.#" , "0" ),
86
52
resource .TestCheckResourceAttr ("data.google_dns_keys.foo_dns_key" , "zone_signing_keys.#" , "0" ),
87
53
),
88
54
},
89
- {
90
- ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
91
- Config : testAccDataSourceDNSKeysConfig (dnsZoneName , "off" ),
92
- Check : resource .ComposeTestCheckFunc (
93
- resource .TestCheckResourceAttr ("data.google_dns_keys.foo_dns_key" , "key_signing_keys.#" , "0" ),
94
- resource .TestCheckResourceAttr ("data.google_dns_keys.foo_dns_key" , "zone_signing_keys.#" , "0" ),
95
- ),
96
- },
97
55
},
98
56
})
99
57
}
@@ -117,7 +75,7 @@ func testAccDataSourceDNSKeysConfig(dnsZoneName, dnssecStatus string) string {
117
75
return fmt .Sprintf (`
118
76
resource "google_dns_managed_zone" "foo" {
119
77
name = "%s"
120
- dns_name = "%s .hashicorptest.com."
78
+ dns_name = "dnssec.gcp.tfacc .hashicorptest.com."
121
79
122
80
dnssec_config {
123
81
state = "%s"
@@ -132,27 +90,90 @@ data "google_dns_keys" "foo_dns_key" {
132
90
data "google_dns_keys" "foo_dns_key_id" {
133
91
managed_zone = google_dns_managed_zone.foo.id
134
92
}
135
- ` , dnsZoneName , dnsZoneName , dnssecStatus )
93
+ ` , dnsZoneName , dnssecStatus )
94
+ }
95
+
96
+ // TestAccDataSourceDNSKeys_basic_AdcAuth is the same as TestAccDataSourceDNSKeys_basic but the test enforces that a developer runs this using
97
+ // ADCs, supplied via GOOGLE_APPLICATION_CREDENTIALS. If any other credentials ENVs are set the PreCheck will fail.
98
+ // Commented out until this test can run in TeamCity/CI.
99
+ // func TestAccDataSourceDNSKeys_basic_AdcAuth(t *testing.T) {
100
+ // acctest.SkipIfVcr(t) // Uses external providers
101
+ // t.Parallel()
102
+
103
+ // creds := os.Getenv("GOOGLE_APPLICATION_CREDENTIALS") // PreCheck assertion handles checking this is set
104
+
105
+ // dnsZoneName := fmt.Sprintf("tf-test-dnskey-test-%s", acctest.RandString(t, 10))
106
+
107
+ // context := map[string]interface{}{
108
+ // "credentials_path": creds,
109
+ // "dns_zone_name": dnsZoneName,
110
+ // "dnssec_status": "on",
111
+ // }
112
+
113
+ // acctest.VcrTest(t, resource.TestCase{
114
+ // PreCheck: func() { acctest.AccTestPreCheck_AdcCredentialsOnly(t) }, // Note different than default
115
+ // CheckDestroy: testAccCheckDNSManagedZoneDestroyProducer(t),
116
+ // Steps: []resource.TestStep{
117
+ // // Check test fails with version of provider where data source is implemented with PF
118
+ // {
119
+ // ExternalProviders: map[string]resource.ExternalProvider{
120
+ // "google": {
121
+ // VersionConstraint: "4.60.0", // Muxed provider with dns data sources migrated to PF
122
+ // Source: "hashicorp/google",
123
+ // },
124
+ // },
125
+ // ExpectError: regexp.MustCompile("Post \"https://oauth2.googleapis.com/token\": context canceled"),
126
+ // Config: testAccDataSourceDNSKeysConfig_AdcCredentials(context),
127
+ // Check: resource.ComposeTestCheckFunc(
128
+ // testAccDataSourceDNSKeysDSRecordCheck("data.google_dns_keys.foo_dns_key"),
129
+ // resource.TestCheckResourceAttr("data.google_dns_keys.foo_dns_key", "key_signing_keys.#", "1"),
130
+ // resource.TestCheckResourceAttr("data.google_dns_keys.foo_dns_key", "zone_signing_keys.#", "1"),
131
+ // resource.TestCheckResourceAttr("data.google_dns_keys.foo_dns_key_id", "key_signing_keys.#", "1"),
132
+ // resource.TestCheckResourceAttr("data.google_dns_keys.foo_dns_key_id", "zone_signing_keys.#", "1"),
133
+ // ),
134
+ // },
135
+ // // Test should pass with more recent code
136
+ // {
137
+ // ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
138
+ // Config: testAccDataSourceDNSKeysConfig_AdcCredentials(context),
139
+ // Check: resource.ComposeTestCheckFunc(
140
+ // testAccDataSourceDNSKeysDSRecordCheck("data.google_dns_keys.foo_dns_key"),
141
+ // resource.TestCheckResourceAttr("data.google_dns_keys.foo_dns_key", "key_signing_keys.#", "1"),
142
+ // resource.TestCheckResourceAttr("data.google_dns_keys.foo_dns_key", "zone_signing_keys.#", "1"),
143
+ // resource.TestCheckResourceAttr("data.google_dns_keys.foo_dns_key_id", "key_signing_keys.#", "1"),
144
+ // resource.TestCheckResourceAttr("data.google_dns_keys.foo_dns_key_id", "zone_signing_keys.#", "1"),
145
+ // ),
146
+ // },
147
+ // },
148
+ // })
149
+ // }
150
+
151
+ func testAccDataSourceDNSKeysConfig_AdcCredentials (context map [string ]interface {}) string {
152
+ return acctest .Nprintf (`
153
+
154
+ // The auth problem isn't triggered unless provider block is
155
+ // present in the test config.
156
+
157
+ provider "google" {
158
+ credentials = "%{credentials_path}"
136
159
}
137
160
138
- // This function extends the config returned from the `testAccDataSourceDNSKeysConfig` function
139
- // to include output blocks that access the `key_signing_keys` and `zone_signing_keys` attributes.
140
- // These are null if DNSSEC is not enabled.
141
- func testAccDataSourceDNSKeysConfigWithOutputs (dnsZoneName , dnssecStatus string ) string {
161
+ resource "google_dns_managed_zone" "foo" {
162
+ name = "%{dns_zone_name}"
163
+ dns_name = "dnssec.gcp.tfacc.hashicorptest.com."
142
164
143
- config := testAccDataSourceDNSKeysConfig (dnsZoneName , dnssecStatus )
144
- config = config + `
145
- # These outputs will cause an error if google_dns_managed_zone.foo.dnssec_config.state == "off"
165
+ dnssec_config {
166
+ state = "%{dnssec_status}"
167
+ non_existence = "nsec3"
168
+ }
169
+ }
146
170
147
- output "test_access_google_dns_keys_key_signing_keys" {
148
- description = "Testing that we can access a value in key_signing_keys ok as a computed block"
149
- value = data.google_dns_keys.foo_dns_key_id.key_signing_keys[0].ds_record
171
+ data "google_dns_keys" "foo_dns_key" {
172
+ managed_zone = google_dns_managed_zone.foo.name
150
173
}
151
174
152
- output "test_access_google_dns_keys_zone_signing_keys" {
153
- description = "Testing that we can access a value in zone_signing_keys ok as a computed block"
154
- value = data.google_dns_keys.foo_dns_key_id.zone_signing_keys[0].id
175
+ data "google_dns_keys" "foo_dns_key_id" {
176
+ managed_zone = google_dns_managed_zone.foo.id
155
177
}
156
- `
157
- return config
178
+ ` , context )
158
179
}
0 commit comments