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

r/kubernetes_cluster: supporting conditional updates / introducing default_node_pool #4898

Merged
merged 45 commits into from
Nov 20, 2019
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
c15831e
r/kubernetes_cluster: documenting the new `enable_node_public_ip` field
tombuildsstuff Nov 5, 2019
cf947f8
r/kubernetes_cluster: conditionally updating the cluster if fields ha…
tombuildsstuff Nov 5, 2019
5f8b887
r/kubernetes_cluster: sorting the documentation
tombuildsstuff Nov 5, 2019
f3d22cc
r/kubernetes_cluster: switching to pass in the objects rather than th…
tombuildsstuff Nov 5, 2019
2e74e7d
r/kubernetes_cluster: inlining the `expandServicePrincipalProfile` me…
tombuildsstuff Nov 5, 2019
6814035
r/kubernetes_cluster: updating the versions of kubernetes being used
tombuildsstuff Nov 5, 2019
657aced
r/kubernetes_cluster: making the addon_profile elements computed but …
tombuildsstuff Nov 6, 2019
0f8d8eb
r/kubernetes_cluster: refactoring the addon helpers out
tombuildsstuff Nov 6, 2019
12283cf
r/kubernetes_cluster: making the top level addon_profile block computed
tombuildsstuff Nov 6, 2019
659816f
r/kubernetes_cluster: introducing a new block `default_node_pool`
tombuildsstuff Nov 6, 2019
ff62923
r/kubernetes_cluster: sending the count unless the users opted out
tombuildsstuff Nov 6, 2019
310c5f7
r/kubernetes_cluster: documenting the agent_pool_profile deprecation
tombuildsstuff Nov 6, 2019
3b305e9
r/kubernetes_cluster: splitting the tests out
tombuildsstuff Nov 6, 2019
7ca2fed
r/kubernetes_cluster: adding tests for the existing setup
tombuildsstuff Nov 6, 2019
437c90a
r/kubernetes_cluster: requiring that the default node pool is a linux…
tombuildsstuff Nov 7, 2019
1c4b011
r/kubernetes_cluster: updating the tests
tombuildsstuff Nov 7, 2019
398fe83
r/kubernetes_cluster: fixing up the networking related tests
tombuildsstuff Nov 7, 2019
1f55a45
r/kubernetes_cluster: updating the auth tests
tombuildsstuff Nov 7, 2019
b6e523b
r/kubernetes_cluster: updating the remaining tests
tombuildsstuff Nov 7, 2019
692f740
r/kubernetes_cluster: moving `windows_profile` further down
tombuildsstuff Nov 8, 2019
2ba3f1a
r/kubernetes_cluster: switching to use a common ID parsing method
tombuildsstuff Nov 8, 2019
7f398bf
d/kubernetes_cluster: fixing the tests
tombuildsstuff Nov 8, 2019
90c09fa
r/kubernetes_cluster: renaming `count` to `node_count`
tombuildsstuff Nov 8, 2019
d70b769
r/kubernetes_cluster: fixing the broken tests
tombuildsstuff Nov 8, 2019
1662813
r/kubernetes_cluster: testing updates for the `windows_profile` block
tombuildsstuff Nov 8, 2019
6037d55
r/kubernetes_cluster: adding a specific test for tags
tombuildsstuff Nov 11, 2019
412189c
r/kubernetes_cluster: fixing the agent type
tombuildsstuff Nov 11, 2019
22474d3
r/kubernetes_cluster: pulling the value for `node_count` from `min_co…
tombuildsstuff Nov 11, 2019
95e75e0
r/kubernetes_cluster: documenting the `default_node_pool` block
tombuildsstuff Nov 11, 2019
eb39af5
r/kubernetes_cluster: making `node_count` computed for autoscaled nodes
tombuildsstuff Nov 11, 2019
93cfd61
r/kubernetes_cluster: updating the default example
tombuildsstuff Nov 11, 2019
9fd7884
r/kubernetes_cluster: fixing the docs/updating the publicip test
tombuildsstuff Nov 12, 2019
89f418a
r/kubernetes_cluster: enabling AutoScaling for TestAccAzureRMKubernet…
tombuildsstuff Nov 13, 2019
d553166
r/kubernetes_cluster: correct syntax for TestAccAzureRMKubernetesClus…
tombuildsstuff Nov 13, 2019
f8b66e6
r/kubernetes_cluster: fixing the assertion for TestAccAzureRMKubernet…
tombuildsstuff Nov 13, 2019
3ede610
r/kubernetes_cluster: fixing tests
tombuildsstuff Nov 13, 2019
4c28b2e
r/kubernetes_cluster: updating the default node pool using the separa…
tombuildsstuff Nov 13, 2019
ae21a2b
r/kubernetes_cluster: fixing a bug where count changes weren't detected
tombuildsstuff Nov 19, 2019
9ef91d7
r/kubernetes_cluster: switching to use the value rather than keying in
tombuildsstuff Nov 20, 2019
b55a402
r/kubernetes_cluster: always submitting the value for `nodeTaints` an…
tombuildsstuff Nov 20, 2019
9d6e5e3
r/kubernetes_cluster: making the VM SKU case sensitive
tombuildsstuff Nov 20, 2019
3b98107
r/kubernetes_cluster: adding nil-check to sub-properties
tombuildsstuff Nov 20, 2019
82e6437
r/kubernetes_cluster: updating the tag to allow scheduling pods
tombuildsstuff Nov 20, 2019
bcefb73
r/kubernetes_cluster: conditionally setting `availability_zones`
tombuildsstuff Nov 20, 2019
d928e22
r/kubernetes_cluster: documentation fixes
tombuildsstuff Nov 20, 2019
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
4 changes: 2 additions & 2 deletions azurerm/data_source_kubernetes_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ func TestAccDataSourceAzureRMKubernetesCluster_enableNodePublicIP(t *testing.T)
}

func testAccDataSourceAzureRMKubernetesCluster_basic(rInt int, clientId string, clientSecret string, location string) string {
r := testAccAzureRMKubernetesCluster_basic(rInt, clientId, clientSecret, location)
r := testAccAzureRMKubernetesCluster_basicVMSS(rInt, clientId, clientSecret, location)
return fmt.Sprintf(`
%s

Expand Down Expand Up @@ -802,7 +802,7 @@ data "azurerm_kubernetes_cluster" "test" {
}

func testAccDataSourceAzureRMKubernetesCluster_enableNodePublicIP(rInt int, clientId string, clientSecret string, location string) string {
r := testAccAzureRMKubernetesCluster_enableNodePublicIP(rInt, clientId, clientSecret, location)
r := testAccAzureRMKubernetesCluster_enableNodePublicIP(rInt, clientId, clientSecret, location, true)
return fmt.Sprintf(`
%s

Expand Down
5 changes: 5 additions & 0 deletions azurerm/internal/services/containers/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)

type Client struct {
AgentPoolsClient *containerservice.AgentPoolsClient
KubernetesClustersClient *containerservice.ManagedClustersClient
GroupsClient *containerinstance.ContainerGroupsClient
RegistriesClient *containerregistry.RegistriesClient
Expand Down Expand Up @@ -37,7 +38,11 @@ func BuildClient(o *common.ClientOptions) *Client {
KubernetesClustersClient := containerservice.NewManagedClustersClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&KubernetesClustersClient.Client, o.ResourceManagerAuthorizer)

agentPoolsClient := containerservice.NewAgentPoolsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&agentPoolsClient.Client, o.ResourceManagerAuthorizer)

return &Client{
AgentPoolsClient: &agentPoolsClient,
KubernetesClustersClient: &KubernetesClustersClient,
GroupsClient: &GroupsClient,
RegistriesClient: &RegistriesClient,
Expand Down
297 changes: 297 additions & 0 deletions azurerm/internal/services/containers/kubernetes_addons.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,297 @@
package containers

import (
"github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2019-06-01/containerservice"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

const (
aciConnectorKey = "aciConnectorLinux"
azurePolicyKey = "azurepolicy"
kubernetesDashboardKey = "kubeDashboard"
httpApplicationRoutingKey = "httpApplicationRouting"
omsAgentKey = "omsagent"
)

func SchemaKubernetesAddOnProfiles() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"aci_connector_linux": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Required: true,
},

"subnet_name": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validate.NoEmptyStrings,
},
},
},
},

"azure_policy": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Required: true,
},
},
},
},

"kube_dashboard": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Required: true,
},
},
},
},

"http_application_routing": {
Type: schema.TypeList,
MaxItems: 1,
ForceNew: true,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
ForceNew: true,
Required: true,
},
"http_application_routing_zone_name": {
Type: schema.TypeString,
Computed: true,
},
},
},
},

"oms_agent": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Required: true,
},
"log_analytics_workspace_id": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: azure.ValidateResourceID,
},
},
},
},
},
},
}
}

func ExpandKubernetesAddOnProfiles(input []interface{}) map[string]*containerservice.ManagedClusterAddonProfile {
disabled := containerservice.ManagedClusterAddonProfile{
Enabled: utils.Bool(false),
}

profiles := map[string]*containerservice.ManagedClusterAddonProfile{
// note: the casing on these keys is important
aciConnectorKey: &disabled,
azurePolicyKey: &disabled,
kubernetesDashboardKey: &disabled,
httpApplicationRoutingKey: &disabled,
omsAgentKey: &disabled,
}
if len(input) == 0 {
return profiles
}

profile := input[0].(map[string]interface{})
addonProfiles := map[string]*containerservice.ManagedClusterAddonProfile{}

httpApplicationRouting := profile["http_application_routing"].([]interface{})
if len(httpApplicationRouting) > 0 {
value := httpApplicationRouting[0].(map[string]interface{})
tombuildsstuff marked this conversation as resolved.
Show resolved Hide resolved
enabled := value["enabled"].(bool)
addonProfiles["httpApplicationRouting"] = &containerservice.ManagedClusterAddonProfile{
Enabled: utils.Bool(enabled),
}
}

omsAgent := profile["oms_agent"].([]interface{})
if len(omsAgent) > 0 {
value := omsAgent[0].(map[string]interface{})
tombuildsstuff marked this conversation as resolved.
Show resolved Hide resolved
config := make(map[string]*string)
enabled := value["enabled"].(bool)

if workspaceId, ok := value["log_analytics_workspace_id"]; ok && workspaceId != "" {
config["logAnalyticsWorkspaceResourceID"] = utils.String(workspaceId.(string))
}

addonProfiles["omsagent"] = &containerservice.ManagedClusterAddonProfile{
Enabled: utils.Bool(enabled),
Config: config,
}
}

aciConnector := profile["aci_connector_linux"].([]interface{})
if len(aciConnector) > 0 {
value := aciConnector[0].(map[string]interface{})
tombuildsstuff marked this conversation as resolved.
Show resolved Hide resolved
config := make(map[string]*string)
enabled := value["enabled"].(bool)

if subnetName, ok := value["subnet_name"]; ok && subnetName != "" {
config["SubnetName"] = utils.String(subnetName.(string))
}

addonProfiles["aciConnectorLinux"] = &containerservice.ManagedClusterAddonProfile{
Enabled: utils.Bool(enabled),
Config: config,
}
}

kubeDashboard := profile["kube_dashboard"].([]interface{})
if len(kubeDashboard) > 0 {
value := kubeDashboard[0].(map[string]interface{})
tombuildsstuff marked this conversation as resolved.
Show resolved Hide resolved
enabled := value["enabled"].(bool)

addonProfiles["kubeDashboard"] = &containerservice.ManagedClusterAddonProfile{
Enabled: utils.Bool(enabled),
Config: nil,
}
}

azurePolicy := profile["azure_policy"].([]interface{})
if len(azurePolicy) > 0 && azurePolicy[0] != nil {
value := azurePolicy[0].(map[string]interface{})
enabled := value["enabled"].(bool)

addonProfiles["azurepolicy"] = &containerservice.ManagedClusterAddonProfile{
Enabled: utils.Bool(enabled),
Config: nil,
}
}

return addonProfiles
}

func FlattenKubernetesAddOnProfiles(profile map[string]*containerservice.ManagedClusterAddonProfile) []interface{} {
aciConnectors := make([]interface{}, 0)
if aciConnector := profile[aciConnectorKey]; aciConnector != nil {
enabled := false
if enabledVal := aciConnector.Enabled; enabledVal != nil {
enabled = *enabledVal
}

subnetName := ""
if v := aciConnector.Config["SubnetName"]; v != nil {
subnetName = *v
}

aciConnectors = append(aciConnectors, map[string]interface{}{
"enabled": enabled,
"subnet_name": subnetName,
})
}

azurePolicies := make([]interface{}, 0)
if azurePolicy := profile[azurePolicyKey]; azurePolicy != nil {
enabled := false
if enabledVal := azurePolicy.Enabled; enabledVal != nil {
enabled = *enabledVal
}

azurePolicies = append(azurePolicies, map[string]interface{}{
"enabled": enabled,
})
}

httpApplicationRoutes := make([]interface{}, 0)
if httpApplicationRouting := profile[httpApplicationRoutingKey]; httpApplicationRouting != nil {
enabled := false
if enabledVal := httpApplicationRouting.Enabled; enabledVal != nil {
enabled = *enabledVal
}

zoneName := ""
if v := httpApplicationRouting.Config["HTTPApplicationRoutingZoneName"]; v != nil {
zoneName = *v
}

httpApplicationRoutes = append(httpApplicationRoutes, map[string]interface{}{
"enabled": enabled,
"http_application_routing_zone_name": zoneName,
})
}

kubeDashboards := make([]interface{}, 0)
if kubeDashboard := profile[kubernetesDashboardKey]; kubeDashboard != nil {
enabled := false
if enabledVal := kubeDashboard.Enabled; enabledVal != nil {
enabled = *enabledVal
}

kubeDashboards = append(kubeDashboards, map[string]interface{}{
"enabled": enabled,
})
}

omsAgents := make([]interface{}, 0)
if omsAgent := profile[omsAgentKey]; omsAgent != nil {
enabled := false
if enabledVal := omsAgent.Enabled; enabledVal != nil {
enabled = *enabledVal
}

workspaceId := ""
if workspaceResourceID := omsAgent.Config["logAnalyticsWorkspaceResourceID"]; workspaceResourceID != nil {
workspaceId = *workspaceResourceID
}

omsAgents = append(omsAgents, map[string]interface{}{
"enabled": enabled,
"log_analytics_workspace_id": workspaceId,
})
}

// this is a UX hack, since if the top level block isn't defined everything should be turned off
if len(aciConnectors) == 0 && len(azurePolicies) == 0 && len(httpApplicationRoutes) == 0 && len(kubeDashboards) == 0 && len(omsAgents) == 0 {
return []interface{}{}
}

return []interface{}{
map[string]interface{}{
"aci_connector_linux": aciConnectors,
"azure_policy": azurePolicies,
"http_application_routing": httpApplicationRoutes,
"kube_dashboard": kubeDashboards,
"oms_agent": omsAgents,
},
}
}
Loading