diff --git a/azurerm/resource_arm_kubernetes_cluster.go b/azurerm/resource_arm_kubernetes_cluster.go index 0e413785df41..cd111d63a391 100644 --- a/azurerm/resource_arm_kubernetes_cluster.go +++ b/azurerm/resource_arm_kubernetes_cluster.go @@ -73,8 +73,10 @@ func resourceArmKubernetesCluster() *schema.Resource { "resource_group_name": resourceGroupNameSchema(), "dns_prefix": { - Type: schema.TypeString, - Required: true, + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validateKubernetesClusterDnsPrefix(), }, "kubernetes_version": { @@ -1123,6 +1125,13 @@ func validateKubernetesClusterAgentPoolName() schema.SchemaValidateFunc { ) } +func validateKubernetesClusterDnsPrefix() schema.SchemaValidateFunc { + return validation.StringMatch( + regexp.MustCompile("^[a-zA-Z][-a-zA-Z0-9]{0,43}[a-zA-Z0-9]$"), + "The DNS name must contain between 3 and 45 characters. The name can contain only letters, numbers, and hyphens. The name must start with a letter and must end with a letter or a number.", + ) +} + func flattenKubernetesClusterKubeConfig(config kubernetes.KubeConfig) []interface{} { values := make(map[string]interface{}) diff --git a/website/docs/r/kubernetes_cluster.html.markdown b/website/docs/r/kubernetes_cluster.html.markdown index 338e42ead7be..1429866effec 100644 --- a/website/docs/r/kubernetes_cluster.html.markdown +++ b/website/docs/r/kubernetes_cluster.html.markdown @@ -67,7 +67,9 @@ The following arguments are supported: * `agent_pool_profile` - (Required) One or more `agent_pool_profile` blocks as documented below. -* `dns_prefix` - (Required) DNS prefix specified when creating the managed cluster. +* `dns_prefix` - (Required) DNS prefix specified when creating the managed cluster. Changing this forces a new resource to be created. + +-> **NOTE:** The `dns_prefix` must contain between 3 and 45 characters, and can contain only letters, numbers, and hyphens. It must start with a letter and must end with a letter or a number. * `service_principal` - (Required) A `service_principal` block as documented below.