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

Add run command enabled parameter to AKS cluster #15029

Merged
merged 2 commits into from
Apr 26, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions internal/services/containers/kubernetes_cluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,12 @@ func resourceKubernetesCluster() *pluginsdk.Resource {
Default: false,
},

"run_command_enabled": {
phillebaba marked this conversation as resolved.
Show resolved Hide resolved
Type: pluginsdk.TypeBool,
Optional: true,
Default: true,
phillebaba marked this conversation as resolved.
Show resolved Hide resolved
},

"private_dns_zone_id": {
Type: pluginsdk.TypeString,
Optional: true,
Expand Down Expand Up @@ -1061,6 +1067,7 @@ func resourceKubernetesClusterCreate(d *pluginsdk.ResourceData, meta interface{}
EnablePrivateCluster: &enablePrivateCluster,
AuthorizedIPRanges: apiServerAuthorizedIPRanges,
EnablePrivateClusterPublicFQDN: utils.Bool(d.Get("private_cluster_public_fqdn_enabled").(bool)),
DisableRunCommand: utils.Bool(!d.Get("run_command_enabled").(bool)),
}

nodeResourceGroup := d.Get("node_resource_group").(string)
Expand Down Expand Up @@ -1350,6 +1357,11 @@ func resourceKubernetesClusterUpdate(d *pluginsdk.ResourceData, meta interface{}
existing.ManagedClusterProperties.APIServerAccessProfile.EnablePrivateClusterPublicFQDN = utils.Bool(d.Get("private_cluster_public_fqdn_enabled").(bool))
}

if d.HasChange("run_command_enabled") {
updateCluster = true
existing.ManagedClusterProperties.APIServerAccessProfile.DisableRunCommand = utils.Bool(!d.Get("run_command_enabled").(bool))
}

if d.HasChange("auto_scaler_profile") {
updateCluster = true
autoScalerProfileRaw := d.Get("auto_scaler_profile").([]interface{})
Expand Down Expand Up @@ -1714,6 +1726,11 @@ func resourceKubernetesClusterRead(d *pluginsdk.ResourceData, meta interface{})

d.Set("private_cluster_enabled", accessProfile.EnablePrivateCluster)
d.Set("private_cluster_public_fqdn_enabled", accessProfile.EnablePrivateClusterPublicFQDN)
runCommandEnabled := true
if accessProfile.DisableRunCommand != nil {
runCommandEnabled = !*accessProfile.DisableRunCommand
}
d.Set("run_command_enabled", runCommandEnabled)
switch {
case accessProfile.PrivateDNSZone != nil && strings.EqualFold("System", *accessProfile.PrivateDNSZone):
d.Set("private_dns_zone_id", "System")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,28 @@ func TestAccKubernetesCluster_hostEncryption(t *testing.T) {
})
}

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

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.runCommand(data, currentKubernetesVersion, true),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("run_command_enabled").HasValue("true"),
),
},
{
Config: r.runCommand(data, currentKubernetesVersion, false),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("run_command_enabled").HasValue("false"),
),
},
})
}

func (t KubernetesClusterResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := parse.ClusterID(state.ID)
if err != nil {
Expand Down Expand Up @@ -116,6 +138,38 @@ resource "azurerm_kubernetes_cluster" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, controlPlaneVersion)
}

func (KubernetesClusterResource) runCommand(data acceptance.TestData, controlPlaneVersion string, runCommandEnabled 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"
kubernetes_version = %q
run_command_enabled = %t

default_node_pool {
name = "default"
node_count = 1
vm_size = "Standard_DS2_v2"
}

identity {
type = "SystemAssigned"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, controlPlaneVersion, runCommandEnabled)
}

func (r KubernetesClusterResource) upgradeSettingsConfig(data acceptance.TestData, maxSurge string) string {
if maxSurge != "" {
maxSurge = fmt.Sprintf(`upgrade_settings {
Expand Down
4 changes: 3 additions & 1 deletion website/docs/r/kubernetes_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ resource "azurerm_kubernetes_cluster" "example" {

* `role_based_access_control_enabled` (Optional) - Whether Role Based Access Control for the Kubernetes Cluster should be enabled. Defaults to `true`. Changing this forces a new resource to be created.

* `service_principal` - (Optional) A `service_principal` block as documented below. One of either `identity` or `service_principal` must be specified.
* `run_command_enabled` - (Optional) Whether to enable run command for the cluster or not. Defaults to `true`.

* `service_principal` - (Optional) A `service_principal` block as documented below. One of either `identity` or `service_principal` must be specified.

!> **Note:** A migration scenario from `service_principal` to `identity` is supported. When upgrading `service_principal` to `identity`, your cluster's control plane and addon pods will switch to use managed identity, but the kubelets will keep using your configured `service_principal` until you upgrade your Node Pool.

Expand Down