Skip to content

Commit

Permalink
Add kubernetes dashboard addon (hashicorp#464)
Browse files Browse the repository at this point in the history
* Update google.golang.org/api/container/v1

* Add support for kubernetes_dashboard addon

* Fix tab/spaces issue in string
  • Loading branch information
selmanj authored Oct 3, 2017
1 parent fa439a5 commit 475ddb1
Show file tree
Hide file tree
Showing 6 changed files with 1,675 additions and 1,298 deletions.
22 changes: 22 additions & 0 deletions google/resource_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,21 @@ func resourceContainerCluster() *schema.Resource {
},
},
},
"kubernetes_dashboard": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"disabled": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
},
},
},
},
},
},
},
Expand Down Expand Up @@ -380,6 +395,13 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
Disabled: addon["disabled"].(bool),
}
}

if v, ok := addonsConfig["kubernetes_dashboard"]; ok && len(v.([]interface{})) > 0 {
addon := v.([]interface{})[0].(map[string]interface{})
cluster.AddonsConfig.KubernetesDashboard = &container.KubernetesDashboard{
Disabled: addon["disabled"].(bool),
}
}
}
if v, ok := d.GetOk("node_config"); ok {
cluster.NodeConfig = expandNodeConfig(v)
Expand Down
64 changes: 53 additions & 11 deletions google/resource_container_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ func TestAccContainerCluster_withTimeout(t *testing.T) {
})
}

func TestAccContainerCluster_withAddons(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckContainerClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccContainerCluster_withAddons,
Check: resource.ComposeTestCheckFunc(
testAccCheckContainerCluster(
"google_container_cluster.primary"),
),
},
},
})
}
func TestAccContainerCluster_withMasterAuth(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down Expand Up @@ -462,15 +478,22 @@ func testAccCheckContainerCluster(n string) resource.TestCheckFunc {
}
clusterTests = append(clusterTests, clusterTestField{"additional_zones", additionalZones})

// AddonsConfig is neither Required or Computed, so the API may return nil for it
if cluster.AddonsConfig != nil {
if cluster.AddonsConfig.HttpLoadBalancing != nil {
clusterTests = append(clusterTests, clusterTestField{"addons_config.0.http_load_balancing.0.disabled", strconv.FormatBool(cluster.AddonsConfig.HttpLoadBalancing.Disabled)})
}
if cluster.AddonsConfig.HorizontalPodAutoscaling != nil {
clusterTests = append(clusterTests, clusterTestField{"addons_config.0.horizontal_pod_autoscaling.0.disabled", strconv.FormatBool(cluster.AddonsConfig.HorizontalPodAutoscaling.Disabled)})
}
// AddonsConfig is neither Required or Computed, so the API may return nil for it.
httpLoadBalancingDisabled := false
if cluster.AddonsConfig != nil && cluster.AddonsConfig.HttpLoadBalancing != nil {
httpLoadBalancingDisabled = cluster.AddonsConfig.HttpLoadBalancing.Disabled
}
horizontalPodAutoscalingDisabled := false
if cluster.AddonsConfig != nil && cluster.AddonsConfig.HorizontalPodAutoscaling != nil {
horizontalPodAutoscalingDisabled = cluster.AddonsConfig.HorizontalPodAutoscaling.Disabled
}
kubernetesDashboardDisabled := false
if cluster.AddonsConfig != nil && cluster.AddonsConfig.KubernetesDashboard != nil {
kubernetesDashboardDisabled = cluster.AddonsConfig.KubernetesDashboard.Disabled
}
clusterTests = append(clusterTests, clusterTestField{"addons_config.0.http_load_balancing.0.disabled", httpLoadBalancingDisabled})
clusterTests = append(clusterTests, clusterTestField{"addons_config.0.horizontal_pod_autoscaling.0.disabled", horizontalPodAutoscalingDisabled})
clusterTests = append(clusterTests, clusterTestField{"addons_config.0.kubernetes_dashboard.0.disabled", kubernetesDashboardDisabled})

for i, np := range cluster.NodePools {
prefix := fmt.Sprintf("node_pool.%d.", i)
Expand Down Expand Up @@ -608,10 +631,17 @@ func checkMapMatch(attributes map[string]string, attr string, gcpMap map[string]
}

func checkBoolMatch(attributes map[string]string, attr string, gcpBool bool) string {
tf, err := strconv.ParseBool(attributes[attr])
if err != nil {
return fmt.Sprintf("Error converting attribute %s to boolean: value is %s", attr, attributes[attr])
// Handle the case where an unset value defaults to false
var tf bool
if attributes[attr] == "" {
tf = false
} else {
tf, err = strconv.ParseBool(attributes[attr])
if err != nil {
return fmt.Sprintf("Error converting attribute %s to boolean: value is %s", attr, attributes[attr])
}
}

if tf != gcpBool {
return matchError(attr, tf, gcpBool)
}
Expand Down Expand Up @@ -645,6 +675,18 @@ resource "google_container_cluster" "primary" {
}
}`, acctest.RandString(10))

var testAccContainerCluster_withAddons = fmt.Sprintf(`
resource "google_container_cluster" "primary" {
name = "cluster-test-%s"
zone = "us-central1-a"
initial_node_count = 3
addons_config {
http_load_balancing { disabled = true }
kubernetes_dashboard { disabled = true }
}
}`, acctest.RandString(10))

var testAccContainerCluster_withMasterAuth = fmt.Sprintf(`
resource "google_container_cluster" "with_master_auth" {
name = "cluster-test-%s"
Expand Down
Loading

0 comments on commit 475ddb1

Please sign in to comment.