provider/google: replace instance group manager urls with instance group urls in container cluster tests

This commit is contained in:
Dana Hoffman 2017-03-22 16:33:11 -07:00
parent 02aa1ea8a1
commit a208c08630
2 changed files with 33 additions and 21 deletions

View File

@ -522,27 +522,11 @@ func resourceContainerClusterRead(d *schema.ResourceData, meta interface{}) erro
d.Set("subnetwork", cluster.Subnetwork) d.Set("subnetwork", cluster.Subnetwork)
d.Set("node_config", flattenClusterNodeConfig(cluster.NodeConfig)) d.Set("node_config", flattenClusterNodeConfig(cluster.NodeConfig))
// container engine's API currently mistakenly returns the instance group manager's if igUrls, err := getInstanceGroupUrlsFromManagerUrls(config, cluster.InstanceGroupUrls); err != nil {
// URL instead of the instance group's URL in its responses. This shim detects that return err
// error, and corrects it, by fetching the instance group manager URL and retrieving } else {
// the instance group manager, then using that to look up the instance group URL, which d.Set("instance_group_urls", igUrls)
// is then substituted.
//
// This should be removed when the API response is fixed.
instanceGroupURLs := make([]string, 0, len(cluster.InstanceGroupUrls))
for _, u := range cluster.InstanceGroupUrls {
if !instanceGroupManagerURL.MatchString(u) {
instanceGroupURLs = append(instanceGroupURLs, u)
continue
}
matches := instanceGroupManagerURL.FindStringSubmatch(u)
instanceGroupManager, err := config.clientCompute.InstanceGroupManagers.Get(matches[1], matches[2], matches[3]).Do()
if err != nil {
return fmt.Errorf("Error reading instance group manager returned as an instance group URL: %s", err)
}
instanceGroupURLs = append(instanceGroupURLs, instanceGroupManager.InstanceGroup)
} }
d.Set("instance_group_urls", instanceGroupURLs)
return nil return nil
} }
@ -613,6 +597,30 @@ func resourceContainerClusterDelete(d *schema.ResourceData, meta interface{}) er
return nil return nil
} }
// container engine's API currently mistakenly returns the instance group manager's
// URL instead of the instance group's URL in its responses. This shim detects that
// error, and corrects it, by fetching the instance group manager URL and retrieving
// the instance group manager, then using that to look up the instance group URL, which
// is then substituted.
//
// This should be removed when the API response is fixed.
func getInstanceGroupUrlsFromManagerUrls(config *Config, igmUrls []string) ([]string, error) {
instanceGroupURLs := make([]string, 0, len(igmUrls))
for _, u := range igmUrls {
if !instanceGroupManagerURL.MatchString(u) {
instanceGroupURLs = append(instanceGroupURLs, u)
continue
}
matches := instanceGroupManagerURL.FindStringSubmatch(u)
instanceGroupManager, err := config.clientCompute.InstanceGroupManagers.Get(matches[1], matches[2], matches[3]).Do()
if err != nil {
return nil, fmt.Errorf("Error reading instance group manager returned as an instance group URL: %s", err)
}
instanceGroupURLs = append(instanceGroupURLs, instanceGroupManager.InstanceGroup)
}
return instanceGroupURLs, nil
}
func flattenClusterNodeConfig(c *container.NodeConfig) []map[string]interface{} { func flattenClusterNodeConfig(c *container.NodeConfig) []map[string]interface{} {
config := []map[string]interface{}{ config := []map[string]interface{}{
map[string]interface{}{ map[string]interface{}{

View File

@ -174,6 +174,10 @@ func testAccCheckContainerCluster(n string) resource.TestCheckFunc {
gcp_attr interface{} gcp_attr interface{}
} }
var igUrls []string
if igUrls, err = getInstanceGroupUrlsFromManagerUrls(config, cluster.InstanceGroupUrls); err != nil {
return err
}
clusterTests := []clusterTestField{ clusterTests := []clusterTestField{
{"initial_node_count", strconv.FormatInt(cluster.InitialNodeCount, 10)}, {"initial_node_count", strconv.FormatInt(cluster.InitialNodeCount, 10)},
{"master_auth.0.client_certificate", cluster.MasterAuth.ClientCertificate}, {"master_auth.0.client_certificate", cluster.MasterAuth.ClientCertificate},
@ -185,7 +189,7 @@ func testAccCheckContainerCluster(n string) resource.TestCheckFunc {
{"cluster_ipv4_cidr", cluster.ClusterIpv4Cidr}, {"cluster_ipv4_cidr", cluster.ClusterIpv4Cidr},
{"description", cluster.Description}, {"description", cluster.Description},
{"endpoint", cluster.Endpoint}, {"endpoint", cluster.Endpoint},
{"instance_group_urls", cluster.InstanceGroupUrls}, {"instance_group_urls", igUrls},
{"logging_service", cluster.LoggingService}, {"logging_service", cluster.LoggingService},
{"monitoring_service", cluster.MonitoringService}, {"monitoring_service", cluster.MonitoringService},
{"subnetwork", cluster.Subnetwork}, {"subnetwork", cluster.Subnetwork},