Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_kubernetes_cluster azurerm_kubernetes_cluster_node_pool - support for the custom_ca_trust_enabled property #19546

Merged
merged 3 commits into from Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -100,6 +100,11 @@ func resourceKubernetesClusterNodePool() *pluginsdk.Resource {
ValidateFunc: computeValidate.CapacityReservationGroupID,
},

"custom_ca_trust_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
},

"enable_auto_scaling": {
Type: pluginsdk.TypeBool,
Optional: true,
Expand Down Expand Up @@ -398,6 +403,7 @@ func resourceKubernetesClusterNodePoolCreate(d *pluginsdk.ResourceData, meta int
profile := agentpools.ManagedClusterAgentPoolProfileProperties{
OsType: utils.ToPtr(agentpools.OSType(osType)),
EnableAutoScaling: utils.Bool(enableAutoScaling),
EnableCustomCATrust: utils.Bool(d.Get("custom_ca_trust_enabled").(bool)),
EnableFIPS: utils.Bool(d.Get("fips_enabled").(bool)),
EnableEncryptionAtHost: utils.Bool(d.Get("enable_host_encryption").(bool)),
EnableUltraSSD: utils.Bool(d.Get("ultra_ssd_enabled").(bool)),
Expand Down Expand Up @@ -615,6 +621,10 @@ func resourceKubernetesClusterNodePoolUpdate(d *pluginsdk.ResourceData, meta int
props.EnableEncryptionAtHost = utils.Bool(d.Get("enable_host_encryption").(bool))
}

if d.HasChange("custom_ca_trust_enabled") {
props.EnableCustomCATrust = utils.Bool(d.Get("custom_ca_trust_enabled").(bool))
}

if d.HasChange("enable_node_public_ip") {
props.EnableNodePublicIP = utils.Bool(d.Get("enable_node_public_ip").(bool))
}
Expand Down Expand Up @@ -769,6 +779,7 @@ func resourceKubernetesClusterNodePoolRead(d *pluginsdk.ResourceData, meta inter
d.Set("enable_auto_scaling", props.EnableAutoScaling)
d.Set("enable_node_public_ip", props.EnableNodePublicIP)
d.Set("enable_host_encryption", props.EnableEncryptionAtHost)
d.Set("custom_ca_trust_enabled", props.EnableCustomCATrust)
d.Set("fips_enabled", props.EnableFIPS)
d.Set("ultra_ssd_enabled", props.EnableUltraSSD)

Expand Down
Expand Up @@ -881,6 +881,28 @@ func TestAccKubernetesClusterNodePool_workloadRuntime(t *testing.T) {
})
}

func TestAccKubernetesClusterNodePool_customCATrustEnabled(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster_node_pool", "test")
r := KubernetesClusterNodePoolResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.customCATrustEnabled(data, true),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.customCATrustEnabled(data, false),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func (t KubernetesClusterNodePoolResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := agentpools.ParseAgentPoolID(state.ID)
if err != nil {
Expand Down Expand Up @@ -2330,3 +2352,35 @@ resource "azurerm_kubernetes_cluster_node_pool" "test" {
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, workloadRuntime)
}

func (KubernetesClusterNodePoolResource) customCATrustEnabled(data acceptance.TestData, enabled bool) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-aks-%d"
location = "%s"
}
resource "azurerm_kubernetes_cluster" "test" {
name = "acctestaks%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
dns_prefix = "acctestaks%d"
default_node_pool {
name = "default"
node_count = 1
vm_size = "Standard_D2s_v3"
}
identity {
type = "SystemAssigned"
}
}
resource "azurerm_kubernetes_cluster_node_pool" "test" {
name = "internal"
kubernetes_cluster_id = azurerm_kubernetes_cluster.test.id
vm_size = "Standard_D2s_v3"
custom_ca_trust_enabled = "%t"
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, enabled)
}
Expand Up @@ -683,6 +683,28 @@ func TestAccKubernetesCluster_workloadIdentity(t *testing.T) {
})
}

func TestAccKubernetesCluster_customCATrustEnabled(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test")
r := KubernetesClusterResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.customCATrustEnabled(data, true),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.customCATrustEnabled(data, false),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccKubernetesCluster_webAppRouting(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test")
r := KubernetesClusterResource{}
Expand Down Expand Up @@ -2254,3 +2276,30 @@ resource "azurerm_kubernetes_cluster" "test" {
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}

func (KubernetesClusterResource) customCATrustEnabled(data acceptance.TestData, enabled bool) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-aks-%d"
location = "%s"
}
resource "azurerm_kubernetes_cluster" "test" {
name = "acctestaks%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
dns_prefix = "acctestaks%d"
default_node_pool {
name = "default"
node_count = 1
vm_size = "Standard_D2s_v3"
custom_ca_trust_enabled = "%t"
}
identity {
type = "SystemAssigned"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, enabled)
}
13 changes: 13 additions & 0 deletions internal/services/containers/kubernetes_nodepool.go
Expand Up @@ -64,6 +64,11 @@ func SchemaDefaultNodePool() *pluginsdk.Schema {
ValidateFunc: computeValidate.CapacityReservationGroupID,
},

"custom_ca_trust_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
},

// TODO 4.0: change this from enable_* to *_enabled
"enable_auto_scaling": {
Type: pluginsdk.TypeBool,
Expand Down Expand Up @@ -636,6 +641,7 @@ func ConvertDefaultNodePoolToAgentPool(input *[]managedclusters.ManagedClusterAg
MessageOfTheDay: defaultCluster.MessageOfTheDay,
MinCount: defaultCluster.MinCount,
EnableAutoScaling: defaultCluster.EnableAutoScaling,
EnableCustomCATrust: defaultCluster.EnableCustomCATrust,
EnableFIPS: defaultCluster.EnableFIPS,
OrchestratorVersion: defaultCluster.OrchestratorVersion,
ProximityPlacementGroupID: defaultCluster.ProximityPlacementGroupID,
Expand Down Expand Up @@ -735,6 +741,7 @@ func ExpandDefaultNodePool(d *pluginsdk.ResourceData) (*[]managedclusters.Manage

profile := managedclusters.ManagedClusterAgentPoolProfile{
EnableAutoScaling: utils.Bool(enableAutoScaling),
EnableCustomCATrust: utils.Bool(raw["custom_ca_trust_enabled"].(bool)),
EnableFIPS: utils.Bool(raw["fips_enabled"].(bool)),
EnableNodePublicIP: utils.Bool(raw["enable_node_public_ip"].(bool)),
EnableEncryptionAtHost: utils.Bool(raw["enable_host_encryption"].(bool)),
Expand Down Expand Up @@ -1087,6 +1094,11 @@ func FlattenDefaultNodePool(input *[]managedclusters.ManagedClusterAgentPoolProf
enableAutoScaling = *agentPool.EnableAutoScaling
}

customCaTrustEnabled := false
if agentPool.EnableCustomCATrust != nil {
customCaTrustEnabled = *agentPool.EnableCustomCATrust
}

enableFIPS := false
if agentPool.EnableFIPS != nil {
enableFIPS = *agentPool.EnableFIPS
Expand Down Expand Up @@ -1232,6 +1244,7 @@ func FlattenDefaultNodePool(input *[]managedclusters.ManagedClusterAgentPoolProf
"enable_auto_scaling": enableAutoScaling,
"enable_node_public_ip": enableNodePublicIP,
"enable_host_encryption": enableHostEncryption,
"custom_ca_trust_enabled": customCaTrustEnabled,
"fips_enabled": enableFIPS,
"host_group_id": hostGroupID,
"kubelet_disk_type": kubeletDiskType,
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/kubernetes_cluster.html.markdown
Expand Up @@ -324,6 +324,10 @@ A `default_node_pool` block supports the following:

* `capacity_reservation_group_id` - (Optional) Specifies the ID of the Capacity Reservation Group within which this AKS Cluster should be created. Changing this forces a new resource to be created.

* `custom_ca_trust_enabled` - (Optional) Specifies whether to trust a Custom CA. Defaults to `false`.

-> **Note:** This requires that the Preview Feature `Microsoft.ContainerService/CustomCATrustPreview` is enabled and the Resource Provider is re-registered, see [the documentation](https://learn.microsoft.com/en-us/azure/aks/custom-certificate-authority) for more information.

* `enable_auto_scaling` - (Optional) Should [the Kubernetes Auto Scaler](https://docs.microsoft.com/azure/aks/cluster-autoscaler) be enabled for this Node Pool? Defaults to `false`.

-> **Note:** This requires that the `type` is set to `VirtualMachineScaleSets`.
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/kubernetes_cluster_node_pool.html.markdown
Expand Up @@ -72,6 +72,10 @@ The following arguments are supported:

* `capacity_reservation_group_id` - (Optional) Specifies the ID of the Capacity Reservation Group where this Node Pool should exist. Changing this forces a new resource to be created.

* `custom_ca_trust_enabled` - (Optional) Specifies whether to trust a Custom CA. Defaults to `false`.

-> **Note:** This requires that the Preview Feature `Microsoft.ContainerService/CustomCATrustPreview` is enabled and the Resource Provider is re-registered, see [the documentation](https://learn.microsoft.com/en-us/azure/aks/custom-certificate-authority) for more information.

* `enable_auto_scaling` - (Optional) Whether to enable [auto-scaler](https://docs.microsoft.com/azure/aks/cluster-autoscaler). Defaults to `false`.

* `enable_host_encryption` - (Optional) Should the nodes in this Node Pool have host encryption enabled? Defaults to `false`.
Expand Down