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 ability to delete the default node pool #1245

Merged
merged 1 commit into from
Mar 23, 2018
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
28 changes: 28 additions & 0 deletions google/resource_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"
"time"

"github.com/hashicorp/errwrap"
"github.com/hashicorp/go-version"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
Expand Down Expand Up @@ -421,6 +422,11 @@ func resourceContainerCluster() *schema.Resource {
},
},
},

"remove_default_node_pool": {
Type: schema.TypeBool,
Optional: true,
},
},
}
}
Expand Down Expand Up @@ -616,6 +622,17 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er

log.Printf("[INFO] GKE cluster %s has been created", clusterName)

if d.Get("remove_default_node_pool").(bool) {
op, err := config.clientContainer.Projects.Zones.Clusters.NodePools.Delete(project, zoneName, clusterName, "default-pool").Do()
if err != nil {
return errwrap.Wrapf("Error deleting default node pool: {{err}}", err)
}
err = containerSharedOperationWait(config, op, project, zoneName, "removing default node pool", timeoutInMinutes, 3)
if err != nil {
return errwrap.Wrapf("Error deleting default node pool: {{err}}", err)
}
}

return resourceContainerClusterRead(d, meta)
}

Expand Down Expand Up @@ -1108,6 +1125,17 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
d.SetPartial("logging_service")
}

if d.HasChange("remove_default_node_pool") && d.Get("remove_default_node_pool").(bool) {
op, err := config.clientContainer.Projects.Zones.Clusters.NodePools.Delete(project, zoneName, clusterName, "default-pool").Do()
if err != nil {
return errwrap.Wrapf("Error deleting default node pool: {{err}}", err)
}
err = containerSharedOperationWait(config, op, project, zoneName, "removing default node pool", timeoutInMinutes, 3)
if err != nil {
return errwrap.Wrapf("Error deleting default node pool: {{err}}", err)
}
}

d.Partial(false)

return resourceContainerClusterRead(d, meta)
Expand Down
76 changes: 60 additions & 16 deletions google/resource_container_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,11 @@ func TestAccContainerCluster_withNetworkPolicyEnabled(t *testing.T) {
),
},
{
ResourceName: "google_container_cluster.with_network_policy_enabled",
ImportStateIdPrefix: "us-central1-a/",
ImportState: true,
ImportStateVerify: true,
ResourceName: "google_container_cluster.with_network_policy_enabled",
ImportStateIdPrefix: "us-central1-a/",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"remove_default_node_pool"},
},
{
Config: testAccContainerCluster_removeNetworkPolicy(clusterName),
Expand All @@ -150,10 +151,11 @@ func TestAccContainerCluster_withNetworkPolicyEnabled(t *testing.T) {
),
},
{
ResourceName: "google_container_cluster.with_network_policy_enabled",
ImportStateIdPrefix: "us-central1-a/",
ImportState: true,
ImportStateVerify: true,
ResourceName: "google_container_cluster.with_network_policy_enabled",
ImportStateIdPrefix: "us-central1-a/",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"remove_default_node_pool"},
},
{
Config: testAccContainerCluster_withNetworkPolicyDisabled(clusterName),
Expand All @@ -163,10 +165,11 @@ func TestAccContainerCluster_withNetworkPolicyEnabled(t *testing.T) {
),
},
{
ResourceName: "google_container_cluster.with_network_policy_enabled",
ImportStateIdPrefix: "us-central1-a/",
ImportState: true,
ImportStateVerify: true,
ResourceName: "google_container_cluster.with_network_policy_enabled",
ImportStateIdPrefix: "us-central1-a/",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"remove_default_node_pool"},
},
{
Config: testAccContainerCluster_withNetworkPolicyConfigDisabled(clusterName),
Expand All @@ -176,10 +179,11 @@ func TestAccContainerCluster_withNetworkPolicyEnabled(t *testing.T) {
),
},
{
ResourceName: "google_container_cluster.with_network_policy_enabled",
ImportStateIdPrefix: "us-central1-a/",
ImportState: true,
ImportStateVerify: true,
ResourceName: "google_container_cluster.with_network_policy_enabled",
ImportStateIdPrefix: "us-central1-a/",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"remove_default_node_pool"},
},
{
Config: testAccContainerCluster_withNetworkPolicyConfigDisabled(clusterName),
Expand Down Expand Up @@ -787,6 +791,30 @@ func TestAccContainerCluster_withNodePoolNodeConfig(t *testing.T) {
})
}

func TestAccContainerCluster_withDefaultNodePoolRemoved(t *testing.T) {
t.Parallel()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckContainerClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccContainerCluster_withDefaultNodePoolRemoved(),
Check: resource.TestCheckResourceAttr(
"google_container_cluster.with_default_node_pool_removed", "node_pool.#", "0"),
},
{
ResourceName: "google_container_cluster.with_default_node_pool_removed",
ImportStateIdPrefix: "us-central1-a/",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"remove_default_node_pool"},
},
},
})
}

func TestAccContainerCluster_withMaintenanceWindow(t *testing.T) {
t.Parallel()
clusterName := acctest.RandString(10)
Expand Down Expand Up @@ -1100,6 +1128,7 @@ resource "google_container_cluster" "with_network_policy_enabled" {
name = "%s"
zone = "us-central1-a"
initial_node_count = 1
remove_default_node_pool = true

network_policy {
enabled = true
Expand All @@ -1119,6 +1148,7 @@ resource "google_container_cluster" "with_network_policy_enabled" {
name = "%s"
zone = "us-central1-a"
initial_node_count = 1
remove_default_node_pool = true
}`, clusterName)
}

Expand All @@ -1128,6 +1158,7 @@ resource "google_container_cluster" "with_network_policy_enabled" {
name = "%s"
zone = "us-central1-a"
initial_node_count = 1
remove_default_node_pool = true

network_policy = {}
}`, clusterName)
Expand All @@ -1139,6 +1170,7 @@ resource "google_container_cluster" "with_network_policy_enabled" {
name = "%s"
zone = "us-central1-a"
initial_node_count = 1
remove_default_node_pool = true

network_policy = {}
addons_config {
Expand Down Expand Up @@ -1632,6 +1664,18 @@ resource "google_container_cluster" "with_node_pool_node_config" {
`, testId, testId)
}

func testAccContainerCluster_withDefaultNodePoolRemoved() string {
return fmt.Sprintf(`
resource "google_container_cluster" "with_default_node_pool_removed" {
name = "cluster-test-%s"
zone = "us-central1-a"
initial_node_count = 1

remove_default_node_pool = true
}
`, acctest.RandString(10))
}

func testAccContainerCluster_withMaintenanceWindow(clusterName string, startTime string) string {
maintenancePolicy := ""
if len(startTime) > 0 {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/container_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ output "cluster_ca_certificate" {
* `project` - (Optional) The ID of the project in which the resource belongs. If it
is not provided, the provider project is used.

* `remove_default_node_pool` - (Optional) If true, deletes the default node pool upon cluster creation.

* `subnetwork` - (Optional) The name of the Google Compute Engine subnetwork in
which the cluster's instances are launched.

Expand Down