Skip to content

Commit f8c6233

Browse files
containers: address local DNS review feedback
1 parent bbc9d59 commit f8c6233

3 files changed

Lines changed: 36 additions & 10 deletions

File tree

internal/services/containers/kubernetes_cluster_node_pool_resource.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ func resourceKubernetesClusterNodePoolSchema() map[string]*pluginsdk.Schema {
228228

229229
"linux_os_config": schemaNodePoolLinuxOSConfig(),
230230

231-
"local_dns_profile": schemaNodePoolResourceLocalDNSProfile(),
231+
"local_dns_profile": schemaNodePoolLocalDNSProfile(),
232232

233233
"fips_enabled": {
234234
Type: pluginsdk.TypeBool,
@@ -1967,10 +1967,6 @@ func flattenAgentPoolNetworkProfileNodePublicIPTags(input *[]agentpools.IPTag) m
19671967
return out
19681968
}
19691969

1970-
func schemaNodePoolResourceLocalDNSProfile() *pluginsdk.Schema {
1971-
return schemaNodePoolLocalDNSProfile()
1972-
}
1973-
19741970
func expandAgentPoolLocalDNSProfile(input []interface{}) *agentpools.LocalDNSProfile {
19751971
if len(input) == 0 || input[0] == nil {
19761972
return nil

internal/services/containers/kubernetes_nodepool.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ func SchemaDefaultNodePool() *pluginsdk.Schema {
282282
Optional: true,
283283
},
284284

285-
"local_dns_profile": schemaDefaultNodePoolLocalDNSProfile(),
285+
"local_dns_profile": schemaNodePoolLocalDNSProfile(),
286286
}
287287
}(),
288288
},
@@ -677,10 +677,6 @@ func schemaNodePoolNetworkProfile() *pluginsdk.Schema {
677677
}
678678
}
679679

680-
func schemaDefaultNodePoolLocalDNSProfile() *pluginsdk.Schema {
681-
return schemaNodePoolLocalDNSProfile()
682-
}
683-
684680
func schemaNodePoolLocalDNSProfile() *pluginsdk.Schema {
685681
return &pluginsdk.Schema{
686682
Type: pluginsdk.TypeList,
@@ -776,6 +772,9 @@ func schemaLocalDNSOverride() *pluginsdk.Schema {
776772
}
777773

778774
func validateDefaultNodePoolLocalDNSProfileRawConfig(d *pluginsdk.ResourceDiff) error {
775+
// The override schema uses the SDK's full-block set hash so changing settings
776+
// under an existing domain still produces a diff. Raw config validation keeps
777+
// the API's domain-keyed uniqueness rule without rejecting unknown domains.
779778
rawConfig := d.GetRawConfig()
780779
if !localDNSRawValueCanIterate(rawConfig) {
781780
return nil

internal/services/containers/kubernetes_nodepool_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package containers
66
import (
77
"testing"
88

9+
"github.com/hashicorp/go-cty/cty"
910
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1011
)
1112

@@ -40,3 +41,33 @@ func TestSchemaLocalDNSOverrideHashIncludesSettings(t *testing.T) {
4041
t.Fatalf("expected two local DNS override hashes, got %d", localDNSOverrides.Len())
4142
}
4243
}
44+
45+
func TestValidateLocalDNSOverrideRawConfigSkipsUnknownDomain(t *testing.T) {
46+
input := cty.ListVal([]cty.Value{
47+
cty.ObjectVal(map[string]cty.Value{
48+
"domain": cty.UnknownVal(cty.String),
49+
}),
50+
cty.ObjectVal(map[string]cty.Value{
51+
"domain": cty.UnknownVal(cty.String),
52+
}),
53+
})
54+
55+
if err := validateLocalDNSOverrideRawConfig(input, "local_dns_profile.kube_dns_override"); err != nil {
56+
t.Fatalf("expected unknown domains to be skipped, got %q", err)
57+
}
58+
}
59+
60+
func TestValidateLocalDNSOverrideRawConfigRejectsDuplicateDomain(t *testing.T) {
61+
input := cty.ListVal([]cty.Value{
62+
cty.ObjectVal(map[string]cty.Value{
63+
"domain": cty.StringVal("example.com"),
64+
}),
65+
cty.ObjectVal(map[string]cty.Value{
66+
"domain": cty.StringVal("example.com"),
67+
}),
68+
})
69+
70+
if err := validateLocalDNSOverrideRawConfig(input, "local_dns_profile.kube_dns_override"); err == nil {
71+
t.Fatal("expected duplicate domain validation error")
72+
}
73+
}

0 commit comments

Comments
 (0)