forked from hashicorp/terraform-provider-google
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_source_google_container_cluster_test.go
142 lines (125 loc) · 3.46 KB
/
data_source_google_container_cluster_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package google
import (
"fmt"
"testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
func TestAccContainerClusterDatasource_zonal(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccContainerClusterDatasource_zonal(),
Check: resource.ComposeTestCheckFunc(
testAccDataSourceGoogleContainerClusterCheck("data.google_container_cluster.kubes", "google_container_cluster.kubes"),
),
},
},
})
}
func TestAccContainerClusterDatasource_regional(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccContainerClusterDatasource_regional(),
Check: resource.ComposeTestCheckFunc(
testAccDataSourceGoogleContainerClusterCheck("data.google_container_cluster.kubes", "google_container_cluster.kubes"),
),
},
},
})
}
func testAccDataSourceGoogleContainerClusterCheck(dataSourceName string, resourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
ds, ok := s.RootModule().Resources[dataSourceName]
if !ok {
return fmt.Errorf("root module has no resource called %s", dataSourceName)
}
rs, ok := s.RootModule().Resources[resourceName]
if !ok {
return fmt.Errorf("can't find %s in state", resourceName)
}
dsAttr := ds.Primary.Attributes
rsAttr := rs.Primary.Attributes
clusterAttrToCheck := []string{
"name",
"zone",
"additional_zones",
"addons_config",
"cluster_ipv4_cidr",
"description",
"enable_kubernetes_alpha",
"enable_tpu",
"enable_legacy_abac",
"endpoint",
"enable_legacy_abac",
"instance_group_urls",
"ip_allocation_policy",
"logging_service",
"maintenance_policy",
"master_auth",
"master_auth.0.password",
"master_auth.0.username",
"master_auth.0.client_certificate_config.0.issue_client_certificate",
"master_auth.0.client_certificate",
"master_auth.0.client_key",
"master_auth.0.cluster_ca_certificate",
"master_authorized_networks_config",
"master_version",
"min_master_version",
"monitoring_service",
"network",
"network_policy",
"node_version",
"subnetwork",
}
for _, attr := range clusterAttrToCheck {
if dsAttr[attr] != rsAttr[attr] {
return fmt.Errorf(
"%s is %s; want %s",
attr,
dsAttr[attr],
rsAttr[attr],
)
}
}
return nil
}
}
func testAccContainerClusterDatasource_zonal() string {
return fmt.Sprintf(`
resource "google_container_cluster" "kubes" {
name = "cluster-test-%s"
zone = "us-central1-a"
initial_node_count = 1
master_auth {
username = "mr.yoda"
password = "adoy.rm.123456789"
}
}
data "google_container_cluster" "kubes" {
name = "${google_container_cluster.kubes.name}"
zone = "${google_container_cluster.kubes.zone}"
}
`, acctest.RandString(10))
}
func testAccContainerClusterDatasource_regional() string {
return fmt.Sprintf(`
resource "google_container_cluster" "kubes" {
name = "cluster-test-%s"
region = "us-central1"
initial_node_count = 1
}
data "google_container_cluster" "kubes" {
name = "${google_container_cluster.kubes.name}"
region = "${google_container_cluster.kubes.region}"
}
`, acctest.RandString(10))
}