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 - kube_config and kube_admin_config blocks now marked entirely as Sensitive #15881

Merged
merged 2 commits into from
Mar 18, 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package containers_test

import (
"fmt"
"os"
"testing"

"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
Expand Down Expand Up @@ -210,32 +209,6 @@ func TestAccKubernetesCluster_roleBasedAccessControlAADUpdateToManaged(t *testin
})
}

func TestAccKubernetesCluster_roleBasedAccessControlAADUpdateToManagedSensitive(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test")
r := KubernetesClusterResource{}
clientData := data.Client()
auth := clientData.Default

os.Setenv("ARM_AKS_KUBE_CONFIGS_SENSITIVE", "true")

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.roleBasedAccessControlAADConfig(data, auth.ClientID, auth.ClientSecret, ""),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(rbacServerAppSecret()...),
{
Config: r.roleBasedAccessControlAADManagedConfig(data, ""),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(rbacServerAppSecret()...),
})
}

func TestAccKubernetesCluster_roleBasedAccessControlAADManaged(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test")
r := KubernetesClusterResource{}
Expand Down
50 changes: 30 additions & 20 deletions internal/services/containers/kubernetes_cluster_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,35 +418,40 @@ func dataSourceKubernetesCluster() *pluginsdk.Resource {
},

"kube_admin_config": {
Type: pluginsdk.TypeList,
Computed: true,
Type: pluginsdk.TypeList,
Computed: true,
Sensitive: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"host": {
Type: pluginsdk.TypeString,
Computed: true,
Type: pluginsdk.TypeString,
Computed: true,
Sensitive: true,
},
"username": {
Type: pluginsdk.TypeString,
Computed: true,
Type: pluginsdk.TypeString,
Computed: true,
Sensitive: true,
},
"password": {
Type: pluginsdk.TypeString,
Computed: true,
Sensitive: true,
},
"client_certificate": {
Type: pluginsdk.TypeString,
Computed: true,
Type: pluginsdk.TypeString,
Computed: true,
Sensitive: true,
},
"client_key": {
Type: pluginsdk.TypeString,
Computed: true,
Sensitive: true,
},
"cluster_ca_certificate": {
Type: pluginsdk.TypeString,
Computed: true,
Type: pluginsdk.TypeString,
Computed: true,
Sensitive: true,
},
},
},
Expand All @@ -459,35 +464,40 @@ func dataSourceKubernetesCluster() *pluginsdk.Resource {
},

"kube_config": {
Type: pluginsdk.TypeList,
Computed: true,
Type: pluginsdk.TypeList,
Computed: true,
Sensitive: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"host": {
Type: pluginsdk.TypeString,
Computed: true,
Type: pluginsdk.TypeString,
Computed: true,
Sensitive: true,
},
"username": {
Type: pluginsdk.TypeString,
Computed: true,
Type: pluginsdk.TypeString,
Computed: true,
Sensitive: true,
},
"password": {
Type: pluginsdk.TypeString,
Computed: true,
Sensitive: true,
},
"client_certificate": {
Type: pluginsdk.TypeString,
Computed: true,
Type: pluginsdk.TypeString,
Computed: true,
Sensitive: true,
},
"client_key": {
Type: pluginsdk.TypeString,
Computed: true,
Sensitive: true,
},
"cluster_ca_certificate": {
Type: pluginsdk.TypeString,
Computed: true,
Type: pluginsdk.TypeString,
Computed: true,
Sensitive: true,
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package containers_test

import (
"fmt"
"os"
"strings"
"testing"

Expand All @@ -27,23 +26,6 @@ func TestAccKubernetesCluster_basicAvailabilitySet(t *testing.T) {
})
}

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

os.Setenv("ARM_AKS_KUBE_CONFIGS_SENSITIVE", "true")

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

func TestAccKubernetesCluster_sameSizeVMSSConfig(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test")
r := KubernetesClusterResource{}
Expand Down
112 changes: 18 additions & 94 deletions internal/services/containers/kubernetes_cluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -886,17 +886,20 @@ func resourceKubernetesCluster() *pluginsdk.Resource {
},

"kube_admin_config": {
Type: pluginsdk.TypeList,
Computed: true,
Type: pluginsdk.TypeList,
Computed: true,
Sensitive: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"host": {
Type: pluginsdk.TypeString,
Computed: true,
Type: pluginsdk.TypeString,
Computed: true,
Sensitive: true,
},
"username": {
Type: pluginsdk.TypeString,
Computed: true,
Type: pluginsdk.TypeString,
Computed: true,
Sensitive: true,
},
"password": {
Type: pluginsdk.TypeString,
Expand Down Expand Up @@ -929,17 +932,20 @@ func resourceKubernetesCluster() *pluginsdk.Resource {
},

"kube_config": {
Type: pluginsdk.TypeList,
Computed: true,
Type: pluginsdk.TypeList,
Computed: true,
Sensitive: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"host": {
Type: pluginsdk.TypeString,
Computed: true,
Type: pluginsdk.TypeString,
Computed: true,
Sensitive: true,
},
"username": {
Type: pluginsdk.TypeString,
Computed: true,
Type: pluginsdk.TypeString,
Computed: true,
Sensitive: true,
},
"password": {
Type: pluginsdk.TypeString,
Expand Down Expand Up @@ -1011,88 +1017,6 @@ func resourceKubernetesCluster() *pluginsdk.Resource {
resource.Schema[k] = v
}

if features.ThreePointOhBeta() {
resource.Schema["kube_config"] = &pluginsdk.Schema{
Type: pluginsdk.TypeList,
Computed: true,
Sensitive: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"host": {
Type: pluginsdk.TypeString,
Computed: true,
Sensitive: true,
},
"username": {
Type: pluginsdk.TypeString,
Computed: true,
Sensitive: true,
},
"password": {
Type: pluginsdk.TypeString,
Computed: true,
Sensitive: true,
},
"client_certificate": {
Type: pluginsdk.TypeString,
Computed: true,
Sensitive: true,
},
"client_key": {
Type: pluginsdk.TypeString,
Computed: true,
Sensitive: true,
},
"cluster_ca_certificate": {
Type: pluginsdk.TypeString,
Computed: true,
Sensitive: true,
},
},
},
}

resource.Schema["kube_admin_config"] = &pluginsdk.Schema{
Type: pluginsdk.TypeList,
Computed: true,
Sensitive: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"host": {
Type: pluginsdk.TypeString,
Computed: true,
Sensitive: true,
},
"username": {
Type: pluginsdk.TypeString,
Computed: true,
Sensitive: true,
},
"password": {
Type: pluginsdk.TypeString,
Computed: true,
Sensitive: true,
},
"client_certificate": {
Type: pluginsdk.TypeString,
Computed: true,
Sensitive: true,
},
"client_key": {
Type: pluginsdk.TypeString,
Computed: true,
Sensitive: true,
},
"cluster_ca_certificate": {
Type: pluginsdk.TypeString,
Computed: true,
Sensitive: true,
},
},
},
}
}

if !features.ThreePointOhBeta() {
resource.Schema["private_link_enabled"] = &pluginsdk.Schema{
Type: pluginsdk.TypeBool,
Expand Down
4 changes: 0 additions & 4 deletions website/docs/r/kubernetes_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -699,14 +699,10 @@ The following attributes are exported:

* `kube_admin_config` - A `kube_admin_config` block as defined below. This is only available when Role Based Access Control with Azure Active Directory is enabled and local accounts enabled.

~> **Note:** To mark the whole of `kube_admin_config` as Sensitive in State, set the environment variable `ARM_AKS_KUBE_CONFIGS_SENSITIVE` to `true`. Any values from this block used in `outputs` will then also need to be marked as sensitive.

* `kube_admin_config_raw` - Raw Kubernetes config for the admin account to be used by [kubectl](https://kubernetes.io/docs/reference/kubectl/overview/) and other compatible tools. This is only available when Role Based Access Control with Azure Active Directory is enabled and local accounts enabled.

* `kube_config` - A `kube_config` block as defined below.

~> **Note:** To mark the whole of `kube_config` as Sensitive in State, set the environment variable `ARM_AKS_KUBE_CONFIGS_SENSITIVE` to `true`. Any values from this block used in `outputs` will then also need to be marked as sensitive.

* `kube_config_raw` - Raw Kubernetes config to be used by [kubectl](https://kubernetes.io/docs/reference/kubectl/overview/) and other compatible tools.

* `http_application_routing_zone_name` - The Zone Name of the HTTP Application Routing.
Expand Down