forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 2
/
data_source_google_container_engine_versions.go
67 lines (57 loc) · 1.57 KB
/
data_source_google_container_engine_versions.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
package google
import (
"fmt"
"time"
"github.com/hashicorp/terraform/helper/schema"
)
func dataSourceGoogleContainerEngineVersions() *schema.Resource {
return &schema.Resource{
Read: dataSourceGoogleContainerEngineVersionsRead,
Schema: map[string]*schema.Schema{
"project": {
Type: schema.TypeString,
Optional: true,
},
"zone": {
Type: schema.TypeString,
Required: true,
},
"latest_master_version": {
Type: schema.TypeString,
Computed: true,
},
"latest_node_version": {
Type: schema.TypeString,
Computed: true,
},
"valid_master_versions": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"valid_node_versions": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
}
}
func dataSourceGoogleContainerEngineVersionsRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
project, err := getProject(d, config)
if err != nil {
return err
}
zone := d.Get("zone").(string)
resp, err := config.clientContainer.Projects.Zones.GetServerconfig(project, zone).Do()
if err != nil {
return fmt.Errorf("Error retrieving available container cluster versions: %s", err.Error())
}
d.Set("valid_master_versions", resp.ValidMasterVersions)
d.Set("valid_node_versions", resp.ValidNodeVersions)
d.Set("latest_master_version", resp.ValidMasterVersions[0])
d.Set("latest_node_version", resp.ValidNodeVersions[0])
d.SetId(time.Now().UTC().String())
return nil
}