2015-07-05 16:39:01 +00:00
|
|
|
package google
|
|
|
|
|
|
|
|
import (
|
2017-11-02 17:38:20 +00:00
|
|
|
"bytes"
|
2015-07-05 16:39:01 +00:00
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2017-03-07 05:14:32 +00:00
|
|
|
"strconv"
|
|
|
|
|
2016-01-05 21:47:10 +00:00
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
2015-07-05 16:39:01 +00:00
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAccContainerCluster_basic(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2018-02-01 18:25:12 +00:00
|
|
|
clusterName := fmt.Sprintf("cluster-test-%s", acctest.RandString(10))
|
2015-07-05 16:39:01 +00:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2017-06-28 08:34:20 +00:00
|
|
|
{
|
2018-02-01 18:25:12 +00:00
|
|
|
Config: testAccContainerCluster_basic(clusterName),
|
2018-03-16 00:08:39 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.primary",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
2015-07-05 16:39:01 +00:00
|
|
|
},
|
2018-04-03 20:39:28 +00:00
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.primary",
|
|
|
|
ImportStateIdPrefix: fmt.Sprintf("%s/us-central1-a/", getTestProjectFromEnv()),
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2015-07-05 16:39:01 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-06-28 08:34:20 +00:00
|
|
|
func TestAccContainerCluster_withTimeout(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-06-28 08:34:20 +00:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
2017-11-28 00:32:00 +00:00
|
|
|
Config: testAccContainerCluster_withTimeout(),
|
2018-03-16 00:08:39 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.primary",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
2017-06-28 08:34:20 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-10-03 16:29:27 +00:00
|
|
|
func TestAccContainerCluster_withAddons(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-10-20 16:47:07 +00:00
|
|
|
clusterName := fmt.Sprintf("cluster-test-%s", acctest.RandString(10))
|
|
|
|
|
2017-10-03 16:29:27 +00:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
2017-10-20 16:47:07 +00:00
|
|
|
Config: testAccContainerCluster_withAddons(clusterName),
|
2017-10-03 16:29:27 +00:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
2017-10-20 16:47:07 +00:00
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.primary", "addons_config.0.http_load_balancing.0.disabled", "true"),
|
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.primary", "addons_config.0.kubernetes_dashboard.0.disabled", "true"),
|
|
|
|
),
|
|
|
|
},
|
2018-03-16 00:08:39 +00:00
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.primary",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2017-10-20 16:47:07 +00:00
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_updateAddons(clusterName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.primary", "addons_config.0.horizontal_pod_autoscaling.0.disabled", "true"),
|
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.primary", "addons_config.0.http_load_balancing.0.disabled", "false"),
|
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.primary", "addons_config.0.kubernetes_dashboard.0.disabled", "true"),
|
2017-10-03 16:29:27 +00:00
|
|
|
),
|
|
|
|
},
|
2018-03-16 00:08:39 +00:00
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.primary",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2017-10-03 16:29:27 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2017-10-20 16:47:07 +00:00
|
|
|
|
2018-04-28 01:06:26 +00:00
|
|
|
func TestAccContainerCluster_withMasterAuthConfig(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2018-08-15 19:50:17 +00:00
|
|
|
clusterName := fmt.Sprintf("cluster-test-%s", acctest.RandString(10))
|
|
|
|
|
2017-05-31 19:43:31 +00:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2017-06-28 08:34:20 +00:00
|
|
|
{
|
2018-08-15 19:50:17 +00:00
|
|
|
Config: testAccContainerCluster_withMasterAuth(clusterName),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_master_auth",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_updateMasterAuth(clusterName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.with_master_auth", "master_auth.0.username", "mr.yoda.adoy.mr"),
|
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.with_master_auth", "master_auth.0.password", "adoy.rm.123456789.mr.yoda"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_master_auth",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_disableMasterAuth(clusterName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.with_master_auth", "master_auth.0.username", ""),
|
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.with_master_auth", "master_auth.0.password", ""),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_master_auth",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_updateMasterAuth(clusterName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.with_master_auth", "master_auth.0.username", "mr.yoda.adoy.mr"),
|
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.with_master_auth", "master_auth.0.password", "adoy.rm.123456789.mr.yoda"),
|
|
|
|
),
|
2018-03-16 00:08:39 +00:00
|
|
|
},
|
2018-04-28 01:06:26 +00:00
|
|
|
{
|
2018-03-16 00:08:39 +00:00
|
|
|
ResourceName: "google_container_cluster.with_master_auth",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
2017-05-31 19:43:31 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-04-28 01:06:26 +00:00
|
|
|
func TestAccContainerCluster_withMasterAuthConfig_NoCert(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_withMasterAuthNoCert(),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.with_master_auth_no_cert", "master_auth.0.client_certificate", ""),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_master_auth_no_cert",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-11-27 20:40:07 +00:00
|
|
|
func TestAccContainerCluster_withNetworkPolicyEnabled(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
clusterName := fmt.Sprintf("cluster-test-%s", acctest.RandString(10))
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_withNetworkPolicyEnabled(clusterName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.with_network_policy_enabled",
|
|
|
|
"network_policy.#", "1"),
|
|
|
|
),
|
|
|
|
},
|
2018-03-16 00:08:39 +00:00
|
|
|
{
|
2018-03-23 00:22:44 +00:00
|
|
|
ResourceName: "google_container_cluster.with_network_policy_enabled",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
ImportStateVerifyIgnore: []string{"remove_default_node_pool"},
|
2018-03-16 00:08:39 +00:00
|
|
|
},
|
2017-11-27 20:40:07 +00:00
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_removeNetworkPolicy(clusterName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckNoResourceAttr("google_container_cluster.with_network_policy_enabled",
|
|
|
|
"network_policy"),
|
|
|
|
),
|
|
|
|
},
|
2018-03-16 00:08:39 +00:00
|
|
|
{
|
2018-03-23 00:22:44 +00:00
|
|
|
ResourceName: "google_container_cluster.with_network_policy_enabled",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
ImportStateVerifyIgnore: []string{"remove_default_node_pool"},
|
2018-03-16 00:08:39 +00:00
|
|
|
},
|
2018-02-01 18:25:12 +00:00
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_withNetworkPolicyDisabled(clusterName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.with_network_policy_enabled",
|
|
|
|
"network_policy.0.enabled", "false"),
|
|
|
|
),
|
|
|
|
},
|
2018-03-16 00:08:39 +00:00
|
|
|
{
|
2018-03-23 00:22:44 +00:00
|
|
|
ResourceName: "google_container_cluster.with_network_policy_enabled",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
ImportStateVerifyIgnore: []string{"remove_default_node_pool"},
|
2018-03-16 00:08:39 +00:00
|
|
|
},
|
2018-02-01 18:25:12 +00:00
|
|
|
{
|
2018-03-15 21:50:24 +00:00
|
|
|
Config: testAccContainerCluster_withNetworkPolicyConfigDisabled(clusterName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.with_network_policy_enabled",
|
|
|
|
"addons_config.0.network_policy_config.0.disabled", "true"),
|
|
|
|
),
|
|
|
|
},
|
2018-03-16 00:08:39 +00:00
|
|
|
{
|
2018-03-23 00:22:44 +00:00
|
|
|
ResourceName: "google_container_cluster.with_network_policy_enabled",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
ImportStateVerifyIgnore: []string{"remove_default_node_pool"},
|
2018-03-16 00:08:39 +00:00
|
|
|
},
|
2018-03-15 21:50:24 +00:00
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_withNetworkPolicyConfigDisabled(clusterName),
|
2018-02-01 18:25:12 +00:00
|
|
|
PlanOnly: true,
|
|
|
|
ExpectNonEmptyPlan: false,
|
|
|
|
},
|
2017-11-27 20:40:07 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-11-02 17:38:20 +00:00
|
|
|
func TestAccContainerCluster_withMasterAuthorizedNetworksConfig(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
clusterName := fmt.Sprintf("cluster-test-%s", acctest.RandString(10))
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
Fix panic on empty list for authorized masters' `cidr_blocks` (#1904)
* test empty authorized masters' cidr_blocks
When the `cidr_block` isn't simply blank but contains an empty list as in
```
master_authorized_networks_config {
cidr_blocks = []
}
```
a panic occurs looking something like
```
goroutine 26 [running]:
github.com/terraform-providers/terraform-provider-google/google.expandMasterAuthorizedNetworksConfig(0x15a4f80, 0xc4202586e0, 0x21)
/tmp/GOPATH/src/github.com/terraform-providers/terraform-provider-google/google/resource_container_cluster.go:1355 +0x4f2
github.com/terraform-providers/terraform-provider-google/google.resourceContainerClusterCreate(0xc420146a80, 0x16b1800, 0xc4200b8000, 0x0, 0x0)
/tmp/GOPATH/src/github.com/terraform-providers/terraform-provider-google/google/resource_container_cluster.go:520 +0x2848
github.com/terraform-providers/terraform-provider-google/vendor/github.com/hashicorp/terraform/helper/schema.(*Resource).Apply(0xc420495490, 0xc420341310, 0xc4202582c0, 0x16b1800, 0xc4200b8000, 0x1, 0xc42024eae0, 0xc4201e3650)
/tmp/GOPATH/src/github.com/terraform-providers/terraform-provider-google/vendor/github.com/hashicorp/terraform/helper/schema/resource.go:227 +0x364
github.com/terraform-providers/terraform-provider-google/vendor/github.com/hashicorp/terraform/helper/schema.(*Provider).Apply(0xc4204c6700, 0xc4203412c0, 0xc420341310, 0xc4202582c0, 0x14ee1441a000, 0x0, 0x18)
/tmp/GOPATH/src/github.com/terraform-providers/terraform-provider-google/vendor/github.com/hashicorp/terraform/helper/schema/provider.go:283 +0xa4
github.com/terraform-providers/terraform-provider-google/vendor/github.com/hashicorp/terraform/plugin.(*ResourceProviderServer).Apply(0xc4202d7c40, 0xc42035de80, 0xc42025c160, 0x0, 0x0)
/tmp/GOPATH/src/github.com/terraform-providers/terraform-provider-google/vendor/github.com/hashicorp/terraform/plugin/resource_provider.go:527 +0x57
reflect.Value.call(0xc4203feae0, 0xc42000e038, 0x13, 0x19e88a8, 0x4, 0xc42015ff20, 0x3, 0x3, 0xc420047ee8, 0xc4204c6798, ...)
/usr/local/go/src/reflect/value.go:434 +0x905
reflect.Value.Call(0xc4203feae0, 0xc42000e038, 0x13, 0xc420047f20, 0x3, 0x3, 0xc400000001, 0x0, 0x0)
/usr/local/go/src/reflect/value.go:302 +0xa4
net/rpc.(*service).call(0xc420418600, 0xc42007c140, 0xc42001e798, 0xc4200c4000, 0xc4202d6c40, 0x1557f80, 0xc42035de80, 0x16, 0x1557fc0, 0xc42025c160, ...)
/usr/local/go/src/net/rpc/server.go:381 +0x142
created by net/rpc.(*Server).ServeCodec
/usr/local/go/src/net/rpc/server.go:475 +0x36b
```
which we trigger by altering the first step to contain the HCL notation
for an empty list instead of simply an empty string.
In order to accomplish this, the tests had to be modified to accept an
emptyValue string as well which contains the content of the
`emptyValue` string when the cidrBlocks array is empty. This maintains
the old behavior of the original tests when `emptyValue` is an empty
string, while also facilating differing behavior for the new testcase by
setting `emptyValue` to whichever string we want to test instead. I
don't think this is very clean, but I guess it's pragmatic enough.
I'll hear if this is a thorn in the side to someone :smirk:.
* avoid panic on cidr_block type assertion
This is basically the fix. Since the value can be nil, we want to ensure
we handle a failure during the assertion since we know that asserting
`nil` conforms to `map[string]interface{}` will cause a run-time panic.
* flatten to config on empty list for cidr_blocks
since an empty list for cidrBlocks constitutes valid input, one should
return a map containing an empty list for the cidr_blocks field instead
of a nil value.
The nil value is only appropriate when the input Config is also nil.
2018-08-21 02:29:37 +00:00
|
|
|
Config: testAccContainerCluster_withMasterAuthorizedNetworksConfig(clusterName, []string{}, "cidr_blocks = []"),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.with_master_authorized_networks",
|
|
|
|
"master_authorized_networks_config.#", "1"),
|
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.with_master_authorized_networks",
|
|
|
|
"master_authorized_networks_config.0.cidr_blocks.#", "0"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_withMasterAuthorizedNetworksConfig(clusterName, []string{"8.8.8.8/32"}, ""),
|
2017-11-02 17:38:20 +00:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.with_master_authorized_networks",
|
|
|
|
"master_authorized_networks_config.0.cidr_blocks.#", "1"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
2018-03-01 21:19:18 +00:00
|
|
|
ResourceName: "google_container_cluster.with_master_authorized_networks",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
},
|
|
|
|
{
|
Fix panic on empty list for authorized masters' `cidr_blocks` (#1904)
* test empty authorized masters' cidr_blocks
When the `cidr_block` isn't simply blank but contains an empty list as in
```
master_authorized_networks_config {
cidr_blocks = []
}
```
a panic occurs looking something like
```
goroutine 26 [running]:
github.com/terraform-providers/terraform-provider-google/google.expandMasterAuthorizedNetworksConfig(0x15a4f80, 0xc4202586e0, 0x21)
/tmp/GOPATH/src/github.com/terraform-providers/terraform-provider-google/google/resource_container_cluster.go:1355 +0x4f2
github.com/terraform-providers/terraform-provider-google/google.resourceContainerClusterCreate(0xc420146a80, 0x16b1800, 0xc4200b8000, 0x0, 0x0)
/tmp/GOPATH/src/github.com/terraform-providers/terraform-provider-google/google/resource_container_cluster.go:520 +0x2848
github.com/terraform-providers/terraform-provider-google/vendor/github.com/hashicorp/terraform/helper/schema.(*Resource).Apply(0xc420495490, 0xc420341310, 0xc4202582c0, 0x16b1800, 0xc4200b8000, 0x1, 0xc42024eae0, 0xc4201e3650)
/tmp/GOPATH/src/github.com/terraform-providers/terraform-provider-google/vendor/github.com/hashicorp/terraform/helper/schema/resource.go:227 +0x364
github.com/terraform-providers/terraform-provider-google/vendor/github.com/hashicorp/terraform/helper/schema.(*Provider).Apply(0xc4204c6700, 0xc4203412c0, 0xc420341310, 0xc4202582c0, 0x14ee1441a000, 0x0, 0x18)
/tmp/GOPATH/src/github.com/terraform-providers/terraform-provider-google/vendor/github.com/hashicorp/terraform/helper/schema/provider.go:283 +0xa4
github.com/terraform-providers/terraform-provider-google/vendor/github.com/hashicorp/terraform/plugin.(*ResourceProviderServer).Apply(0xc4202d7c40, 0xc42035de80, 0xc42025c160, 0x0, 0x0)
/tmp/GOPATH/src/github.com/terraform-providers/terraform-provider-google/vendor/github.com/hashicorp/terraform/plugin/resource_provider.go:527 +0x57
reflect.Value.call(0xc4203feae0, 0xc42000e038, 0x13, 0x19e88a8, 0x4, 0xc42015ff20, 0x3, 0x3, 0xc420047ee8, 0xc4204c6798, ...)
/usr/local/go/src/reflect/value.go:434 +0x905
reflect.Value.Call(0xc4203feae0, 0xc42000e038, 0x13, 0xc420047f20, 0x3, 0x3, 0xc400000001, 0x0, 0x0)
/usr/local/go/src/reflect/value.go:302 +0xa4
net/rpc.(*service).call(0xc420418600, 0xc42007c140, 0xc42001e798, 0xc4200c4000, 0xc4202d6c40, 0x1557f80, 0xc42035de80, 0x16, 0x1557fc0, 0xc42025c160, ...)
/usr/local/go/src/net/rpc/server.go:381 +0x142
created by net/rpc.(*Server).ServeCodec
/usr/local/go/src/net/rpc/server.go:475 +0x36b
```
which we trigger by altering the first step to contain the HCL notation
for an empty list instead of simply an empty string.
In order to accomplish this, the tests had to be modified to accept an
emptyValue string as well which contains the content of the
`emptyValue` string when the cidrBlocks array is empty. This maintains
the old behavior of the original tests when `emptyValue` is an empty
string, while also facilating differing behavior for the new testcase by
setting `emptyValue` to whichever string we want to test instead. I
don't think this is very clean, but I guess it's pragmatic enough.
I'll hear if this is a thorn in the side to someone :smirk:.
* avoid panic on cidr_block type assertion
This is basically the fix. Since the value can be nil, we want to ensure
we handle a failure during the assertion since we know that asserting
`nil` conforms to `map[string]interface{}` will cause a run-time panic.
* flatten to config on empty list for cidr_blocks
since an empty list for cidrBlocks constitutes valid input, one should
return a map containing an empty list for the cidr_blocks field instead
of a nil value.
The nil value is only appropriate when the input Config is also nil.
2018-08-21 02:29:37 +00:00
|
|
|
Config: testAccContainerCluster_withMasterAuthorizedNetworksConfig(clusterName, []string{"10.0.0.0/8", "8.8.8.8/32"}, ""),
|
2017-11-02 17:38:20 +00:00
|
|
|
},
|
|
|
|
{
|
2018-03-01 21:19:18 +00:00
|
|
|
ResourceName: "google_container_cluster.with_master_authorized_networks",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
},
|
|
|
|
{
|
Fix panic on empty list for authorized masters' `cidr_blocks` (#1904)
* test empty authorized masters' cidr_blocks
When the `cidr_block` isn't simply blank but contains an empty list as in
```
master_authorized_networks_config {
cidr_blocks = []
}
```
a panic occurs looking something like
```
goroutine 26 [running]:
github.com/terraform-providers/terraform-provider-google/google.expandMasterAuthorizedNetworksConfig(0x15a4f80, 0xc4202586e0, 0x21)
/tmp/GOPATH/src/github.com/terraform-providers/terraform-provider-google/google/resource_container_cluster.go:1355 +0x4f2
github.com/terraform-providers/terraform-provider-google/google.resourceContainerClusterCreate(0xc420146a80, 0x16b1800, 0xc4200b8000, 0x0, 0x0)
/tmp/GOPATH/src/github.com/terraform-providers/terraform-provider-google/google/resource_container_cluster.go:520 +0x2848
github.com/terraform-providers/terraform-provider-google/vendor/github.com/hashicorp/terraform/helper/schema.(*Resource).Apply(0xc420495490, 0xc420341310, 0xc4202582c0, 0x16b1800, 0xc4200b8000, 0x1, 0xc42024eae0, 0xc4201e3650)
/tmp/GOPATH/src/github.com/terraform-providers/terraform-provider-google/vendor/github.com/hashicorp/terraform/helper/schema/resource.go:227 +0x364
github.com/terraform-providers/terraform-provider-google/vendor/github.com/hashicorp/terraform/helper/schema.(*Provider).Apply(0xc4204c6700, 0xc4203412c0, 0xc420341310, 0xc4202582c0, 0x14ee1441a000, 0x0, 0x18)
/tmp/GOPATH/src/github.com/terraform-providers/terraform-provider-google/vendor/github.com/hashicorp/terraform/helper/schema/provider.go:283 +0xa4
github.com/terraform-providers/terraform-provider-google/vendor/github.com/hashicorp/terraform/plugin.(*ResourceProviderServer).Apply(0xc4202d7c40, 0xc42035de80, 0xc42025c160, 0x0, 0x0)
/tmp/GOPATH/src/github.com/terraform-providers/terraform-provider-google/vendor/github.com/hashicorp/terraform/plugin/resource_provider.go:527 +0x57
reflect.Value.call(0xc4203feae0, 0xc42000e038, 0x13, 0x19e88a8, 0x4, 0xc42015ff20, 0x3, 0x3, 0xc420047ee8, 0xc4204c6798, ...)
/usr/local/go/src/reflect/value.go:434 +0x905
reflect.Value.Call(0xc4203feae0, 0xc42000e038, 0x13, 0xc420047f20, 0x3, 0x3, 0xc400000001, 0x0, 0x0)
/usr/local/go/src/reflect/value.go:302 +0xa4
net/rpc.(*service).call(0xc420418600, 0xc42007c140, 0xc42001e798, 0xc4200c4000, 0xc4202d6c40, 0x1557f80, 0xc42035de80, 0x16, 0x1557fc0, 0xc42025c160, ...)
/usr/local/go/src/net/rpc/server.go:381 +0x142
created by net/rpc.(*Server).ServeCodec
/usr/local/go/src/net/rpc/server.go:475 +0x36b
```
which we trigger by altering the first step to contain the HCL notation
for an empty list instead of simply an empty string.
In order to accomplish this, the tests had to be modified to accept an
emptyValue string as well which contains the content of the
`emptyValue` string when the cidrBlocks array is empty. This maintains
the old behavior of the original tests when `emptyValue` is an empty
string, while also facilating differing behavior for the new testcase by
setting `emptyValue` to whichever string we want to test instead. I
don't think this is very clean, but I guess it's pragmatic enough.
I'll hear if this is a thorn in the side to someone :smirk:.
* avoid panic on cidr_block type assertion
This is basically the fix. Since the value can be nil, we want to ensure
we handle a failure during the assertion since we know that asserting
`nil` conforms to `map[string]interface{}` will cause a run-time panic.
* flatten to config on empty list for cidr_blocks
since an empty list for cidrBlocks constitutes valid input, one should
return a map containing an empty list for the cidr_blocks field instead
of a nil value.
The nil value is only appropriate when the input Config is also nil.
2018-08-21 02:29:37 +00:00
|
|
|
Config: testAccContainerCluster_withMasterAuthorizedNetworksConfig(clusterName, []string{}, ""),
|
2017-11-02 17:38:20 +00:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
2018-03-01 21:19:18 +00:00
|
|
|
resource.TestCheckNoResourceAttr("google_container_cluster.with_master_authorized_networks",
|
|
|
|
"master_authorized_networks_config.0.cidr_blocks"),
|
2017-11-02 17:38:20 +00:00
|
|
|
),
|
|
|
|
},
|
2018-03-16 00:08:39 +00:00
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_master_authorized_networks",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2017-11-02 17:38:20 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-04-05 21:51:35 +00:00
|
|
|
func TestAccContainerCluster_regional(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
clusterName := fmt.Sprintf("cluster-test-regional-%s", acctest.RandString(10))
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_regional(clusterName),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.regional",
|
|
|
|
ImportStateIdPrefix: "us-central1/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
#1300 Supporting regional clusters for node pools (#1320)
This PR also switched us to using the beta API in all cases, and that had a side effect which is worth noting, note included here for posterity.
=====
The problem is, we add a GPU, and as per the docs, GKE adds a taint to
the node pool saying "don't schedule here unless you tolerate GPUs",
which is pretty sensible.
Terraform doesn't know about that, because it didn't ask for the taint
to be added. So after apply, on refresh, it sees the state of the world
(1 taint) and the state of the config (0 taints) and wants to set the
world equal to the config. This introduces a diff, which makes the test
fail - tests fail if there's a diff after they run.
Taints are a beta feature, though. :) And since the config doesn't
contain any taints, terraform didn't see any beta features in that node
pool ... so it used to send the request to the v1 API. And since the v1
API didn't return anything about taints (since they're a beta feature),
terraform happily checked the state of the world (0 taints I know about)
vs the config (0 taints), and all was well.
This PR makes every node pool refresh request hit the beta API. So now
terraform finds out about the taints (which were always there) and the
test fails (which it always should have done).
The solution is probably to write a little bit of code which suppresses
the report of the diff of any taint with value 'nvidia.com/gpu', but
only if GPUs are enabled. I think that's something that can be done.
2018-04-25 00:55:21 +00:00
|
|
|
func TestAccContainerCluster_regionalWithNodePool(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
clusterName := fmt.Sprintf("cluster-test-regional-%s", acctest.RandString(10))
|
|
|
|
npName := fmt.Sprintf("tf-cluster-nodepool-test-%s", acctest.RandString(10))
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_regionalWithNodePool(clusterName, npName),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.regional",
|
|
|
|
ImportStateIdPrefix: "us-central1/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-01-04 06:14:39 +00:00
|
|
|
func TestAccContainerCluster_withAdditionalZones(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-07-05 23:00:49 +00:00
|
|
|
clusterName := fmt.Sprintf("cluster-test-%s", acctest.RandString(10))
|
|
|
|
|
2017-01-04 06:14:39 +00:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2017-06-28 08:34:20 +00:00
|
|
|
{
|
2017-07-05 23:00:49 +00:00
|
|
|
Config: testAccContainerCluster_withAdditionalZones(clusterName),
|
2018-03-16 00:08:39 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_additional_zones",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
2017-07-05 23:00:49 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_updateAdditionalZones(clusterName),
|
2018-03-16 00:08:39 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_additional_zones",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
2017-01-04 06:14:39 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-04-19 21:17:38 +00:00
|
|
|
func TestAccContainerCluster_regionalWithAdditionalZones(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
clusterName := fmt.Sprintf("cluster-test-%s", acctest.RandString(10))
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_regionalAdditionalZones(clusterName),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_additional_zones",
|
|
|
|
ImportStateIdPrefix: "us-central1/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_regionalUpdateAdditionalZones(clusterName),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_additional_zones",
|
|
|
|
ImportStateIdPrefix: "us-central1/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-10-31 23:38:18 +00:00
|
|
|
func TestAccContainerCluster_withKubernetesAlpha(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
clusterName := fmt.Sprintf("cluster-test-%s", acctest.RandString(10))
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_withKubernetesAlpha(clusterName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.with_kubernetes_alpha", "enable_kubernetes_alpha", "true"),
|
|
|
|
),
|
|
|
|
},
|
2018-03-16 00:08:39 +00:00
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_kubernetes_alpha",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2017-10-31 23:38:18 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-10-01 16:41:54 +00:00
|
|
|
func TestAccContainerCluster_withTpu(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
clusterName := fmt.Sprintf("cluster-test-%s", acctest.RandString(10))
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_withTpu(clusterName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.with_tpu", "enable_tpu", "true"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_tpu",
|
|
|
|
ImportStateIdPrefix: "us-central1-b/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-03-30 17:10:25 +00:00
|
|
|
func TestAccContainerCluster_withPrivateCluster(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
clusterName := fmt.Sprintf("cluster-test-%s", acctest.RandString(10))
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_withPrivateCluster(clusterName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.with_private_cluster", "private_cluster", "true"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_private_cluster",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2017-07-31 18:09:05 +00:00
|
|
|
func TestAccContainerCluster_withLegacyAbac(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-07-31 18:09:05 +00:00
|
|
|
clusterName := fmt.Sprintf("cluster-test-%s", acctest.RandString(10))
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_withLegacyAbac(clusterName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.with_legacy_abac", "enable_legacy_abac", "true"),
|
|
|
|
),
|
|
|
|
},
|
2018-03-16 00:08:39 +00:00
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_legacy_abac",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2017-07-31 18:09:05 +00:00
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_updateLegacyAbac(clusterName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.with_legacy_abac", "enable_legacy_abac", "false"),
|
|
|
|
),
|
|
|
|
},
|
2018-03-16 00:08:39 +00:00
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_legacy_abac",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2017-07-31 18:09:05 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-04-04 17:58:08 +00:00
|
|
|
/*
|
|
|
|
Since GKE disables legacy ABAC by default in Kubernetes version 1.8+, and the default Kubernetes
|
|
|
|
version for GKE is also 1.8+, this test will ensure that legacy ABAC is disabled by default to be
|
|
|
|
more consistent with default settings in the Cloud Console
|
|
|
|
*/
|
|
|
|
func TestAccContainerCluster_withDefaultLegacyAbac(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_defaultLegacyAbac(acctest.RandString(10)),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.default_legacy_abac", "enable_legacy_abac", "false"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.default_legacy_abac",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-12-18 13:50:46 +00:00
|
|
|
func TestAccContainerCluster_withVersion(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-08-08 18:31:12 +00:00
|
|
|
clusterName := fmt.Sprintf("cluster-test-%s", acctest.RandString(10))
|
|
|
|
|
2016-12-18 13:50:46 +00:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2017-06-28 08:34:20 +00:00
|
|
|
{
|
2017-08-08 18:31:12 +00:00
|
|
|
Config: testAccContainerCluster_withVersion(clusterName),
|
2018-03-16 00:08:39 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_version",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
ImportStateVerifyIgnore: []string{"min_master_version"},
|
2017-08-08 18:31:12 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccContainerCluster_updateVersion(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-08-08 18:31:12 +00:00
|
|
|
clusterName := fmt.Sprintf("cluster-test-%s", acctest.RandString(10))
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_withLowerVersion(clusterName),
|
2018-03-16 00:08:39 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_version",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
ImportStateVerifyIgnore: []string{"min_master_version"},
|
2017-08-08 18:31:12 +00:00
|
|
|
},
|
|
|
|
{
|
2017-10-06 22:48:01 +00:00
|
|
|
Config: testAccContainerCluster_updateVersion(clusterName),
|
2018-03-16 00:08:39 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_version",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
ImportStateVerifyIgnore: []string{"min_master_version"},
|
2016-12-18 13:50:46 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-08-20 20:40:38 +00:00
|
|
|
func TestAccContainerCluster_withNodeConfig(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2018-08-07 21:07:28 +00:00
|
|
|
clusterName := fmt.Sprintf("cluster-test-%s", acctest.RandString(10))
|
|
|
|
|
2015-08-20 20:40:38 +00:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2017-06-28 08:34:20 +00:00
|
|
|
{
|
2018-08-07 21:07:28 +00:00
|
|
|
Config: testAccContainerCluster_withNodeConfig(clusterName),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_node_config",
|
|
|
|
ImportStateIdPrefix: "us-central1-f/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_withNodeConfigUpdate(clusterName),
|
2018-03-16 00:08:39 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_node_config",
|
|
|
|
ImportStateIdPrefix: "us-central1-f/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
2015-08-20 20:40:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-11-14 23:50:24 +00:00
|
|
|
func TestAccContainerCluster_withNodeConfigScopeAlias(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2016-11-14 23:50:24 +00:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2017-06-28 08:34:20 +00:00
|
|
|
{
|
2017-11-28 00:32:00 +00:00
|
|
|
Config: testAccContainerCluster_withNodeConfigScopeAlias(),
|
2018-03-16 00:08:39 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_node_config_scope_alias",
|
|
|
|
ImportStateIdPrefix: "us-central1-f/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
2016-11-14 23:50:24 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-03-27 21:55:42 +00:00
|
|
|
func TestAccContainerCluster_withNodeConfigTaints(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_withNodeConfigTaints(),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.with_node_config", "node_config.0.taint.#", "2"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
// Don't include an import step because beta features can't yet be imported.
|
|
|
|
// Once taints are in GA, consider merging this test with the _withNodeConfig test.
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-03-15 20:28:30 +00:00
|
|
|
func TestAccContainerCluster_withWorkloadMetadataConfig(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_withWorkloadMetadataConfig(),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.with_workload_metadata_config",
|
|
|
|
"node_config.0.workload_metadata_config.0.node_metadata", "SECURE"),
|
|
|
|
),
|
|
|
|
},
|
2018-03-16 00:08:39 +00:00
|
|
|
{
|
2018-05-09 18:24:40 +00:00
|
|
|
ResourceName: "google_container_cluster.with_workload_metadata_config",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
ImportStateVerifyIgnore: []string{"min_master_version"},
|
2018-03-16 00:08:39 +00:00
|
|
|
},
|
2018-03-15 20:28:30 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-09-03 09:51:20 +00:00
|
|
|
func TestAccContainerCluster_network(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2016-09-03 09:51:20 +00:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2017-06-28 08:34:20 +00:00
|
|
|
{
|
2017-11-28 00:32:00 +00:00
|
|
|
Config: testAccContainerCluster_networkRef(),
|
2018-03-16 00:08:39 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_net_ref_by_url",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_net_ref_by_name",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
2016-09-03 09:51:20 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-03-07 05:14:32 +00:00
|
|
|
func TestAccContainerCluster_backend(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-03-07 05:14:32 +00:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2017-06-28 08:34:20 +00:00
|
|
|
{
|
2017-11-28 00:32:00 +00:00
|
|
|
Config: testAccContainerCluster_backendRef(),
|
2018-03-16 00:08:39 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.primary",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
2017-03-07 05:14:32 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-08-18 22:29:51 +00:00
|
|
|
func TestAccContainerCluster_withLogging(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-08-18 22:29:51 +00:00
|
|
|
clusterName := fmt.Sprintf("cluster-test-%s", acctest.RandString(10))
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_withLogging(clusterName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.with_logging", "logging_service", "logging.googleapis.com"),
|
|
|
|
),
|
|
|
|
},
|
2018-03-16 00:08:39 +00:00
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_logging",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2017-08-18 22:29:51 +00:00
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_updateLogging(clusterName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.with_logging", "logging_service", "none"),
|
|
|
|
),
|
|
|
|
},
|
2018-03-16 00:08:39 +00:00
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_logging",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2017-08-18 22:29:51 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-10-20 16:46:21 +00:00
|
|
|
func TestAccContainerCluster_withMonitoring(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
clusterName := fmt.Sprintf("cluster-test-%s", acctest.RandString(10))
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_withMonitoring(clusterName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.with_monitoring", "monitoring_service", "monitoring.googleapis.com"),
|
|
|
|
),
|
|
|
|
},
|
2018-03-16 00:08:39 +00:00
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_monitoring",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2017-10-20 16:46:21 +00:00
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_updateMonitoring(clusterName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.with_monitoring", "monitoring_service", "none"),
|
|
|
|
),
|
|
|
|
},
|
2018-03-16 00:08:39 +00:00
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_monitoring",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2017-10-20 16:46:21 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-04-12 19:57:53 +00:00
|
|
|
func TestAccContainerCluster_withNodePoolBasic(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-10-04 00:09:34 +00:00
|
|
|
clusterName := fmt.Sprintf("tf-cluster-nodepool-test-%s", acctest.RandString(10))
|
|
|
|
npName := fmt.Sprintf("tf-cluster-nodepool-test-%s", acctest.RandString(10))
|
|
|
|
|
2017-04-12 19:57:53 +00:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2017-06-28 08:34:20 +00:00
|
|
|
{
|
2017-10-04 00:09:34 +00:00
|
|
|
Config: testAccContainerCluster_withNodePoolBasic(clusterName, npName),
|
2018-03-16 00:08:39 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_node_pool",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
2017-04-12 19:57:53 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-08-18 00:51:58 +00:00
|
|
|
func TestAccContainerCluster_withNodePoolResize(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-08-18 00:51:58 +00:00
|
|
|
clusterName := fmt.Sprintf("tf-cluster-nodepool-test-%s", acctest.RandString(10))
|
|
|
|
npName := fmt.Sprintf("tf-cluster-nodepool-test-%s", acctest.RandString(10))
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_withNodePoolAdditionalZones(clusterName, npName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.with_node_pool", "node_pool.0.node_count", "2"),
|
|
|
|
),
|
|
|
|
},
|
2018-03-16 00:08:39 +00:00
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_node_pool",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2017-08-18 00:51:58 +00:00
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_withNodePoolResize(clusterName, npName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.with_node_pool", "node_pool.0.node_count", "3"),
|
|
|
|
),
|
|
|
|
},
|
2018-03-16 00:08:39 +00:00
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_node_pool",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2017-08-18 00:51:58 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-10-04 00:09:34 +00:00
|
|
|
func TestAccContainerCluster_withNodePoolAutoscaling(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-10-04 00:09:34 +00:00
|
|
|
clusterName := fmt.Sprintf("tf-cluster-nodepool-test-%s", acctest.RandString(10))
|
|
|
|
npName := fmt.Sprintf("tf-cluster-nodepool-test-%s", acctest.RandString(10))
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerNodePoolDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccContainerCluster_withNodePoolAutoscaling(clusterName, npName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.with_node_pool", "node_pool.0.autoscaling.0.min_node_count", "1"),
|
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.with_node_pool", "node_pool.0.autoscaling.0.max_node_count", "3"),
|
|
|
|
),
|
|
|
|
},
|
2018-03-16 00:08:39 +00:00
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_node_pool",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2017-10-04 00:09:34 +00:00
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccContainerCluster_withNodePoolUpdateAutoscaling(clusterName, npName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.with_node_pool", "node_pool.0.autoscaling.0.min_node_count", "1"),
|
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.with_node_pool", "node_pool.0.autoscaling.0.max_node_count", "5"),
|
|
|
|
),
|
|
|
|
},
|
2018-03-16 00:08:39 +00:00
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_node_pool",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2017-10-04 00:09:34 +00:00
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccContainerCluster_withNodePoolBasic(clusterName, npName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckNoResourceAttr("google_container_cluster.with_node_pool", "node_pool.0.autoscaling.0.min_node_count"),
|
|
|
|
resource.TestCheckNoResourceAttr("google_container_cluster.with_node_pool", "node_pool.0.autoscaling.0.max_node_count"),
|
|
|
|
),
|
|
|
|
},
|
2018-03-16 00:08:39 +00:00
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_node_pool",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2017-10-04 00:09:34 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-04-12 19:57:53 +00:00
|
|
|
func TestAccContainerCluster_withNodePoolMultiple(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-04-12 19:57:53 +00:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2017-06-28 08:34:20 +00:00
|
|
|
{
|
2017-11-28 00:32:00 +00:00
|
|
|
Config: testAccContainerCluster_withNodePoolMultiple(),
|
2018-03-16 00:08:39 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_node_pool_multiple",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
2017-04-12 19:57:53 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-08-11 19:23:17 +00:00
|
|
|
func TestAccContainerCluster_withNodePoolNodeConfig(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-08-11 19:23:17 +00:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_withNodePoolNodeConfig(),
|
2018-03-16 00:08:39 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_node_pool_node_config",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
2017-08-11 19:23:17 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-03-23 00:22:44 +00:00
|
|
|
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"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-11-07 23:42:11 +00:00
|
|
|
func TestAccContainerCluster_withMaintenanceWindow(t *testing.T) {
|
|
|
|
t.Parallel()
|
2017-12-27 20:29:14 +00:00
|
|
|
clusterName := acctest.RandString(10)
|
|
|
|
resourceName := "google_container_cluster.with_maintenance_window"
|
2017-11-07 23:42:11 +00:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
2017-12-27 20:29:14 +00:00
|
|
|
Config: testAccContainerCluster_withMaintenanceWindow(clusterName, "03:00"),
|
2018-03-16 00:08:39 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: resourceName,
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
2017-12-27 20:29:14 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_withMaintenanceWindow(clusterName, ""),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckNoResourceAttr(resourceName,
|
|
|
|
"maintenance_policy.0.daily_maintenance_window.0.start_time"),
|
2017-11-07 23:42:11 +00:00
|
|
|
),
|
|
|
|
},
|
2018-03-16 00:08:39 +00:00
|
|
|
{
|
|
|
|
ResourceName: resourceName,
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
// maintenance_policy.# = 0 is equivalent to no maintenance policy at all,
|
|
|
|
// but will still cause an import diff
|
|
|
|
ImportStateVerifyIgnore: []string{"maintenance_policy.#"},
|
|
|
|
},
|
2017-11-07 23:42:11 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-09-05 16:52:06 +00:00
|
|
|
func TestAccContainerCluster_withIPAllocationPolicy_existingSecondaryRanges(t *testing.T) {
|
2017-11-27 23:15:03 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
cluster := fmt.Sprintf("cluster-test-%s", acctest.RandString(10))
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
2018-09-05 16:52:06 +00:00
|
|
|
Config: testAccContainerCluster_withIPAllocationPolicy_existingSecondaryRanges(cluster),
|
2017-11-27 23:15:03 +00:00
|
|
|
},
|
2018-03-16 00:08:39 +00:00
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_ip_allocation_policy",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2018-09-05 16:52:06 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccContainerCluster_withIPAllocationPolicy_specificIPRanges(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
cluster := fmt.Sprintf("cluster-test-%s", acctest.RandString(10))
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_withIPAllocationPolicy_specificIPRanges(cluster),
|
|
|
|
},
|
2017-11-27 23:15:03 +00:00
|
|
|
{
|
2018-09-05 16:52:06 +00:00
|
|
|
ResourceName: "google_container_cluster.with_ip_allocation_policy",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccContainerCluster_withIPAllocationPolicy_specificSizes(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
cluster := fmt.Sprintf("cluster-test-%s", acctest.RandString(10))
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_withIPAllocationPolicy_specificSizes(cluster),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_ip_allocation_policy",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccContainerCluster_withIPAllocationPolicy_createSubnetwork(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
cluster := fmt.Sprintf("cluster-test-%s", acctest.RandString(10))
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_withIPAllocationPolicy_createSubnetwork(cluster),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_ip_allocation_policy",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
2017-11-27 23:15:03 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-03-14 21:00:31 +00:00
|
|
|
func TestAccContainerCluster_withPodSecurityPolicy(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
clusterName := fmt.Sprintf("cluster-test-%s", acctest.RandString(10))
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_withPodSecurityPolicy(clusterName, true),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.with_pod_security_policy",
|
|
|
|
"pod_security_policy_config.0.enabled", "true"),
|
|
|
|
),
|
|
|
|
},
|
2018-03-16 00:08:39 +00:00
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_pod_security_policy",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2018-03-23 18:27:37 +00:00
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_withPodSecurityPolicy(clusterName, false),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr("google_container_cluster.with_pod_security_policy",
|
|
|
|
"pod_security_policy_config.0.enabled", "false"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_pod_security_policy",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2018-03-14 21:00:31 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-05-23 23:47:17 +00:00
|
|
|
func TestAccContainerCluster_sharedVpc(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
clusterName := fmt.Sprintf("cluster-test-%s", acctest.RandString(10))
|
|
|
|
org := getTestOrgFromEnv(t)
|
|
|
|
billingId := getTestBillingAccountFromEnv(t)
|
|
|
|
projectName := fmt.Sprintf("tf-xpntest-%s", acctest.RandString(10))
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_sharedVpc(org, billingId, projectName, clusterName),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.shared_vpc_cluster",
|
|
|
|
ImportStateIdPrefix: fmt.Sprintf("%s-service/us-central1-a/", projectName),
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-06-15 10:10:25 +00:00
|
|
|
func TestAccContainerCluster_withResourceLabels(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
2018-06-25 08:55:27 +00:00
|
|
|
clusterName := fmt.Sprintf("cluster-test-%s", acctest.RandString(10))
|
|
|
|
|
2018-06-15 10:10:25 +00:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
2018-06-25 08:55:27 +00:00
|
|
|
Config: testAccContainerCluster_withResourceLabels(clusterName),
|
2018-06-15 10:10:25 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_resource_labels",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-07-13 09:27:40 +00:00
|
|
|
func TestAccContainerCluster_withResourceLabelsUpdate(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
clusterName := fmt.Sprintf("cluster-test-%s", acctest.RandString(10))
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_withoutResourceLabels(clusterName),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_withResourceLabels(clusterName),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_resource_labels",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-08-17 00:51:03 +00:00
|
|
|
func TestAccContainerCluster_withBinaryAuthorization(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
clusterName := fmt.Sprintf("cluster-test-%s", acctest.RandString(10))
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_withBinaryAuthorization(clusterName, true),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_binary_authorization",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Config: testAccContainerCluster_withBinaryAuthorization(clusterName, false),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ResourceName: "google_container_cluster.with_binary_authorization",
|
|
|
|
ImportStateIdPrefix: "us-central1-a/",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-07-05 16:39:01 +00:00
|
|
|
func testAccCheckContainerClusterDestroy(s *terraform.State) error {
|
|
|
|
config := testAccProvider.Meta().(*Config)
|
|
|
|
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
|
|
if rs.Type != "google_container_cluster" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
attributes := rs.Primary.Attributes
|
|
|
|
_, err := config.clientContainer.Projects.Zones.Clusters.Get(
|
|
|
|
config.Project, attributes["zone"], attributes["name"]).Do()
|
|
|
|
if err == nil {
|
|
|
|
return fmt.Errorf("Cluster still exists")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-03-15 00:50:58 +00:00
|
|
|
func getResourceAttributes(n string, s *terraform.State) (map[string]string, error) {
|
|
|
|
rs, ok := s.RootModule().Resources[n]
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("Not found: %s", n)
|
|
|
|
}
|
|
|
|
|
|
|
|
if rs.Primary.ID == "" {
|
|
|
|
return nil, fmt.Errorf("No ID is set")
|
|
|
|
}
|
|
|
|
|
|
|
|
return rs.Primary.Attributes, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func checkMatch(attributes map[string]string, attr string, gcp interface{}) string {
|
|
|
|
if gcpList, ok := gcp.([]string); ok {
|
|
|
|
return checkListMatch(attributes, attr, gcpList)
|
|
|
|
}
|
2017-02-15 01:45:53 +00:00
|
|
|
if gcpMap, ok := gcp.(map[string]string); ok {
|
|
|
|
return checkMapMatch(attributes, attr, gcpMap)
|
|
|
|
}
|
2017-09-01 20:02:26 +00:00
|
|
|
if gcpBool, ok := gcp.(bool); ok {
|
|
|
|
return checkBoolMatch(attributes, attr, gcpBool)
|
|
|
|
}
|
|
|
|
|
2017-03-15 00:50:58 +00:00
|
|
|
tf := attributes[attr]
|
|
|
|
if tf != gcp {
|
|
|
|
return matchError(attr, tf, gcp)
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func checkListMatch(attributes map[string]string, attr string, gcpList []string) string {
|
|
|
|
num, err := strconv.Atoi(attributes[attr+".#"])
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Sprintf("Error in number conversion for attribute %s: %s", attr, err)
|
|
|
|
}
|
|
|
|
if num != len(gcpList) {
|
|
|
|
return fmt.Sprintf("Cluster has mismatched %s size.\nTF Size: %d\nGCP Size: %d", attr, num, len(gcpList))
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, gcp := range gcpList {
|
|
|
|
if tf := attributes[fmt.Sprintf("%s.%d", attr, i)]; tf != gcp {
|
|
|
|
return matchError(fmt.Sprintf("%s[%d]", attr, i), tf, gcp)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2017-02-15 01:45:53 +00:00
|
|
|
func checkMapMatch(attributes map[string]string, attr string, gcpMap map[string]string) string {
|
|
|
|
num, err := strconv.Atoi(attributes[attr+".%"])
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Sprintf("Error in number conversion for attribute %s: %s", attr, err)
|
|
|
|
}
|
|
|
|
if num != len(gcpMap) {
|
|
|
|
return fmt.Sprintf("Cluster has mismatched %s size.\nTF Size: %d\nGCP Size: %d", attr, num, len(gcpMap))
|
|
|
|
}
|
|
|
|
|
|
|
|
for k, gcp := range gcpMap {
|
|
|
|
if tf := attributes[fmt.Sprintf("%s.%s", attr, k)]; tf != gcp {
|
|
|
|
return matchError(fmt.Sprintf("%s[%s]", attr, k), tf, gcp)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2017-09-01 20:02:26 +00:00
|
|
|
func checkBoolMatch(attributes map[string]string, attr string, gcpBool bool) string {
|
2017-10-03 16:29:27 +00:00
|
|
|
// Handle the case where an unset value defaults to false
|
|
|
|
var tf bool
|
2017-11-28 00:25:32 +00:00
|
|
|
var err error
|
2017-10-03 16:29:27 +00:00
|
|
|
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])
|
|
|
|
}
|
2017-09-01 20:02:26 +00:00
|
|
|
}
|
2017-10-03 16:29:27 +00:00
|
|
|
|
2017-09-01 20:02:26 +00:00
|
|
|
if tf != gcpBool {
|
|
|
|
return matchError(attr, tf, gcpBool)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2017-07-05 23:00:49 +00:00
|
|
|
func matchError(attr, tf interface{}, gcp interface{}) string {
|
2017-03-15 00:50:58 +00:00
|
|
|
return fmt.Sprintf("Cluster has mismatched %s.\nTF State: %+v\nGCP State: %+v", attr, tf, gcp)
|
|
|
|
}
|
|
|
|
|
2017-09-07 17:31:58 +00:00
|
|
|
func testAccContainerCluster_basic(name string) string {
|
|
|
|
return fmt.Sprintf(`
|
2015-07-05 16:39:01 +00:00
|
|
|
resource "google_container_cluster" "primary" {
|
2017-09-07 17:31:58 +00:00
|
|
|
name = "%s"
|
2015-07-05 16:39:01 +00:00
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 3
|
2017-09-07 17:31:58 +00:00
|
|
|
}`, name)
|
|
|
|
}
|
2017-05-31 19:43:31 +00:00
|
|
|
|
2017-11-28 00:32:00 +00:00
|
|
|
func testAccContainerCluster_withTimeout() string {
|
|
|
|
return fmt.Sprintf(`
|
2017-06-28 08:34:20 +00:00
|
|
|
resource "google_container_cluster" "primary" {
|
|
|
|
name = "cluster-test-%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 3
|
|
|
|
|
|
|
|
timeouts {
|
|
|
|
create = "30m"
|
|
|
|
delete = "30m"
|
|
|
|
update = "30m"
|
|
|
|
}
|
|
|
|
}`, acctest.RandString(10))
|
2017-11-28 00:32:00 +00:00
|
|
|
}
|
2017-06-28 08:34:20 +00:00
|
|
|
|
2017-10-20 16:47:07 +00:00
|
|
|
func testAccContainerCluster_withAddons(clusterName string) string {
|
|
|
|
return fmt.Sprintf(`
|
2017-10-03 16:29:27 +00:00
|
|
|
resource "google_container_cluster" "primary" {
|
2017-10-20 16:47:07 +00:00
|
|
|
name = "%s"
|
2017-10-03 16:29:27 +00:00
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 3
|
|
|
|
|
|
|
|
addons_config {
|
|
|
|
http_load_balancing { disabled = true }
|
|
|
|
kubernetes_dashboard { disabled = true }
|
|
|
|
}
|
2017-10-20 16:47:07 +00:00
|
|
|
}`, clusterName)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccContainerCluster_updateAddons(clusterName string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "primary" {
|
|
|
|
name = "%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 3
|
|
|
|
|
|
|
|
addons_config {
|
|
|
|
http_load_balancing { disabled = false }
|
|
|
|
kubernetes_dashboard { disabled = true }
|
|
|
|
horizontal_pod_autoscaling { disabled = true }
|
|
|
|
}
|
|
|
|
}`, clusterName)
|
|
|
|
}
|
2017-10-03 16:29:27 +00:00
|
|
|
|
2018-08-15 19:50:17 +00:00
|
|
|
func testAccContainerCluster_withMasterAuth(clusterName string) string {
|
2017-11-28 00:32:00 +00:00
|
|
|
return fmt.Sprintf(`
|
2017-05-31 19:43:31 +00:00
|
|
|
resource "google_container_cluster" "with_master_auth" {
|
2018-08-15 19:50:17 +00:00
|
|
|
name = "%s"
|
2017-05-31 19:43:31 +00:00
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 3
|
2015-07-05 16:39:01 +00:00
|
|
|
|
|
|
|
master_auth {
|
|
|
|
username = "mr.yoda"
|
2018-01-18 17:51:55 +00:00
|
|
|
password = "adoy.rm.123456789"
|
2015-07-05 16:39:01 +00:00
|
|
|
}
|
2018-08-15 19:50:17 +00:00
|
|
|
}`, clusterName)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccContainerCluster_updateMasterAuth(clusterName string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_master_auth" {
|
|
|
|
name = "%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 3
|
|
|
|
|
|
|
|
master_auth {
|
|
|
|
username = "mr.yoda.adoy.mr"
|
|
|
|
password = "adoy.rm.123456789.mr.yoda"
|
|
|
|
}
|
|
|
|
}`, clusterName)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccContainerCluster_disableMasterAuth(clusterName string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_master_auth" {
|
|
|
|
name = "%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 3
|
|
|
|
|
|
|
|
master_auth {
|
|
|
|
username = ""
|
|
|
|
password = ""
|
|
|
|
}
|
|
|
|
}`, clusterName)
|
2017-11-28 00:32:00 +00:00
|
|
|
}
|
2015-08-20 20:40:38 +00:00
|
|
|
|
2018-04-28 01:06:26 +00:00
|
|
|
func testAccContainerCluster_updateMasterAuthNoCert() string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_master_auth" {
|
|
|
|
name = "cluster-test-%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 3
|
|
|
|
|
|
|
|
master_auth {
|
|
|
|
username = "mr.yoda"
|
|
|
|
password = "adoy.rm.123456789"
|
|
|
|
client_certificate_config {
|
|
|
|
issue_client_certificate = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`, acctest.RandString(10))
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccContainerCluster_withMasterAuthNoCert() string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_master_auth_no_cert" {
|
|
|
|
name = "cluster-test-%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 3
|
|
|
|
|
|
|
|
master_auth {
|
|
|
|
username = "mr.yoda"
|
|
|
|
password = "adoy.rm.123456789"
|
|
|
|
client_certificate_config {
|
|
|
|
issue_client_certificate = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`, acctest.RandString(10))
|
|
|
|
}
|
|
|
|
|
2017-11-27 20:40:07 +00:00
|
|
|
func testAccContainerCluster_withNetworkPolicyEnabled(clusterName string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_network_policy_enabled" {
|
|
|
|
name = "%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 1
|
2018-03-23 00:22:44 +00:00
|
|
|
remove_default_node_pool = true
|
2017-11-27 20:40:07 +00:00
|
|
|
|
|
|
|
network_policy {
|
|
|
|
enabled = true
|
|
|
|
provider = "CALICO"
|
2018-06-15 20:21:51 +00:00
|
|
|
}
|
2018-03-15 21:50:24 +00:00
|
|
|
addons_config {
|
|
|
|
network_policy_config {
|
|
|
|
disabled = false
|
|
|
|
}
|
|
|
|
}
|
2017-11-27 20:40:07 +00:00
|
|
|
}`, clusterName)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccContainerCluster_removeNetworkPolicy(clusterName string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_network_policy_enabled" {
|
|
|
|
name = "%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 1
|
2018-03-23 00:22:44 +00:00
|
|
|
remove_default_node_pool = true
|
2017-11-27 20:40:07 +00:00
|
|
|
}`, clusterName)
|
|
|
|
}
|
|
|
|
|
2018-02-01 18:25:12 +00:00
|
|
|
func testAccContainerCluster_withNetworkPolicyDisabled(clusterName string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_network_policy_enabled" {
|
|
|
|
name = "%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 1
|
2018-03-23 00:22:44 +00:00
|
|
|
remove_default_node_pool = true
|
2018-02-01 18:25:12 +00:00
|
|
|
|
|
|
|
network_policy = {}
|
|
|
|
}`, clusterName)
|
|
|
|
}
|
|
|
|
|
2018-03-15 21:50:24 +00:00
|
|
|
func testAccContainerCluster_withNetworkPolicyConfigDisabled(clusterName string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_network_policy_enabled" {
|
|
|
|
name = "%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 1
|
2018-03-23 00:22:44 +00:00
|
|
|
remove_default_node_pool = true
|
2018-03-15 21:50:24 +00:00
|
|
|
|
|
|
|
network_policy = {}
|
|
|
|
addons_config {
|
|
|
|
network_policy_config {
|
|
|
|
disabled = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`, clusterName)
|
|
|
|
}
|
|
|
|
|
Fix panic on empty list for authorized masters' `cidr_blocks` (#1904)
* test empty authorized masters' cidr_blocks
When the `cidr_block` isn't simply blank but contains an empty list as in
```
master_authorized_networks_config {
cidr_blocks = []
}
```
a panic occurs looking something like
```
goroutine 26 [running]:
github.com/terraform-providers/terraform-provider-google/google.expandMasterAuthorizedNetworksConfig(0x15a4f80, 0xc4202586e0, 0x21)
/tmp/GOPATH/src/github.com/terraform-providers/terraform-provider-google/google/resource_container_cluster.go:1355 +0x4f2
github.com/terraform-providers/terraform-provider-google/google.resourceContainerClusterCreate(0xc420146a80, 0x16b1800, 0xc4200b8000, 0x0, 0x0)
/tmp/GOPATH/src/github.com/terraform-providers/terraform-provider-google/google/resource_container_cluster.go:520 +0x2848
github.com/terraform-providers/terraform-provider-google/vendor/github.com/hashicorp/terraform/helper/schema.(*Resource).Apply(0xc420495490, 0xc420341310, 0xc4202582c0, 0x16b1800, 0xc4200b8000, 0x1, 0xc42024eae0, 0xc4201e3650)
/tmp/GOPATH/src/github.com/terraform-providers/terraform-provider-google/vendor/github.com/hashicorp/terraform/helper/schema/resource.go:227 +0x364
github.com/terraform-providers/terraform-provider-google/vendor/github.com/hashicorp/terraform/helper/schema.(*Provider).Apply(0xc4204c6700, 0xc4203412c0, 0xc420341310, 0xc4202582c0, 0x14ee1441a000, 0x0, 0x18)
/tmp/GOPATH/src/github.com/terraform-providers/terraform-provider-google/vendor/github.com/hashicorp/terraform/helper/schema/provider.go:283 +0xa4
github.com/terraform-providers/terraform-provider-google/vendor/github.com/hashicorp/terraform/plugin.(*ResourceProviderServer).Apply(0xc4202d7c40, 0xc42035de80, 0xc42025c160, 0x0, 0x0)
/tmp/GOPATH/src/github.com/terraform-providers/terraform-provider-google/vendor/github.com/hashicorp/terraform/plugin/resource_provider.go:527 +0x57
reflect.Value.call(0xc4203feae0, 0xc42000e038, 0x13, 0x19e88a8, 0x4, 0xc42015ff20, 0x3, 0x3, 0xc420047ee8, 0xc4204c6798, ...)
/usr/local/go/src/reflect/value.go:434 +0x905
reflect.Value.Call(0xc4203feae0, 0xc42000e038, 0x13, 0xc420047f20, 0x3, 0x3, 0xc400000001, 0x0, 0x0)
/usr/local/go/src/reflect/value.go:302 +0xa4
net/rpc.(*service).call(0xc420418600, 0xc42007c140, 0xc42001e798, 0xc4200c4000, 0xc4202d6c40, 0x1557f80, 0xc42035de80, 0x16, 0x1557fc0, 0xc42025c160, ...)
/usr/local/go/src/net/rpc/server.go:381 +0x142
created by net/rpc.(*Server).ServeCodec
/usr/local/go/src/net/rpc/server.go:475 +0x36b
```
which we trigger by altering the first step to contain the HCL notation
for an empty list instead of simply an empty string.
In order to accomplish this, the tests had to be modified to accept an
emptyValue string as well which contains the content of the
`emptyValue` string when the cidrBlocks array is empty. This maintains
the old behavior of the original tests when `emptyValue` is an empty
string, while also facilating differing behavior for the new testcase by
setting `emptyValue` to whichever string we want to test instead. I
don't think this is very clean, but I guess it's pragmatic enough.
I'll hear if this is a thorn in the side to someone :smirk:.
* avoid panic on cidr_block type assertion
This is basically the fix. Since the value can be nil, we want to ensure
we handle a failure during the assertion since we know that asserting
`nil` conforms to `map[string]interface{}` will cause a run-time panic.
* flatten to config on empty list for cidr_blocks
since an empty list for cidrBlocks constitutes valid input, one should
return a map containing an empty list for the cidr_blocks field instead
of a nil value.
The nil value is only appropriate when the input Config is also nil.
2018-08-21 02:29:37 +00:00
|
|
|
func testAccContainerCluster_withMasterAuthorizedNetworksConfig(clusterName string, cidrs []string, emptyValue string) string {
|
2017-11-02 17:38:20 +00:00
|
|
|
|
Fix panic on empty list for authorized masters' `cidr_blocks` (#1904)
* test empty authorized masters' cidr_blocks
When the `cidr_block` isn't simply blank but contains an empty list as in
```
master_authorized_networks_config {
cidr_blocks = []
}
```
a panic occurs looking something like
```
goroutine 26 [running]:
github.com/terraform-providers/terraform-provider-google/google.expandMasterAuthorizedNetworksConfig(0x15a4f80, 0xc4202586e0, 0x21)
/tmp/GOPATH/src/github.com/terraform-providers/terraform-provider-google/google/resource_container_cluster.go:1355 +0x4f2
github.com/terraform-providers/terraform-provider-google/google.resourceContainerClusterCreate(0xc420146a80, 0x16b1800, 0xc4200b8000, 0x0, 0x0)
/tmp/GOPATH/src/github.com/terraform-providers/terraform-provider-google/google/resource_container_cluster.go:520 +0x2848
github.com/terraform-providers/terraform-provider-google/vendor/github.com/hashicorp/terraform/helper/schema.(*Resource).Apply(0xc420495490, 0xc420341310, 0xc4202582c0, 0x16b1800, 0xc4200b8000, 0x1, 0xc42024eae0, 0xc4201e3650)
/tmp/GOPATH/src/github.com/terraform-providers/terraform-provider-google/vendor/github.com/hashicorp/terraform/helper/schema/resource.go:227 +0x364
github.com/terraform-providers/terraform-provider-google/vendor/github.com/hashicorp/terraform/helper/schema.(*Provider).Apply(0xc4204c6700, 0xc4203412c0, 0xc420341310, 0xc4202582c0, 0x14ee1441a000, 0x0, 0x18)
/tmp/GOPATH/src/github.com/terraform-providers/terraform-provider-google/vendor/github.com/hashicorp/terraform/helper/schema/provider.go:283 +0xa4
github.com/terraform-providers/terraform-provider-google/vendor/github.com/hashicorp/terraform/plugin.(*ResourceProviderServer).Apply(0xc4202d7c40, 0xc42035de80, 0xc42025c160, 0x0, 0x0)
/tmp/GOPATH/src/github.com/terraform-providers/terraform-provider-google/vendor/github.com/hashicorp/terraform/plugin/resource_provider.go:527 +0x57
reflect.Value.call(0xc4203feae0, 0xc42000e038, 0x13, 0x19e88a8, 0x4, 0xc42015ff20, 0x3, 0x3, 0xc420047ee8, 0xc4204c6798, ...)
/usr/local/go/src/reflect/value.go:434 +0x905
reflect.Value.Call(0xc4203feae0, 0xc42000e038, 0x13, 0xc420047f20, 0x3, 0x3, 0xc400000001, 0x0, 0x0)
/usr/local/go/src/reflect/value.go:302 +0xa4
net/rpc.(*service).call(0xc420418600, 0xc42007c140, 0xc42001e798, 0xc4200c4000, 0xc4202d6c40, 0x1557f80, 0xc42035de80, 0x16, 0x1557fc0, 0xc42025c160, ...)
/usr/local/go/src/net/rpc/server.go:381 +0x142
created by net/rpc.(*Server).ServeCodec
/usr/local/go/src/net/rpc/server.go:475 +0x36b
```
which we trigger by altering the first step to contain the HCL notation
for an empty list instead of simply an empty string.
In order to accomplish this, the tests had to be modified to accept an
emptyValue string as well which contains the content of the
`emptyValue` string when the cidrBlocks array is empty. This maintains
the old behavior of the original tests when `emptyValue` is an empty
string, while also facilating differing behavior for the new testcase by
setting `emptyValue` to whichever string we want to test instead. I
don't think this is very clean, but I guess it's pragmatic enough.
I'll hear if this is a thorn in the side to someone :smirk:.
* avoid panic on cidr_block type assertion
This is basically the fix. Since the value can be nil, we want to ensure
we handle a failure during the assertion since we know that asserting
`nil` conforms to `map[string]interface{}` will cause a run-time panic.
* flatten to config on empty list for cidr_blocks
since an empty list for cidrBlocks constitutes valid input, one should
return a map containing an empty list for the cidr_blocks field instead
of a nil value.
The nil value is only appropriate when the input Config is also nil.
2018-08-21 02:29:37 +00:00
|
|
|
cidrBlocks := emptyValue
|
2017-11-02 17:38:20 +00:00
|
|
|
if len(cidrs) > 0 {
|
|
|
|
var buf bytes.Buffer
|
2018-03-01 21:19:18 +00:00
|
|
|
buf.WriteString("cidr_blocks = [")
|
2017-11-02 17:38:20 +00:00
|
|
|
for _, c := range cidrs {
|
|
|
|
buf.WriteString(fmt.Sprintf(`
|
2018-03-01 21:19:18 +00:00
|
|
|
{
|
2017-11-02 17:38:20 +00:00
|
|
|
cidr_block = "%s"
|
2018-03-01 21:19:18 +00:00
|
|
|
display_name = "disp-%s"
|
|
|
|
},`, c, c))
|
2017-11-02 17:38:20 +00:00
|
|
|
}
|
2018-03-01 21:19:18 +00:00
|
|
|
buf.WriteString("]")
|
2017-11-02 17:38:20 +00:00
|
|
|
cidrBlocks = buf.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_master_authorized_networks" {
|
|
|
|
name = "%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 1
|
|
|
|
|
|
|
|
master_authorized_networks_config {
|
|
|
|
%s
|
|
|
|
}
|
|
|
|
}`, clusterName, cidrBlocks)
|
|
|
|
}
|
|
|
|
|
2018-04-05 21:51:35 +00:00
|
|
|
func testAccContainerCluster_regional(clusterName string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "regional" {
|
|
|
|
name = "%s"
|
|
|
|
region = "us-central1"
|
|
|
|
initial_node_count = 1
|
|
|
|
}`, clusterName)
|
|
|
|
}
|
|
|
|
|
#1300 Supporting regional clusters for node pools (#1320)
This PR also switched us to using the beta API in all cases, and that had a side effect which is worth noting, note included here for posterity.
=====
The problem is, we add a GPU, and as per the docs, GKE adds a taint to
the node pool saying "don't schedule here unless you tolerate GPUs",
which is pretty sensible.
Terraform doesn't know about that, because it didn't ask for the taint
to be added. So after apply, on refresh, it sees the state of the world
(1 taint) and the state of the config (0 taints) and wants to set the
world equal to the config. This introduces a diff, which makes the test
fail - tests fail if there's a diff after they run.
Taints are a beta feature, though. :) And since the config doesn't
contain any taints, terraform didn't see any beta features in that node
pool ... so it used to send the request to the v1 API. And since the v1
API didn't return anything about taints (since they're a beta feature),
terraform happily checked the state of the world (0 taints I know about)
vs the config (0 taints), and all was well.
This PR makes every node pool refresh request hit the beta API. So now
terraform finds out about the taints (which were always there) and the
test fails (which it always should have done).
The solution is probably to write a little bit of code which suppresses
the report of the diff of any taint with value 'nvidia.com/gpu', but
only if GPUs are enabled. I think that's something that can be done.
2018-04-25 00:55:21 +00:00
|
|
|
func testAccContainerCluster_regionalWithNodePool(cluster, nodePool string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "regional" {
|
|
|
|
name = "%s"
|
|
|
|
region = "us-central1"
|
|
|
|
|
|
|
|
node_pool {
|
|
|
|
name = "%s"
|
|
|
|
}
|
|
|
|
}`, cluster, nodePool)
|
|
|
|
}
|
|
|
|
|
2017-07-05 23:00:49 +00:00
|
|
|
func testAccContainerCluster_withAdditionalZones(clusterName string) string {
|
|
|
|
return fmt.Sprintf(`
|
2017-01-04 06:14:39 +00:00
|
|
|
resource "google_container_cluster" "with_additional_zones" {
|
2017-07-05 23:00:49 +00:00
|
|
|
name = "%s"
|
2017-01-04 06:14:39 +00:00
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 1
|
|
|
|
|
|
|
|
additional_zones = [
|
|
|
|
"us-central1-b",
|
|
|
|
"us-central1-c"
|
|
|
|
]
|
2017-07-05 23:00:49 +00:00
|
|
|
}`, clusterName)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccContainerCluster_updateAdditionalZones(clusterName string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_additional_zones" {
|
|
|
|
name = "%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 1
|
|
|
|
|
|
|
|
additional_zones = [
|
|
|
|
"us-central1-f",
|
|
|
|
"us-central1-c",
|
|
|
|
]
|
|
|
|
}`, clusterName)
|
|
|
|
}
|
2017-01-04 06:14:39 +00:00
|
|
|
|
2018-04-19 21:17:38 +00:00
|
|
|
func testAccContainerCluster_regionalAdditionalZones(clusterName string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_additional_zones" {
|
|
|
|
name = "%s"
|
|
|
|
region = "us-central1"
|
|
|
|
initial_node_count = 1
|
|
|
|
|
|
|
|
additional_zones = [
|
|
|
|
"us-central1-f",
|
|
|
|
"us-central1-c",
|
|
|
|
]
|
|
|
|
}`, clusterName)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccContainerCluster_regionalUpdateAdditionalZones(clusterName string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_additional_zones" {
|
|
|
|
name = "%s"
|
|
|
|
region = "us-central1"
|
|
|
|
initial_node_count = 1
|
|
|
|
|
|
|
|
additional_zones = [
|
|
|
|
"us-central1-f",
|
|
|
|
"us-central1-b",
|
|
|
|
]
|
|
|
|
}`, clusterName)
|
|
|
|
}
|
|
|
|
|
2017-10-31 23:38:18 +00:00
|
|
|
func testAccContainerCluster_withKubernetesAlpha(clusterName string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_kubernetes_alpha" {
|
|
|
|
name = "cluster-test-%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 1
|
|
|
|
|
|
|
|
enable_kubernetes_alpha = true
|
|
|
|
}`, clusterName)
|
|
|
|
}
|
|
|
|
|
2018-10-01 16:41:54 +00:00
|
|
|
func testAccContainerCluster_withTpu(clusterName string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_network" "container_network" {
|
|
|
|
name = "container-net-%s"
|
|
|
|
auto_create_subnetworks = false
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_subnetwork" "container_subnetwork" {
|
|
|
|
name = "${google_compute_network.container_network.name}"
|
|
|
|
network = "${google_compute_network.container_network.name}"
|
|
|
|
ip_cidr_range = "10.0.35.0/24"
|
|
|
|
region = "us-central1"
|
|
|
|
|
|
|
|
secondary_ip_range {
|
|
|
|
range_name = "pod"
|
|
|
|
ip_cidr_range = "10.1.0.0/19"
|
|
|
|
}
|
|
|
|
|
|
|
|
secondary_ip_range {
|
|
|
|
range_name = "svc"
|
|
|
|
ip_cidr_range = "10.2.0.0/22"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_container_cluster" "with_tpu" {
|
|
|
|
name = "cluster-test-%s"
|
|
|
|
zone = "us-central1-b"
|
|
|
|
initial_node_count = 1
|
|
|
|
|
|
|
|
enable_tpu = true
|
|
|
|
|
|
|
|
network = "${google_compute_network.container_network.name}"
|
|
|
|
subnetwork = "${google_compute_subnetwork.container_subnetwork.name}"
|
|
|
|
|
|
|
|
master_ipv4_cidr_block = "10.42.0.0/28"
|
|
|
|
master_authorized_networks_config { cidr_blocks = [] }
|
|
|
|
ip_allocation_policy {
|
|
|
|
cluster_secondary_range_name = "${google_compute_subnetwork.container_subnetwork.secondary_ip_range.0.range_name}"
|
|
|
|
services_secondary_range_name = "${google_compute_subnetwork.container_subnetwork.secondary_ip_range.1.range_name}"
|
|
|
|
}
|
|
|
|
}`, clusterName, clusterName)
|
|
|
|
}
|
|
|
|
|
2018-04-04 17:58:08 +00:00
|
|
|
func testAccContainerCluster_defaultLegacyAbac(clusterName string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "default_legacy_abac" {
|
|
|
|
name = "cluster-test-%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 1
|
|
|
|
}`, clusterName)
|
|
|
|
}
|
|
|
|
|
2017-07-31 18:09:05 +00:00
|
|
|
func testAccContainerCluster_withLegacyAbac(clusterName string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_legacy_abac" {
|
|
|
|
name = "cluster-test-%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 1
|
|
|
|
|
|
|
|
enable_legacy_abac = true
|
|
|
|
}`, clusterName)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccContainerCluster_updateLegacyAbac(clusterName string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_legacy_abac" {
|
|
|
|
name = "cluster-test-%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 1
|
|
|
|
|
|
|
|
enable_legacy_abac = false
|
|
|
|
}`, clusterName)
|
|
|
|
}
|
|
|
|
|
2017-08-08 18:31:12 +00:00
|
|
|
func testAccContainerCluster_withVersion(clusterName string) string {
|
|
|
|
return fmt.Sprintf(`
|
2017-05-10 22:01:15 +00:00
|
|
|
data "google_container_engine_versions" "central1a" {
|
2017-05-08 07:38:11 +00:00
|
|
|
zone = "us-central1-a"
|
|
|
|
}
|
|
|
|
|
2016-12-18 13:50:46 +00:00
|
|
|
resource "google_container_cluster" "with_version" {
|
|
|
|
name = "cluster-test-%s"
|
|
|
|
zone = "us-central1-a"
|
2017-10-12 18:21:33 +00:00
|
|
|
min_master_version = "${data.google_container_engine_versions.central1a.latest_master_version}"
|
2016-12-18 13:50:46 +00:00
|
|
|
initial_node_count = 1
|
2017-08-08 18:31:12 +00:00
|
|
|
}`, clusterName)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccContainerCluster_withLowerVersion(clusterName string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
data "google_container_engine_versions" "central1a" {
|
|
|
|
zone = "us-central1-a"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_container_cluster" "with_version" {
|
|
|
|
name = "cluster-test-%s"
|
|
|
|
zone = "us-central1-a"
|
2017-10-12 18:21:33 +00:00
|
|
|
min_master_version = "${data.google_container_engine_versions.central1a.valid_master_versions.2}"
|
2017-10-06 22:48:01 +00:00
|
|
|
initial_node_count = 1
|
|
|
|
}`, clusterName)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccContainerCluster_updateVersion(clusterName string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
data "google_container_engine_versions" "central1a" {
|
|
|
|
zone = "us-central1-a"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_container_cluster" "with_version" {
|
|
|
|
name = "cluster-test-%s"
|
|
|
|
zone = "us-central1-a"
|
2017-10-12 18:21:33 +00:00
|
|
|
min_master_version = "${data.google_container_engine_versions.central1a.valid_master_versions.1}"
|
|
|
|
node_version = "${data.google_container_engine_versions.central1a.valid_node_versions.1}"
|
2017-08-08 18:31:12 +00:00
|
|
|
initial_node_count = 1
|
|
|
|
}`, clusterName)
|
|
|
|
}
|
2016-12-18 13:50:46 +00:00
|
|
|
|
2018-08-07 21:07:28 +00:00
|
|
|
func testAccContainerCluster_withNodeConfig(clusterName string) string {
|
2017-11-28 00:32:00 +00:00
|
|
|
return fmt.Sprintf(`
|
2015-08-20 20:40:38 +00:00
|
|
|
resource "google_container_cluster" "with_node_config" {
|
2018-08-07 21:07:28 +00:00
|
|
|
name = "%s"
|
2015-08-20 20:40:38 +00:00
|
|
|
zone = "us-central1-f"
|
|
|
|
initial_node_count = 1
|
|
|
|
|
|
|
|
node_config {
|
2017-02-27 15:03:55 +00:00
|
|
|
machine_type = "n1-standard-1"
|
2015-08-20 20:40:38 +00:00
|
|
|
disk_size_gb = 15
|
2018-06-15 20:21:51 +00:00
|
|
|
disk_type = "pd-ssd"
|
2017-02-27 15:03:55 +00:00
|
|
|
local_ssd_count = 1
|
2015-08-20 20:40:38 +00:00
|
|
|
oauth_scopes = [
|
2017-10-25 20:41:42 +00:00
|
|
|
"https://www.googleapis.com/auth/monitoring",
|
2015-08-20 20:40:38 +00:00
|
|
|
"https://www.googleapis.com/auth/compute",
|
|
|
|
"https://www.googleapis.com/auth/devstorage.read_only",
|
2017-10-25 20:41:42 +00:00
|
|
|
"https://www.googleapis.com/auth/logging.write"
|
2015-08-20 20:40:38 +00:00
|
|
|
]
|
2017-02-15 01:45:53 +00:00
|
|
|
service_account = "default"
|
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
2018-08-07 21:07:28 +00:00
|
|
|
labels {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
tags = ["foo", "bar"]
|
|
|
|
preemptible = true
|
|
|
|
min_cpu_platform = "Intel Broadwell"
|
|
|
|
|
|
|
|
// Updatable fields
|
2017-09-01 20:02:26 +00:00
|
|
|
image_type = "COS"
|
2018-08-07 21:07:28 +00:00
|
|
|
}
|
|
|
|
}`, clusterName)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccContainerCluster_withNodeConfigUpdate(clusterName string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_node_config" {
|
|
|
|
name = "%s"
|
|
|
|
zone = "us-central1-f"
|
|
|
|
initial_node_count = 1
|
|
|
|
|
|
|
|
node_config {
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
disk_size_gb = 15
|
|
|
|
disk_type = "pd-ssd"
|
|
|
|
local_ssd_count = 1
|
|
|
|
oauth_scopes = [
|
|
|
|
"https://www.googleapis.com/auth/monitoring",
|
|
|
|
"https://www.googleapis.com/auth/compute",
|
|
|
|
"https://www.googleapis.com/auth/devstorage.read_only",
|
|
|
|
"https://www.googleapis.com/auth/logging.write"
|
|
|
|
]
|
|
|
|
service_account = "default"
|
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
2017-06-12 14:29:30 +00:00
|
|
|
labels {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
tags = ["foo", "bar"]
|
2017-09-01 20:02:26 +00:00
|
|
|
preemptible = true
|
2017-10-25 21:08:48 +00:00
|
|
|
min_cpu_platform = "Intel Broadwell"
|
2018-08-07 21:07:28 +00:00
|
|
|
|
|
|
|
// Updatable fields
|
|
|
|
image_type = "UBUNTU"
|
2015-08-20 20:40:38 +00:00
|
|
|
}
|
2018-08-07 21:07:28 +00:00
|
|
|
}`, clusterName)
|
2017-11-28 00:32:00 +00:00
|
|
|
}
|
2016-09-03 09:51:20 +00:00
|
|
|
|
2017-11-28 00:32:00 +00:00
|
|
|
func testAccContainerCluster_withNodeConfigScopeAlias() string {
|
|
|
|
return fmt.Sprintf(`
|
2016-11-14 23:50:24 +00:00
|
|
|
resource "google_container_cluster" "with_node_config_scope_alias" {
|
|
|
|
name = "cluster-test-%s"
|
|
|
|
zone = "us-central1-f"
|
|
|
|
initial_node_count = 1
|
|
|
|
|
|
|
|
node_config {
|
|
|
|
machine_type = "g1-small"
|
|
|
|
disk_size_gb = 15
|
|
|
|
oauth_scopes = [ "compute-rw", "storage-ro", "logging-write", "monitoring" ]
|
|
|
|
}
|
|
|
|
}`, acctest.RandString(10))
|
2017-11-28 00:32:00 +00:00
|
|
|
}
|
2016-11-14 23:50:24 +00:00
|
|
|
|
2018-03-27 21:55:42 +00:00
|
|
|
func testAccContainerCluster_withNodeConfigTaints() string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_node_config" {
|
|
|
|
name = "cluster-test-%s"
|
|
|
|
zone = "us-central1-f"
|
|
|
|
initial_node_count = 1
|
|
|
|
|
|
|
|
node_config {
|
|
|
|
taint {
|
|
|
|
key = "taint_key"
|
|
|
|
value = "taint_value"
|
|
|
|
effect = "PREFER_NO_SCHEDULE"
|
|
|
|
}
|
|
|
|
taint {
|
|
|
|
key = "taint_key2"
|
|
|
|
value = "taint_value2"
|
|
|
|
effect = "NO_EXECUTE"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`, acctest.RandString(10))
|
|
|
|
}
|
|
|
|
|
2018-03-15 20:28:30 +00:00
|
|
|
func testAccContainerCluster_withWorkloadMetadataConfig() string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
data "google_container_engine_versions" "central1a" {
|
|
|
|
zone = "us-central1-a"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_container_cluster" "with_workload_metadata_config" {
|
|
|
|
name = "cluster-test-%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 1
|
|
|
|
min_master_version = "${data.google_container_engine_versions.central1a.latest_master_version}"
|
|
|
|
node_version = "${data.google_container_engine_versions.central1a.latest_node_version}"
|
|
|
|
|
|
|
|
node_config {
|
|
|
|
oauth_scopes = [
|
|
|
|
"https://www.googleapis.com/auth/logging.write",
|
|
|
|
"https://www.googleapis.com/auth/monitoring"
|
|
|
|
]
|
|
|
|
|
|
|
|
workload_metadata_config {
|
|
|
|
node_metadata = "SECURE"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, acctest.RandString(10))
|
|
|
|
}
|
|
|
|
|
2017-11-28 00:32:00 +00:00
|
|
|
func testAccContainerCluster_networkRef() string {
|
|
|
|
return fmt.Sprintf(`
|
2016-09-03 09:51:20 +00:00
|
|
|
resource "google_compute_network" "container_network" {
|
|
|
|
name = "container-net-%s"
|
|
|
|
auto_create_subnetworks = true
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_container_cluster" "with_net_ref_by_url" {
|
|
|
|
name = "cluster-test-%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 1
|
|
|
|
|
|
|
|
network = "${google_compute_network.container_network.self_link}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_container_cluster" "with_net_ref_by_name" {
|
|
|
|
name = "cluster-test-%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 1
|
|
|
|
|
|
|
|
network = "${google_compute_network.container_network.name}"
|
|
|
|
}`, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10))
|
2017-11-28 00:32:00 +00:00
|
|
|
}
|
2017-03-07 05:14:32 +00:00
|
|
|
|
2017-11-28 00:32:00 +00:00
|
|
|
func testAccContainerCluster_backendRef() string {
|
|
|
|
return fmt.Sprintf(`
|
2017-03-07 05:14:32 +00:00
|
|
|
resource "google_compute_backend_service" "my-backend-service" {
|
|
|
|
name = "terraform-test-%s"
|
|
|
|
port_name = "http"
|
|
|
|
protocol = "HTTP"
|
|
|
|
|
|
|
|
backend {
|
|
|
|
group = "${element(google_container_cluster.primary.instance_group_urls, 1)}"
|
|
|
|
}
|
|
|
|
|
|
|
|
health_checks = ["${google_compute_http_health_check.default.self_link}"]
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_http_health_check" "default" {
|
|
|
|
name = "terraform-test-%s"
|
|
|
|
request_path = "/"
|
|
|
|
check_interval_sec = 1
|
|
|
|
timeout_sec = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_container_cluster" "primary" {
|
|
|
|
name = "terraform-test-%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 3
|
|
|
|
|
|
|
|
additional_zones = [
|
|
|
|
"us-central1-b",
|
|
|
|
"us-central1-c",
|
|
|
|
]
|
|
|
|
|
|
|
|
node_config {
|
|
|
|
oauth_scopes = [
|
|
|
|
"https://www.googleapis.com/auth/compute",
|
|
|
|
"https://www.googleapis.com/auth/devstorage.read_only",
|
|
|
|
"https://www.googleapis.com/auth/logging.write",
|
|
|
|
"https://www.googleapis.com/auth/monitoring",
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10))
|
2017-11-28 00:32:00 +00:00
|
|
|
}
|
2017-04-12 19:57:53 +00:00
|
|
|
|
2017-08-18 22:29:51 +00:00
|
|
|
func testAccContainerCluster_withLogging(clusterName string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_logging" {
|
|
|
|
name = "cluster-test-%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 1
|
|
|
|
|
|
|
|
logging_service = "logging.googleapis.com"
|
|
|
|
}`, clusterName)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccContainerCluster_updateLogging(clusterName string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_logging" {
|
|
|
|
name = "cluster-test-%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 1
|
|
|
|
|
|
|
|
logging_service = "none"
|
|
|
|
}`, clusterName)
|
|
|
|
}
|
|
|
|
|
2017-10-20 16:46:21 +00:00
|
|
|
func testAccContainerCluster_withMonitoring(clusterName string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_monitoring" {
|
|
|
|
name = "cluster-test-%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 1
|
|
|
|
|
|
|
|
monitoring_service = "monitoring.googleapis.com"
|
|
|
|
}`, clusterName)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccContainerCluster_updateMonitoring(clusterName string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_monitoring" {
|
|
|
|
name = "cluster-test-%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 1
|
|
|
|
|
|
|
|
monitoring_service = "none"
|
|
|
|
}`, clusterName)
|
|
|
|
}
|
|
|
|
|
2017-10-04 00:09:34 +00:00
|
|
|
func testAccContainerCluster_withNodePoolBasic(cluster, nodePool string) string {
|
|
|
|
return fmt.Sprintf(`
|
2017-04-12 19:57:53 +00:00
|
|
|
resource "google_container_cluster" "with_node_pool" {
|
2017-10-04 00:09:34 +00:00
|
|
|
name = "%s"
|
2017-04-12 19:57:53 +00:00
|
|
|
zone = "us-central1-a"
|
|
|
|
|
|
|
|
node_pool {
|
2017-10-04 00:09:34 +00:00
|
|
|
name = "%s"
|
2017-04-12 19:57:53 +00:00
|
|
|
initial_node_count = 2
|
|
|
|
}
|
2017-10-04 00:09:34 +00:00
|
|
|
}`, cluster, nodePool)
|
|
|
|
}
|
2017-04-12 19:57:53 +00:00
|
|
|
|
2017-08-18 00:51:58 +00:00
|
|
|
func testAccContainerCluster_withNodePoolAdditionalZones(cluster, nodePool string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_node_pool" {
|
|
|
|
name = "%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
|
|
|
|
additional_zones = [
|
|
|
|
"us-central1-b",
|
|
|
|
"us-central1-c"
|
|
|
|
]
|
|
|
|
|
|
|
|
node_pool {
|
|
|
|
name = "%s"
|
|
|
|
node_count = 2
|
|
|
|
}
|
|
|
|
}`, cluster, nodePool)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccContainerCluster_withNodePoolResize(cluster, nodePool string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_node_pool" {
|
|
|
|
name = "%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
|
|
|
|
additional_zones = [
|
|
|
|
"us-central1-b",
|
|
|
|
"us-central1-c"
|
|
|
|
]
|
|
|
|
|
|
|
|
node_pool {
|
|
|
|
name = "%s"
|
|
|
|
node_count = 3
|
|
|
|
}
|
|
|
|
}`, cluster, nodePool)
|
|
|
|
}
|
|
|
|
|
2017-10-04 00:09:34 +00:00
|
|
|
func testAccContainerCluster_withNodePoolAutoscaling(cluster, np string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_node_pool" {
|
|
|
|
name = "%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
|
|
|
|
node_pool {
|
|
|
|
name = "%s"
|
|
|
|
initial_node_count = 2
|
|
|
|
autoscaling {
|
|
|
|
min_node_count = 1
|
|
|
|
max_node_count = 3
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`, cluster, np)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccContainerCluster_withNodePoolUpdateAutoscaling(cluster, np string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_node_pool" {
|
|
|
|
name = "%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
|
|
|
|
node_pool {
|
|
|
|
name = "%s"
|
|
|
|
initial_node_count = 2
|
|
|
|
autoscaling {
|
|
|
|
min_node_count = 1
|
|
|
|
max_node_count = 5
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`, cluster, np)
|
|
|
|
}
|
|
|
|
|
2017-11-28 00:32:00 +00:00
|
|
|
func testAccContainerCluster_withNodePoolMultiple() string {
|
|
|
|
return fmt.Sprintf(`
|
2017-04-12 19:57:53 +00:00
|
|
|
resource "google_container_cluster" "with_node_pool_multiple" {
|
|
|
|
name = "tf-cluster-nodepool-test-%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
|
|
|
|
node_pool {
|
2017-08-18 00:51:58 +00:00
|
|
|
name = "tf-cluster-nodepool-test-%s"
|
|
|
|
node_count = 2
|
2017-04-12 19:57:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
node_pool {
|
2017-08-18 00:51:58 +00:00
|
|
|
name = "tf-cluster-nodepool-test-%s"
|
|
|
|
node_count = 3
|
2017-04-12 19:57:53 +00:00
|
|
|
}
|
|
|
|
}`, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10))
|
2017-11-28 00:32:00 +00:00
|
|
|
}
|
2017-08-04 22:34:02 +00:00
|
|
|
|
2017-08-11 19:23:17 +00:00
|
|
|
func testAccContainerCluster_withNodePoolNodeConfig() string {
|
|
|
|
testId := acctest.RandString(10)
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_node_pool_node_config" {
|
|
|
|
name = "tf-cluster-nodepool-test-%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
node_pool {
|
|
|
|
name = "tf-cluster-nodepool-test-%s"
|
2017-08-18 00:51:58 +00:00
|
|
|
node_count = 2
|
2017-08-11 19:23:17 +00:00
|
|
|
node_config {
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
disk_size_gb = 15
|
|
|
|
local_ssd_count = 1
|
|
|
|
oauth_scopes = [
|
|
|
|
"https://www.googleapis.com/auth/compute",
|
|
|
|
"https://www.googleapis.com/auth/devstorage.read_only",
|
|
|
|
"https://www.googleapis.com/auth/logging.write",
|
|
|
|
"https://www.googleapis.com/auth/monitoring"
|
|
|
|
]
|
|
|
|
service_account = "default"
|
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
2017-09-01 20:02:26 +00:00
|
|
|
image_type = "COS"
|
2017-08-11 19:23:17 +00:00
|
|
|
labels {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
tags = ["foo", "bar"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
`, testId, testId)
|
|
|
|
}
|
2017-11-07 23:42:11 +00:00
|
|
|
|
2018-03-23 00:22:44 +00:00
|
|
|
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))
|
|
|
|
}
|
|
|
|
|
2017-12-27 20:29:14 +00:00
|
|
|
func testAccContainerCluster_withMaintenanceWindow(clusterName string, startTime string) string {
|
|
|
|
maintenancePolicy := ""
|
|
|
|
if len(startTime) > 0 {
|
|
|
|
maintenancePolicy = fmt.Sprintf(`
|
|
|
|
maintenance_policy {
|
|
|
|
daily_maintenance_window {
|
|
|
|
start_time = "%s"
|
|
|
|
}
|
|
|
|
}`, startTime)
|
|
|
|
}
|
|
|
|
|
2017-11-07 23:42:11 +00:00
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_maintenance_window" {
|
|
|
|
name = "cluster-test-%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 1
|
2017-11-27 23:15:03 +00:00
|
|
|
|
2017-12-27 20:29:14 +00:00
|
|
|
%s
|
|
|
|
}`, clusterName, maintenancePolicy)
|
2017-11-07 23:42:11 +00:00
|
|
|
}
|
2017-11-27 23:15:03 +00:00
|
|
|
|
2018-09-05 16:52:06 +00:00
|
|
|
func testAccContainerCluster_withIPAllocationPolicy_existingSecondaryRanges(cluster string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_network" "container_network" {
|
|
|
|
name = "container-net-%s"
|
|
|
|
auto_create_subnetworks = false
|
|
|
|
}
|
2017-11-27 23:15:03 +00:00
|
|
|
|
2018-09-05 16:52:06 +00:00
|
|
|
resource "google_compute_subnetwork" "container_subnetwork" {
|
|
|
|
name = "${google_compute_network.container_network.name}"
|
|
|
|
network = "${google_compute_network.container_network.name}"
|
|
|
|
ip_cidr_range = "10.0.0.0/24"
|
|
|
|
region = "us-central1"
|
|
|
|
|
|
|
|
secondary_ip_range {
|
|
|
|
range_name = "pods"
|
|
|
|
ip_cidr_range = "10.1.0.0/16"
|
|
|
|
}
|
2017-11-27 23:15:03 +00:00
|
|
|
secondary_ip_range {
|
2018-09-05 16:52:06 +00:00
|
|
|
range_name = "services"
|
|
|
|
ip_cidr_range = "10.2.0.0/20"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_container_cluster" "with_ip_allocation_policy" {
|
|
|
|
name = "%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
|
|
|
|
network = "${google_compute_network.container_network.name}"
|
|
|
|
subnetwork = "${google_compute_subnetwork.container_subnetwork.name}"
|
|
|
|
|
|
|
|
initial_node_count = 1
|
|
|
|
ip_allocation_policy {
|
|
|
|
cluster_secondary_range_name = "pods"
|
|
|
|
services_secondary_range_name = "services"
|
2017-11-27 23:15:03 +00:00
|
|
|
}
|
2018-09-05 16:52:06 +00:00
|
|
|
}`, cluster, cluster)
|
|
|
|
}
|
2017-11-27 23:15:03 +00:00
|
|
|
|
2018-09-05 16:52:06 +00:00
|
|
|
func testAccContainerCluster_withIPAllocationPolicy_specificIPRanges(cluster string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_ip_allocation_policy" {
|
|
|
|
name = "%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
|
|
|
|
initial_node_count = 1
|
|
|
|
ip_allocation_policy {
|
|
|
|
cluster_ipv4_cidr_block = "10.90.0.0/19"
|
|
|
|
services_ipv4_cidr_block = "10.40.0.0/19"
|
2017-11-27 23:15:03 +00:00
|
|
|
}
|
2018-09-05 16:52:06 +00:00
|
|
|
}`, cluster)
|
|
|
|
}
|
2017-11-27 23:15:03 +00:00
|
|
|
|
2018-09-05 16:52:06 +00:00
|
|
|
func testAccContainerCluster_withIPAllocationPolicy_specificSizes(cluster string) string {
|
2017-11-27 23:15:03 +00:00
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_network" "container_network" {
|
|
|
|
name = "container-net-%s"
|
|
|
|
auto_create_subnetworks = false
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_subnetwork" "container_subnetwork" {
|
|
|
|
name = "${google_compute_network.container_network.name}"
|
|
|
|
network = "${google_compute_network.container_network.name}"
|
|
|
|
ip_cidr_range = "10.0.0.0/24"
|
|
|
|
region = "us-central1"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_container_cluster" "with_ip_allocation_policy" {
|
|
|
|
name = "%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
|
|
|
|
network = "${google_compute_network.container_network.name}"
|
|
|
|
subnetwork = "${google_compute_subnetwork.container_subnetwork.name}"
|
|
|
|
|
|
|
|
initial_node_count = 1
|
|
|
|
ip_allocation_policy {
|
2018-09-05 16:52:06 +00:00
|
|
|
cluster_ipv4_cidr_block = "/16"
|
|
|
|
services_ipv4_cidr_block = "/22"
|
|
|
|
}
|
|
|
|
}`, cluster, cluster)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccContainerCluster_withIPAllocationPolicy_createSubnetwork(cluster string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_ip_allocation_policy" {
|
|
|
|
name = "%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
|
|
|
|
initial_node_count = 1
|
|
|
|
ip_allocation_policy {
|
|
|
|
create_subnetwork = true
|
2017-11-27 23:15:03 +00:00
|
|
|
}
|
2018-09-05 16:52:06 +00:00
|
|
|
}`, cluster)
|
2017-11-27 23:15:03 +00:00
|
|
|
}
|
2018-03-14 21:00:31 +00:00
|
|
|
|
|
|
|
func testAccContainerCluster_withPodSecurityPolicy(clusterName string, enabled bool) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_pod_security_policy" {
|
|
|
|
name = "cluster-test-%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 1
|
|
|
|
|
|
|
|
pod_security_policy_config {
|
|
|
|
enabled = %v
|
|
|
|
}
|
|
|
|
}`, clusterName, enabled)
|
|
|
|
}
|
2018-03-30 17:10:25 +00:00
|
|
|
|
|
|
|
func testAccContainerCluster_withPrivateCluster(clusterName string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_network" "container_network" {
|
|
|
|
name = "container-net-%s"
|
|
|
|
auto_create_subnetworks = false
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_subnetwork" "container_subnetwork" {
|
|
|
|
name = "${google_compute_network.container_network.name}"
|
|
|
|
network = "${google_compute_network.container_network.name}"
|
|
|
|
ip_cidr_range = "10.0.36.0/24"
|
|
|
|
region = "us-central1"
|
|
|
|
private_ip_google_access = true
|
|
|
|
|
|
|
|
secondary_ip_range {
|
|
|
|
range_name = "pod"
|
|
|
|
ip_cidr_range = "10.0.0.0/19"
|
|
|
|
}
|
|
|
|
|
|
|
|
secondary_ip_range {
|
|
|
|
range_name = "svc"
|
|
|
|
ip_cidr_range = "10.0.32.0/22"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_container_cluster" "with_private_cluster" {
|
|
|
|
name = "cluster-test-%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 1
|
|
|
|
|
|
|
|
network = "${google_compute_network.container_network.name}"
|
|
|
|
subnetwork = "${google_compute_subnetwork.container_subnetwork.name}"
|
|
|
|
|
|
|
|
private_cluster = true
|
|
|
|
master_ipv4_cidr_block = "10.42.0.0/28"
|
2018-09-13 00:58:11 +00:00
|
|
|
master_authorized_networks_config { cidr_blocks = [] }
|
2018-03-30 17:10:25 +00:00
|
|
|
ip_allocation_policy {
|
|
|
|
cluster_secondary_range_name = "${google_compute_subnetwork.container_subnetwork.secondary_ip_range.0.range_name}"
|
|
|
|
services_secondary_range_name = "${google_compute_subnetwork.container_subnetwork.secondary_ip_range.1.range_name}"
|
|
|
|
}
|
|
|
|
}`, clusterName, clusterName)
|
|
|
|
}
|
2018-05-23 23:47:17 +00:00
|
|
|
func testAccContainerCluster_sharedVpc(org, billingId, projectName, name string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_project" "host_project" {
|
|
|
|
name = "Test Project XPN Host"
|
|
|
|
project_id = "%s-host"
|
|
|
|
org_id = "%s"
|
|
|
|
billing_account = "%s"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_project_service" "host_project" {
|
|
|
|
project = "${google_project.host_project.project_id}"
|
|
|
|
service = "container.googleapis.com"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_shared_vpc_host_project" "host_project" {
|
|
|
|
project = "${google_project_service.host_project.project}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_project" "service_project" {
|
|
|
|
name = "Test Project XPN Service"
|
|
|
|
project_id = "%s-service"
|
|
|
|
org_id = "%s"
|
|
|
|
billing_account = "%s"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_project_service" "service_project" {
|
|
|
|
project = "${google_project.service_project.project_id}"
|
|
|
|
service = "container.googleapis.com"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_shared_vpc_service_project" "service_project" {
|
|
|
|
host_project = "${google_compute_shared_vpc_host_project.host_project.project}"
|
|
|
|
service_project = "${google_project_service.service_project.project}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_project_iam_member" "host_service_agent" {
|
|
|
|
project = "${google_project_service.host_project.project}"
|
|
|
|
role = "roles/container.hostServiceAgentUser"
|
|
|
|
member = "serviceAccount:service-${google_project.service_project.number}@container-engine-robot.iam.gserviceaccount.com"
|
|
|
|
|
|
|
|
depends_on = ["google_project_service.service_project"]
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_subnetwork_iam_member" "service_network_cloud_services" {
|
|
|
|
project = "${google_compute_shared_vpc_host_project.host_project.project}"
|
|
|
|
subnetwork = "${google_compute_subnetwork.shared_subnetwork.name}"
|
|
|
|
role = "roles/compute.networkUser"
|
|
|
|
member = "serviceAccount:${google_project.service_project.number}@cloudservices.gserviceaccount.com"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_subnetwork_iam_member" "service_network_gke_user" {
|
|
|
|
project = "${google_compute_shared_vpc_host_project.host_project.project}"
|
|
|
|
subnetwork = "${google_compute_subnetwork.shared_subnetwork.name}"
|
|
|
|
role = "roles/compute.networkUser"
|
|
|
|
member = "serviceAccount:service-${google_project.service_project.number}@container-engine-robot.iam.gserviceaccount.com"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_network" "shared_network" {
|
|
|
|
name = "test-%s"
|
|
|
|
project = "${google_compute_shared_vpc_host_project.host_project.project}"
|
|
|
|
|
|
|
|
auto_create_subnetworks = false
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_subnetwork" "shared_subnetwork" {
|
|
|
|
name = "test-%s"
|
|
|
|
ip_cidr_range = "10.0.0.0/16"
|
|
|
|
region = "us-central1"
|
|
|
|
network = "${google_compute_network.shared_network.self_link}"
|
|
|
|
project = "${google_compute_shared_vpc_host_project.host_project.project}"
|
|
|
|
|
|
|
|
secondary_ip_range {
|
|
|
|
range_name = "pods"
|
|
|
|
ip_cidr_range = "10.1.0.0/16"
|
|
|
|
}
|
|
|
|
|
|
|
|
secondary_ip_range {
|
|
|
|
range_name = "services"
|
|
|
|
ip_cidr_range = "10.2.0.0/20"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_container_cluster" "shared_vpc_cluster" {
|
|
|
|
name = "%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 1
|
|
|
|
project = "${google_compute_shared_vpc_service_project.service_project.service_project}"
|
|
|
|
|
|
|
|
network = "${google_compute_network.shared_network.self_link}"
|
|
|
|
subnetwork = "${google_compute_subnetwork.shared_subnetwork.self_link}"
|
|
|
|
|
|
|
|
ip_allocation_policy {
|
|
|
|
cluster_secondary_range_name = "${google_compute_subnetwork.shared_subnetwork.secondary_ip_range.0.range_name}"
|
|
|
|
services_secondary_range_name = "${google_compute_subnetwork.shared_subnetwork.secondary_ip_range.1.range_name}"
|
|
|
|
}
|
|
|
|
|
|
|
|
depends_on = [
|
|
|
|
"google_project_iam_member.host_service_agent",
|
|
|
|
"google_compute_subnetwork_iam_member.service_network_cloud_services",
|
|
|
|
"google_compute_subnetwork_iam_member.service_network_gke_user"
|
|
|
|
]
|
|
|
|
}`, projectName, org, billingId, projectName, org, billingId, acctest.RandString(10), acctest.RandString(10), name)
|
|
|
|
}
|
2018-06-15 10:10:25 +00:00
|
|
|
|
2018-07-13 09:27:40 +00:00
|
|
|
func testAccContainerCluster_withoutResourceLabels(clusterName string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_resource_labels" {
|
|
|
|
name = "%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 1
|
|
|
|
}
|
|
|
|
`, clusterName)
|
|
|
|
}
|
|
|
|
|
2018-06-25 08:55:27 +00:00
|
|
|
func testAccContainerCluster_withResourceLabels(clusterName string) string {
|
2018-06-15 10:10:25 +00:00
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_resource_labels" {
|
2018-06-25 08:55:27 +00:00
|
|
|
name = "%s"
|
2018-06-15 10:10:25 +00:00
|
|
|
zone = "us-central1-a"
|
2018-06-25 08:55:27 +00:00
|
|
|
initial_node_count = 1
|
|
|
|
|
|
|
|
resource_labels {
|
|
|
|
created-by = "terraform"
|
|
|
|
}
|
2018-06-15 10:10:25 +00:00
|
|
|
}
|
2018-06-25 08:55:27 +00:00
|
|
|
`, clusterName)
|
2018-06-15 10:10:25 +00:00
|
|
|
}
|
2018-08-17 00:51:03 +00:00
|
|
|
|
|
|
|
func testAccContainerCluster_withBinaryAuthorization(clusterName string, enabled bool) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_binary_authorization" {
|
|
|
|
name = "%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 1
|
|
|
|
|
|
|
|
enable_binary_authorization = %v
|
|
|
|
}
|
|
|
|
`, clusterName, enabled)
|
|
|
|
}
|