2015-07-05 18:39:01 +02:00
|
|
|
package google
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2017-03-07 06:14:32 +01:00
|
|
|
"strconv"
|
|
|
|
|
2016-01-05 22:47:10 +01:00
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
2015-07-05 18:39:01 +02:00
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAccContainerCluster_basic(t *testing.T) {
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccContainerCluster_basic,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
2017-03-15 01:50:58 +01:00
|
|
|
testAccCheckContainerCluster(
|
2015-07-05 18:39:01 +02:00
|
|
|
"google_container_cluster.primary"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-01-04 07:14:39 +01:00
|
|
|
func TestAccContainerCluster_withAdditionalZones(t *testing.T) {
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccContainerCluster_withAdditionalZones,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
2017-03-15 01:50:58 +01:00
|
|
|
testAccCheckContainerCluster(
|
2017-01-04 07:14:39 +01:00
|
|
|
"google_container_cluster.with_additional_zones"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-12-18 14:50:46 +01:00
|
|
|
func TestAccContainerCluster_withVersion(t *testing.T) {
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccContainerCluster_withVersion,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
2017-03-15 01:50:58 +01:00
|
|
|
testAccCheckContainerCluster(
|
2016-12-18 14:50:46 +01:00
|
|
|
"google_container_cluster.with_version"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-08-20 22:40:38 +02:00
|
|
|
func TestAccContainerCluster_withNodeConfig(t *testing.T) {
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccContainerCluster_withNodeConfig,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
2017-03-15 01:50:58 +01:00
|
|
|
testAccCheckContainerCluster(
|
2015-08-20 22:40:38 +02:00
|
|
|
"google_container_cluster.with_node_config"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-11-15 00:50:24 +01:00
|
|
|
func TestAccContainerCluster_withNodeConfigScopeAlias(t *testing.T) {
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccContainerCluster_withNodeConfigScopeAlias,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
2017-03-15 01:50:58 +01:00
|
|
|
testAccCheckContainerCluster(
|
2016-11-15 00:50:24 +01:00
|
|
|
"google_container_cluster.with_node_config_scope_alias"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-09-03 11:51:20 +02:00
|
|
|
func TestAccContainerCluster_network(t *testing.T) {
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccContainerCluster_networkRef,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
2017-03-15 01:50:58 +01:00
|
|
|
testAccCheckContainerCluster(
|
2016-09-03 11:51:20 +02:00
|
|
|
"google_container_cluster.with_net_ref_by_url"),
|
2017-03-15 01:50:58 +01:00
|
|
|
testAccCheckContainerCluster(
|
2016-09-03 11:51:20 +02:00
|
|
|
"google_container_cluster.with_net_ref_by_name"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-03-07 06:14:32 +01:00
|
|
|
func TestAccContainerCluster_backend(t *testing.T) {
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccContainerCluster_backendRef,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
2017-03-15 01:50:58 +01:00
|
|
|
testAccCheckContainerCluster(
|
2017-03-07 06:14:32 +01:00
|
|
|
"google_container_cluster.primary"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-04-12 21:57:53 +02:00
|
|
|
func TestAccContainerCluster_withNodePoolBasic(t *testing.T) {
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccContainerCluster_withNodePoolBasic,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckContainerCluster(
|
|
|
|
"google_container_cluster.with_node_pool"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccContainerCluster_withNodePoolNamePrefix(t *testing.T) {
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccContainerCluster_withNodePoolNamePrefix,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckContainerCluster(
|
|
|
|
"google_container_cluster.with_node_pool_name_prefix"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccContainerCluster_withNodePoolMultiple(t *testing.T) {
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccContainerCluster_withNodePoolMultiple,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckContainerCluster(
|
|
|
|
"google_container_cluster.with_node_pool_multiple"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-07-05 18:39:01 +02: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 01:50:58 +01:00
|
|
|
func testAccCheckContainerCluster(n string) resource.TestCheckFunc {
|
2015-07-05 18:39:01 +02:00
|
|
|
return func(s *terraform.State) error {
|
2017-03-15 01:50:58 +01:00
|
|
|
attributes, err := getResourceAttributes(n, s)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2015-07-05 18:39:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
config := testAccProvider.Meta().(*Config)
|
2017-03-15 01:50:58 +01:00
|
|
|
cluster, err := config.clientContainer.Projects.Zones.Clusters.Get(
|
2015-07-05 18:39:01 +02:00
|
|
|
config.Project, attributes["zone"], attributes["name"]).Do()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-03-15 01:50:58 +01:00
|
|
|
if cluster.Name != attributes["name"] {
|
|
|
|
return fmt.Errorf("Cluster %s not found, found %s instead", attributes["name"], cluster.Name)
|
2015-07-05 18:39:01 +02:00
|
|
|
}
|
|
|
|
|
2017-03-15 01:50:58 +01:00
|
|
|
type clusterTestField struct {
|
|
|
|
tf_attr string
|
|
|
|
gcp_attr interface{}
|
|
|
|
}
|
2015-07-05 18:39:01 +02:00
|
|
|
|
2017-03-23 00:33:11 +01:00
|
|
|
var igUrls []string
|
|
|
|
if igUrls, err = getInstanceGroupUrlsFromManagerUrls(config, cluster.InstanceGroupUrls); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-03-15 01:50:58 +01:00
|
|
|
clusterTests := []clusterTestField{
|
|
|
|
{"initial_node_count", strconv.FormatInt(cluster.InitialNodeCount, 10)},
|
|
|
|
{"master_auth.0.client_certificate", cluster.MasterAuth.ClientCertificate},
|
|
|
|
{"master_auth.0.client_key", cluster.MasterAuth.ClientKey},
|
|
|
|
{"master_auth.0.cluster_ca_certificate", cluster.MasterAuth.ClusterCaCertificate},
|
|
|
|
{"master_auth.0.password", cluster.MasterAuth.Password},
|
|
|
|
{"master_auth.0.username", cluster.MasterAuth.Username},
|
|
|
|
{"zone", cluster.Zone},
|
|
|
|
{"cluster_ipv4_cidr", cluster.ClusterIpv4Cidr},
|
|
|
|
{"description", cluster.Description},
|
|
|
|
{"endpoint", cluster.Endpoint},
|
2017-03-23 00:33:11 +01:00
|
|
|
{"instance_group_urls", igUrls},
|
2017-03-15 01:50:58 +01:00
|
|
|
{"logging_service", cluster.LoggingService},
|
|
|
|
{"monitoring_service", cluster.MonitoringService},
|
|
|
|
{"subnetwork", cluster.Subnetwork},
|
|
|
|
{"node_config.0.machine_type", cluster.NodeConfig.MachineType},
|
|
|
|
{"node_config.0.disk_size_gb", strconv.FormatInt(cluster.NodeConfig.DiskSizeGb, 10)},
|
2017-02-27 16:03:55 +01:00
|
|
|
{"node_config.0.local_ssd_count", strconv.FormatInt(cluster.NodeConfig.LocalSsdCount, 10)},
|
2017-03-15 01:50:58 +01:00
|
|
|
{"node_config.0.oauth_scopes", cluster.NodeConfig.OauthScopes},
|
2017-02-15 02:45:53 +01:00
|
|
|
{"node_config.0.service_account", cluster.NodeConfig.ServiceAccount},
|
|
|
|
{"node_config.0.metadata", cluster.NodeConfig.Metadata},
|
|
|
|
{"node_config.0.image_type", cluster.NodeConfig.ImageType},
|
2017-03-15 01:50:58 +01:00
|
|
|
{"node_version", cluster.CurrentNodeVersion},
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove Zone from additional_zones since that's what the resource writes in state
|
|
|
|
additionalZones := []string{}
|
|
|
|
for _, location := range cluster.Locations {
|
|
|
|
if location != cluster.Zone {
|
|
|
|
additionalZones = append(additionalZones, location)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
clusterTests = append(clusterTests, clusterTestField{"additional_zones", additionalZones})
|
|
|
|
|
|
|
|
// AddonsConfig is neither Required or Computed, so the API may return nil for it
|
|
|
|
if cluster.AddonsConfig != nil {
|
|
|
|
if cluster.AddonsConfig.HttpLoadBalancing != nil {
|
|
|
|
clusterTests = append(clusterTests, clusterTestField{"addons_config.0.http_load_balancing.0.disabled", strconv.FormatBool(cluster.AddonsConfig.HttpLoadBalancing.Disabled)})
|
|
|
|
}
|
|
|
|
if cluster.AddonsConfig.HorizontalPodAutoscaling != nil {
|
|
|
|
clusterTests = append(clusterTests, clusterTestField{"addons_config.0.horizontal_pod_autoscaling.0.disabled", strconv.FormatBool(cluster.AddonsConfig.HorizontalPodAutoscaling.Disabled)})
|
|
|
|
}
|
2017-01-13 17:03:28 +01:00
|
|
|
}
|
|
|
|
|
2017-04-12 21:57:53 +02:00
|
|
|
for i, np := range cluster.NodePools {
|
|
|
|
prefix := fmt.Sprintf("node_pool.%d.", i)
|
|
|
|
clusterTests = append(clusterTests,
|
|
|
|
clusterTestField{prefix + "name", np.Name},
|
|
|
|
clusterTestField{prefix + "initial_node_count", strconv.FormatInt(np.InitialNodeCount, 10)})
|
|
|
|
}
|
|
|
|
|
2017-03-15 01:50:58 +01:00
|
|
|
for _, attrs := range clusterTests {
|
|
|
|
if c := checkMatch(attributes, attrs.tf_attr, attrs.gcp_attr); c != "" {
|
|
|
|
return fmt.Errorf(c)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Network has to be done separately in order to normalize the two values
|
|
|
|
tf, err := getNetworkNameFromSelfLink(attributes["network"])
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
gcp, err := getNetworkNameFromSelfLink(cluster.Network)
|
2017-02-07 02:21:34 +01:00
|
|
|
if err != nil {
|
2017-01-13 17:03:28 +01:00
|
|
|
return err
|
|
|
|
}
|
2017-03-15 01:50:58 +01:00
|
|
|
if tf != gcp {
|
|
|
|
return fmt.Errorf(matchError("network", tf, gcp))
|
2017-01-13 17:03:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-15 01:50:58 +01: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 02:45:53 +01:00
|
|
|
if gcpMap, ok := gcp.(map[string]string); ok {
|
|
|
|
return checkMapMatch(attributes, attr, gcpMap)
|
|
|
|
}
|
2017-03-15 01:50:58 +01: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 02:45:53 +01: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-03-15 01:50:58 +01:00
|
|
|
func matchError(attr, tf string, gcp interface{}) string {
|
|
|
|
return fmt.Sprintf("Cluster has mismatched %s.\nTF State: %+v\nGCP State: %+v", attr, tf, gcp)
|
|
|
|
}
|
|
|
|
|
2016-01-05 22:47:10 +01:00
|
|
|
var testAccContainerCluster_basic = fmt.Sprintf(`
|
2015-07-05 18:39:01 +02:00
|
|
|
resource "google_container_cluster" "primary" {
|
2016-01-05 22:47:10 +01:00
|
|
|
name = "cluster-test-%s"
|
2015-07-05 18:39:01 +02:00
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 3
|
|
|
|
|
|
|
|
master_auth {
|
|
|
|
username = "mr.yoda"
|
|
|
|
password = "adoy.rm"
|
|
|
|
}
|
2016-01-05 22:47:10 +01:00
|
|
|
}`, acctest.RandString(10))
|
2015-08-20 22:40:38 +02:00
|
|
|
|
2017-01-04 07:14:39 +01:00
|
|
|
var testAccContainerCluster_withAdditionalZones = fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_additional_zones" {
|
|
|
|
name = "cluster-test-%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 1
|
|
|
|
|
|
|
|
additional_zones = [
|
|
|
|
"us-central1-b",
|
|
|
|
"us-central1-c"
|
|
|
|
]
|
|
|
|
|
|
|
|
master_auth {
|
|
|
|
username = "mr.yoda"
|
|
|
|
password = "adoy.rm"
|
|
|
|
}
|
|
|
|
}`, acctest.RandString(10))
|
|
|
|
|
2016-12-18 14:50:46 +01:00
|
|
|
var testAccContainerCluster_withVersion = fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_version" {
|
|
|
|
name = "cluster-test-%s"
|
|
|
|
zone = "us-central1-a"
|
2017-04-12 21:38:45 +02:00
|
|
|
node_version = "1.6.0"
|
2016-12-18 14:50:46 +01:00
|
|
|
initial_node_count = 1
|
|
|
|
|
|
|
|
master_auth {
|
|
|
|
username = "mr.yoda"
|
|
|
|
password = "adoy.rm"
|
|
|
|
}
|
|
|
|
}`, acctest.RandString(10))
|
|
|
|
|
2016-01-05 22:47:10 +01:00
|
|
|
var testAccContainerCluster_withNodeConfig = fmt.Sprintf(`
|
2015-08-20 22:40:38 +02:00
|
|
|
resource "google_container_cluster" "with_node_config" {
|
2016-01-05 22:47:10 +01:00
|
|
|
name = "cluster-test-%s"
|
2015-08-20 22:40:38 +02:00
|
|
|
zone = "us-central1-f"
|
|
|
|
initial_node_count = 1
|
|
|
|
|
|
|
|
master_auth {
|
|
|
|
username = "mr.yoda"
|
|
|
|
password = "adoy.rm"
|
|
|
|
}
|
|
|
|
|
|
|
|
node_config {
|
2017-02-27 16:03:55 +01:00
|
|
|
machine_type = "n1-standard-1"
|
2015-08-20 22:40:38 +02:00
|
|
|
disk_size_gb = 15
|
2017-02-27 16:03:55 +01:00
|
|
|
local_ssd_count = 1
|
2015-08-20 22:40:38 +02:00
|
|
|
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"
|
|
|
|
]
|
2017-02-15 02:45:53 +01:00
|
|
|
service_account = "default"
|
|
|
|
metadata {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
image_type = "CONTAINER_VM"
|
2015-08-20 22:40:38 +02:00
|
|
|
}
|
2016-01-05 22:47:10 +01:00
|
|
|
}`, acctest.RandString(10))
|
2016-09-03 11:51:20 +02:00
|
|
|
|
2016-11-15 00:50:24 +01:00
|
|
|
var testAccContainerCluster_withNodeConfigScopeAlias = fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_node_config_scope_alias" {
|
|
|
|
name = "cluster-test-%s"
|
|
|
|
zone = "us-central1-f"
|
|
|
|
initial_node_count = 1
|
|
|
|
|
|
|
|
master_auth {
|
|
|
|
username = "mr.yoda"
|
|
|
|
password = "adoy.rm"
|
|
|
|
}
|
|
|
|
|
|
|
|
node_config {
|
|
|
|
machine_type = "g1-small"
|
|
|
|
disk_size_gb = 15
|
|
|
|
oauth_scopes = [ "compute-rw", "storage-ro", "logging-write", "monitoring" ]
|
|
|
|
}
|
|
|
|
}`, acctest.RandString(10))
|
|
|
|
|
2016-09-03 11:51:20 +02:00
|
|
|
var testAccContainerCluster_networkRef = fmt.Sprintf(`
|
|
|
|
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
|
|
|
|
|
|
|
|
master_auth {
|
|
|
|
username = "mr.yoda"
|
|
|
|
password = "adoy.rm"
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
master_auth {
|
|
|
|
username = "mr.yoda"
|
|
|
|
password = "adoy.rm"
|
|
|
|
}
|
|
|
|
|
|
|
|
network = "${google_compute_network.container_network.name}"
|
|
|
|
}`, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10))
|
2017-03-07 06:14:32 +01:00
|
|
|
|
|
|
|
var testAccContainerCluster_backendRef = fmt.Sprintf(`
|
|
|
|
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",
|
|
|
|
]
|
|
|
|
|
|
|
|
master_auth {
|
|
|
|
username = "mr.yoda"
|
|
|
|
password = "adoy.rm"
|
|
|
|
}
|
|
|
|
|
|
|
|
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-04-12 21:57:53 +02:00
|
|
|
|
|
|
|
var testAccContainerCluster_withNodePoolBasic = fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_node_pool" {
|
|
|
|
name = "tf-cluster-nodepool-test-%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
|
|
|
|
master_auth {
|
|
|
|
username = "mr.yoda"
|
|
|
|
password = "adoy.rm"
|
|
|
|
}
|
|
|
|
|
|
|
|
node_pool {
|
|
|
|
name = "tf-cluster-nodepool-test-%s"
|
|
|
|
initial_node_count = 2
|
|
|
|
}
|
|
|
|
}`, acctest.RandString(10), acctest.RandString(10))
|
|
|
|
|
|
|
|
var testAccContainerCluster_withNodePoolNamePrefix = fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_node_pool_name_prefix" {
|
|
|
|
name = "tf-cluster-nodepool-test-%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
|
|
|
|
master_auth {
|
|
|
|
username = "mr.yoda"
|
|
|
|
password = "adoy.rm"
|
|
|
|
}
|
|
|
|
|
|
|
|
node_pool {
|
|
|
|
name_prefix = "tf-np-test"
|
|
|
|
initial_node_count = 2
|
|
|
|
}
|
|
|
|
}`, acctest.RandString(10))
|
|
|
|
|
|
|
|
var testAccContainerCluster_withNodePoolMultiple = fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "with_node_pool_multiple" {
|
|
|
|
name = "tf-cluster-nodepool-test-%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
|
|
|
|
master_auth {
|
|
|
|
username = "mr.yoda"
|
|
|
|
password = "adoy.rm"
|
|
|
|
}
|
|
|
|
|
|
|
|
node_pool {
|
|
|
|
name = "tf-cluster-nodepool-test-%s"
|
|
|
|
initial_node_count = 2
|
|
|
|
}
|
|
|
|
|
|
|
|
node_pool {
|
|
|
|
name = "tf-cluster-nodepool-test-%s"
|
|
|
|
initial_node_count = 3
|
|
|
|
}
|
|
|
|
}`, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10))
|