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

AKS: Add-On Profiles #1751

Merged
merged 42 commits into from
Aug 14, 2018
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
5865322
Added kubernetes_cluster advanced network creation
lfshr Jul 2, 2018
305c1d0
Changed network_profile from TypeSet to TypeList
lfshr Jul 2, 2018
df237b2
Added kubernetes_cluster advanced network creation
lfshr Jul 2, 2018
e3ec37e
Changed network_profile from TypeSet to TypeList
lfshr Jul 2, 2018
a3ff5b0
Merge branch 'containerservices-advancednetworking' of https://github…
lfshr Jul 2, 2018
b7d274b
Updated ForceNew attributes on kubernetes_cluster.network_profile params
lfshr Jul 2, 2018
11bed67
Added advanced network read functionality
lfshr Jul 2, 2018
30f39ff
Added tests for kubernetes_cluster.network_profile
lfshr Jul 2, 2018
195e7d6
Fixed indentations
lfshr Jul 2, 2018
f8f5626
Fixed function name in tests
lfshr Jul 2, 2018
25c6e6e
Fixed property name in test
lfshr Jul 2, 2018
48cff90
Fixed variable name
lfshr Jul 3, 2018
2dd887c
working on data source for kubernetes cluster
lfshr Jul 3, 2018
1bdf8b6
Merge branch 'containerservices-advancednetworking' of https://github…
lfshr Jul 3, 2018
33c84c6
Fixed issue with datasource not working
lfshr Jul 3, 2018
f9786e1
Added network_policy and fixed read
lfshr Jul 3, 2018
02b22e5
Removed network_policy as unsupported
lfshr Jul 3, 2018
b62a643
Added example of advanced networking
lfshr Jul 4, 2018
377c52f
Added test for data_source
lfshr Jul 4, 2018
7453f41
Made address space more sensible
lfshr Jul 4, 2018
c90ea55
Removing kubenet test.
lfshr Jul 6, 2018
16e7d3e
Made network_plugin a mandatory field.
lfshr Jul 6, 2018
675d0b9
Updated documentation to include network_profile
lfshr Jul 6, 2018
7c21183
Fixing the build
tombuildsstuff Jul 6, 2018
1959c2f
Added ForceNew to network_profile
lfshr Jul 6, 2018
518cacc
Made the docs a little clearer
lfshr Jul 6, 2018
9faeb69
Documenting a required field
tombuildsstuff Jul 11, 2018
1ef6ccf
Rephrasing the data sources
tombuildsstuff Jul 11, 2018
dac7913
Making the `network_profile` block computed
tombuildsstuff Jul 11, 2018
48d5ed7
Fixing the field we're asserting on
tombuildsstuff Jul 11, 2018
a54aa89
Conditionally expanding the network_profile block.
tombuildsstuff Jul 25, 2018
9e862eb
Validation to ensure that a Subnet ID is assigned to the cluster when…
tombuildsstuff Jul 25, 2018
f2219c5
Updating the documentation to mention the new behaviour
tombuildsstuff Jul 25, 2018
8a23d24
Adding independent tests for Kubenet and Azure networking profiles
tombuildsstuff Jul 25, 2018
8d08c53
Conditional validation of the `docker_bridge_cidr`, `dns_service_ip` …
tombuildsstuff Jul 25, 2018
a72f105
Updating the docs
tombuildsstuff Jul 25, 2018
ff3e206
Fixing the tests
tombuildsstuff Jul 25, 2018
7d62f51
Merge branch 'master' into containerservices-advancednetworking
tombuildsstuff Aug 10, 2018
403bc1d
Adding back in the changes from PR #1502 since they were lost in the …
tombuildsstuff Aug 10, 2018
be893dc
Renaming the methods to `addonProfiles` to match the sdk
tombuildsstuff Aug 10, 2018
018a6db
fixing the quotes
tombuildsstuff Aug 13, 2018
3106ee1
Merge branch 'master' into containerservices-advancednetworking
tombuildsstuff Aug 14, 2018
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
104 changes: 98 additions & 6 deletions azurerm/data_source_kubernetes_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,48 @@ func dataSourceArmKubernetesCluster() *schema.Resource {
},
},

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

"oms_agent": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Computed: true,
},
"log_analytics_workspace_id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
},
},

"tags": tagsForDataSourceSchema(),
},
}
Expand Down Expand Up @@ -245,23 +287,27 @@ func dataSourceArmKubernetesClusterRead(d *schema.ResourceData, meta interface{}
return fmt.Errorf("Error setting `linux_profile`: %+v", err)
}

addonProfiles := flattenKubernetesClusterDataSourceAddonProfiles(props.AddonProfiles)
if err := d.Set("addon_profile", addonProfiles); err != nil {
return fmt.Errorf("Error setting `addon_profile`: %+v", err)
}

agentPoolProfiles := flattenKubernetesClusterDataSourceAgentPoolProfiles(props.AgentPoolProfiles)
if err := d.Set("agent_pool_profile", agentPoolProfiles); err != nil {
return fmt.Errorf("Error setting `agent_pool_profile`: %+v", err)
}

networkProfile := flattenKubernetesClusterDataSourceNetworkProfile(props.NetworkProfile)
if err := d.Set("network_profile", networkProfile); err != nil {
return fmt.Errorf("Error setting `network_profile`: %+v", err)
}

servicePrincipal := flattenKubernetesClusterDataSourceServicePrincipalProfile(resp.ManagedClusterProperties.ServicePrincipalProfile)
if err := d.Set("service_principal", servicePrincipal); err != nil {
return fmt.Errorf("Error setting `service_principal`: %+v", err)
}
}

networkProfile := flattenKubernetesClusterDataSourceNetworkProfile(resp.NetworkProfile)

if err := d.Set("network_profile", networkProfile); err != nil {
return fmt.Errorf("Error setting `network_profile`: %+v", err)
}

kubeConfigRaw, kubeConfig := flattenKubernetesClusterDataSourceAccessProfile(&profile)
d.Set("kube_config_raw", kubeConfigRaw)

Expand Down Expand Up @@ -419,3 +465,49 @@ func flattenKubernetesClusterDataSourceNetworkProfile(profile *containerservice.

return []interface{}{values}
}

func flattenKubernetesClusterDataSourceAddonProfiles(profile map[string]*containerservice.ManagedClusterAddonProfile) interface{} {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we just rename either this function or flattenAzureRmKubernetesClusterAddonProfiles and reuse it? It's exactly the same function with the same interface, just a different name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably - but historically this has caused us issues where the schema's diverged - so we're trying to avoid that

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I follow, how could it diverge if the output is coming from the exact same API call? If the API response is going to diverge, then both functions (as they're exactly the same except name) need fixing, AFAICT?

Copy link
Contributor Author

@tombuildsstuff tombuildsstuff Aug 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the schema being the Terraform schema here - since one is a Data Source and hence Computed (this one) vs the other being a Resource / not computed. We've had PR's in the past with folks adding items to each independently, which means there's a Set error when this happens - as such it appears preferable to dupe this logic?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, I see what do you mean 🤔That's tricky, yeah.

I wish we had a better way to reuse parts of schema between resources and data sources 😞

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this discussion -- this is something we can run into on AWS as well since we generally are pushing for separate schema definitions and read functions, but usually sharing the flatten functions. 🤔

values := make(map[string]interface{}, 0)

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

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

output := map[string]interface{}{
"enabled": enabled,
"http_application_routing_zone_name": zoneName,
}
routes = append(routes, output)
}
values["http_application_routing"] = routes

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

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

output := map[string]interface{}{
"enabled": enabled,
"log_analytics_workspace_id": workspaceId,
}
agents = append(agents, output)
}
values["oms_agent"] = agents

return []interface{}{values}
}
78 changes: 78 additions & 0 deletions azurerm/data_source_kubernetes_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,60 @@ func TestAccDataSourceAzureRMKubernetesCluster_advancedNetworkingKubenetComplete
})
}

func TestAccDataSourceAzureRMKubernetesCluster_addOnProfileOMS(t *testing.T) {
dataSourceName := "data.azurerm_kubernetes_cluster.test"
ri := acctest.RandInt()
clientId := os.Getenv("ARM_CLIENT_ID")
clientSecret := os.Getenv("ARM_CLIENT_SECRET")
location := testLocation()
config := testAccDataSourceAzureRMKubernetesCluster_addOnProfileOMS(ri, clientId, clientSecret, location)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMKubernetesClusterDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMKubernetesClusterExists(dataSourceName),
resource.TestCheckResourceAttr(dataSourceName, "addon_profile.#", "1"),
resource.TestCheckResourceAttr(dataSourceName, "addon_profile.0.oms_agent.#", "1"),
resource.TestCheckResourceAttr(dataSourceName, "addon_profile.0.oms_agent.0.enabled", "true"),
resource.TestCheckResourceAttrSet(dataSourceName, "addon_profile.0.oms_agent.0.log_analytics_workspace_id"),
),
},
},
})
}

func TestAccDataSourceAzureRMKubernetesCluster_addOnProfileRouting(t *testing.T) {
dataSourceName := "data.azurerm_kubernetes_cluster.test"
ri := acctest.RandInt()
clientId := os.Getenv("ARM_CLIENT_ID")
clientSecret := os.Getenv("ARM_CLIENT_SECRET")
location := testLocation()
config := testAccDataSourceAzureRMKubernetesCluster_addOnProfileRouting(ri, clientId, clientSecret, location)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMKubernetesClusterDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMKubernetesClusterExists(dataSourceName),
resource.TestCheckResourceAttr(dataSourceName, "addon_profile.#", "1"),
resource.TestCheckResourceAttr(dataSourceName, "addon_profile.0.http_application_routing.#", "1"),
resource.TestCheckResourceAttr(dataSourceName, "addon_profile.0.http_application_routing.0.enabled", "true"),
resource.TestCheckResourceAttrSet(dataSourceName, "addon_profile.0.http_application_routing.0.http_application_routing_zone_name"),
),
},
},
})
}

func testAccDataSourceAzureRMKubernetesCluster_basic(rInt int, clientId string, clientSecret string, location string) string {
resource := testAccAzureRMKubernetesCluster_basic(rInt, clientId, clientSecret, location)
return fmt.Sprintf(`
Expand Down Expand Up @@ -249,3 +303,27 @@ data "azurerm_kubernetes_cluster" "test" {
}
`, resource)
}

func testAccDataSourceAzureRMKubernetesCluster_addOnProfileOMS(rInt int, clientId string, clientSecret string, location string) string {
resource := testAccAzureRMKubernetesCluster_addonProfileOMS(rInt, clientId, clientSecret, location)
return fmt.Sprintf(`
%s

data "azurerm_kubernetes_cluster" "test" {
name = "${azurerm_kubernetes_cluster.test.name}"
resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}"
}
`, resource)
}

func testAccDataSourceAzureRMKubernetesCluster_addOnProfileRouting(rInt int, clientId string, clientSecret string, location string) string {
resource := testAccAzureRMKubernetesCluster_addonProfileRouting(rInt, clientId, clientSecret, location)
return fmt.Sprintf(`
%s

data "azurerm_kubernetes_cluster" "test" {
name = "${azurerm_kubernetes_cluster.test.name}"
resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}"
}
`, resource)
}
Loading