Skip to content

Commit

Permalink
Allow configuring GKE Node Pool upgrade settings
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
chrissng authored and modular-magician committed Nov 27, 2019
1 parent b11c43f commit 69b755c
Show file tree
Hide file tree
Showing 29 changed files with 76 additions and 45 deletions.
2 changes: 1 addition & 1 deletion google/data_source_google_compute_node_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func dataSourceGoogleComputeNodeTypesRead(d *schema.ResourceData, meta interface
}

func flattenComputeNodeTypes(nodeTypes []*compute.NodeType) []string {
result := make([]string, len(nodeTypes))
result := make([]string, len(nodeTypes), len(nodeTypes))
for i, nodeType := range nodeTypes {
result[i] = nodeType.Name
}
Expand Down
2 changes: 1 addition & 1 deletion google/data_source_google_compute_regions.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func dataSourceGoogleComputeRegionsRead(d *schema.ResourceData, meta interface{}
}

func flattenRegions(regions []*compute.Region) []string {
result := make([]string, len(regions))
result := make([]string, len(regions), len(regions))
for i, region := range regions {
result[i] = region.Name
}
Expand Down
2 changes: 1 addition & 1 deletion google/data_source_google_compute_zones.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func dataSourceGoogleComputeZonesRead(d *schema.ResourceData, meta interface{})
}

func flattenZones(zones []*compute.Zone) []string {
result := make([]string, len(zones))
result := make([]string, len(zones), len(zones))
for i, zone := range zones {
result[i] = zone.Name
}
Expand Down
6 changes: 4 additions & 2 deletions google/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ func getImportIdQualifiers(idRegexes []string, d TerraformResourceData, config *
}

if fieldValues := re.FindStringSubmatch(id); fieldValues != nil {
result := make(map[string]string)
var result map[string]string
result = make(map[string]string)
log.Printf("[DEBUG] matching ID %s to regex %s.", id, idFormat)
// Starting at index 1, the first match is the full string.
for i := 1; i < len(fieldValues); i++ {
Expand Down Expand Up @@ -147,7 +148,8 @@ func getImportIdQualifiers(idRegexes []string, d TerraformResourceData, config *
// Returns a set of default values that are contained in a regular expression
// This does not mutate any parameters, instead returning a map of defaults
func getDefaultValues(idRegex string, d TerraformResourceData, config *Config) (map[string]string, error) {
result := make(map[string]string)
var result map[string]string
result = make(map[string]string)
if _, ok := d.GetOk("project"); !ok && strings.Contains(idRegex, "?P<project>") {
project, err := getProject(d, config)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion google/kms_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (s *kmsCryptoKeyId) terraformId() string {

func validateKmsCryptoKeyRotationPeriod(value interface{}, _ string) (ws []string, errors []error) {
period := value.(string)
pattern := regexp.MustCompile(`^([0-9.]*\\d)s$`)
pattern := regexp.MustCompile("^([0-9.]*\\d)s$")
match := pattern.FindStringSubmatch(period)

if len(match) == 0 {
Expand Down
2 changes: 1 addition & 1 deletion google/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ func providerConfigure(d *schema.ResourceData, terraformVersion string) (interfa

scopes := d.Get("scopes").([]interface{})
if len(scopes) > 0 {
config.Scopes = make([]string, len(scopes))
config.Scopes = make([]string, len(scopes), len(scopes))
}
for i, scope := range scopes {
config.Scopes[i] = scope.(string)
Expand Down
8 changes: 4 additions & 4 deletions google/resource_bigquery_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ func flattenExternalDataConfiguration(edc *bigquery.ExternalDataConfiguration) (
result["google_sheets_options"] = flattenGoogleSheetsOptions(edc.GoogleSheetsOptions)
}

if edc.IgnoreUnknownValues {
if edc.IgnoreUnknownValues == true {
result["ignore_unknown_values"] = edc.IgnoreUnknownValues
}
if edc.MaxBadRecords != 0 {
Expand Down Expand Up @@ -702,11 +702,11 @@ func expandCsvOptions(configured interface{}) *bigquery.CsvOptions {
func flattenCsvOptions(opts *bigquery.CsvOptions) []map[string]interface{} {
result := map[string]interface{}{}

if opts.AllowJaggedRows {
if opts.AllowJaggedRows == true {
result["allow_jagged_rows"] = opts.AllowJaggedRows
}

if opts.AllowQuotedNewlines {
if opts.AllowQuotedNewlines == true {
result["allow_quoted_newlines"] = opts.AllowQuotedNewlines
}

Expand Down Expand Up @@ -814,7 +814,7 @@ func flattenTimePartitioning(tp *bigquery.TimePartitioning) []map[string]interfa
result["expiration_ms"] = tp.ExpirationMs
}

if tp.RequirePartitionFilter {
if tp.RequirePartitionFilter == true {
result["require_partition_filter"] = tp.RequirePartitionFilter
}

Expand Down
6 changes: 5 additions & 1 deletion google/resource_bigtable_app_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,11 @@ func flattenBigtableAppProfileDescription(v interface{}, d *schema.ResourceData)
}

func flattenBigtableAppProfileMultiClusterRoutingUseAny(v interface{}, d *schema.ResourceData) interface{} {
return v != nil
if v == nil {
return false
}

return true
}

func flattenBigtableAppProfileSingleClusterRouting(v interface{}, d *schema.ResourceData) interface{} {
Expand Down
8 changes: 4 additions & 4 deletions google/resource_cloud_scheduler_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -763,9 +763,9 @@ func flattenCloudSchedulerJobAppEngineHttpTargetHeaders(v interface{}, d *schema
delete(headers, "Content-Type")
}
}
r := regexp.MustCompile(`(X-Google-|X-AppEngine-|Content-Length).*`)
for key := range headers {
if r.MatchString(key) {
match, _ := regexp.MatchString("(X-Google-|X-AppEngine-|Content-Length).*", key)
if match {
delete(headers, key)
}
}
Expand Down Expand Up @@ -823,9 +823,9 @@ func flattenCloudSchedulerJobHttpTargetHeaders(v interface{}, d *schema.Resource
delete(headers, "Content-Type")
}
}
r := regexp.MustCompile(`(X-Google-|X-AppEngine-|Content-Length).*`)
for key := range headers {
if r.MatchString(key) {
match, _ := regexp.MatchString("(X-Google-|X-AppEngine-|Content-Length).*", key)
if match {
delete(headers, key)
}
}
Expand Down
2 changes: 1 addition & 1 deletion google/resource_cloudfunctions_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func resourceCloudFunctionsFunction() *schema.Resource {
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
availableMemoryMB := v.(int)

if !functionAllowedMemory[availableMemoryMB] {
if functionAllowedMemory[availableMemoryMB] != true {
errors = append(errors, fmt.Errorf("Allowed values for memory (in MB) are: %s . Got %d",
joinMapKeys(&functionAllowedMemory), availableMemoryMB))
}
Expand Down
6 changes: 5 additions & 1 deletion google/resource_compute_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,11 @@ func suppressWindowsFamilyDiff(imageName, familyName string) bool {
updatedFamilyString := strings.Replace(familyName, "windows-", "windows-server-", 1)
updatedImageName := strings.Replace(imageName, "-dc-", "-", 1)

return strings.Contains(updatedImageName, updatedFamilyString)
if strings.Contains(updatedImageName, updatedFamilyString) {
return true
}

return false
}

func resourceComputeDisk() *schema.Resource {
Expand Down
5 changes: 4 additions & 1 deletion google/resource_compute_firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ func resourceComputeFirewallRuleHash(v interface{}) int {
}

func compareCaseInsensitive(k, old, new string, d *schema.ResourceData) bool {
return strings.ToLower(old) == strings.ToLower(new)
if strings.ToLower(old) == strings.ToLower(new) {
return true
}
return false
}

func resourceComputeFirewall() *schema.Resource {
Expand Down
2 changes: 1 addition & 1 deletion google/resource_compute_instance_group_migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func TestComputeInstanceGroupMigrateState_empty(t *testing.T) {

// should handle non-nil but empty
is = &terraform.InstanceState{}
_, err = resourceComputeInstanceGroupMigrateState(tc.StateVersion, is, meta)
is, err = resourceComputeInstanceGroupMigrateState(tc.StateVersion, is, meta)

if err != nil {
t.Fatalf("bad %s, err: %#v", tn, err)
Expand Down
2 changes: 1 addition & 1 deletion google/resource_compute_instance_iam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestAccComputeInstanceIamPolicy(t *testing.T) {
},
{
ResourceName: "google_compute_instance_iam_policy.foo",
ImportStateId: instanceName,
ImportStateId: fmt.Sprintf("%s", instanceName),
ImportState: true,
ImportStateVerify: true,
},
Expand Down
10 changes: 5 additions & 5 deletions google/resource_compute_instance_migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ func getDiskFromAttributes(config *Config, instance *compute.Instance, allDisks

func getDiskFromSource(instance *compute.Instance, source string) (*compute.AttachedDisk, error) {
for _, disk := range instance.Disks {
if disk.Boot || disk.Type == "SCRATCH" {
if disk.Boot == true || disk.Type == "SCRATCH" {
// Ignore boot/scratch disks since this is just for finding attached disks
continue
}
Expand All @@ -420,7 +420,7 @@ func getDiskFromSource(instance *compute.Instance, source string) (*compute.Atta

func getDiskFromDeviceName(instance *compute.Instance, deviceName string) (*compute.AttachedDisk, error) {
for _, disk := range instance.Disks {
if disk.Boot || disk.Type == "SCRATCH" {
if disk.Boot == true || disk.Type == "SCRATCH" {
// Ignore boot/scratch disks since this is just for finding attached disks
continue
}
Expand All @@ -437,7 +437,7 @@ func getDiskFromEncryptionKey(instance *compute.Instance, encryptionKey string)
return nil, err
}
for _, disk := range instance.Disks {
if disk.Boot || disk.Type == "SCRATCH" {
if disk.Boot == true || disk.Type == "SCRATCH" {
// Ignore boot/scratch disks since this is just for finding attached disks
continue
}
Expand All @@ -457,7 +457,7 @@ func getDiskFromAutoDeleteAndImage(config *Config, instance *compute.Instance, a
canonicalImage := imgParts[len(imgParts)-1]

for i, disk := range instance.Disks {
if disk.Boot || disk.Type == "SCRATCH" {
if disk.Boot == true || disk.Type == "SCRATCH" {
// Ignore boot/scratch disks since this is just for finding attached disks
continue
}
Expand All @@ -482,7 +482,7 @@ func getDiskFromAutoDeleteAndImage(config *Config, instance *compute.Instance, a
// the image family.
canonicalImage = strings.Replace(canonicalImage, "/family/", "/", -1)
for i, disk := range instance.Disks {
if disk.Boot || disk.Type == "SCRATCH" {
if disk.Boot == true || disk.Type == "SCRATCH" {
// Ignore boot/scratch disks since this is just for finding attached disks
continue
}
Expand Down
2 changes: 1 addition & 1 deletion google/resource_compute_instance_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ func reorderDisks(configDisks []interface{}, apiDisks []map[string]interface{})
return apiDisks
}

result := make([]map[string]interface{}, len(apiDisks))
result := make([]map[string]interface{}, len(apiDisks), len(apiDisks))

/*
Disks aren't necessarily returned from the API in the same order they were sent, so gather
Expand Down
2 changes: 1 addition & 1 deletion google/resource_compute_subnetwork_iam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestAccComputeSubnetworkIamPolicy(t *testing.T) {
},
{
ResourceName: "google_compute_subnetwork_iam_policy.foo",
ImportStateId: subnetwork,
ImportStateId: fmt.Sprintf("%s", subnetwork),
ImportState: true,
ImportStateVerify: true,
},
Expand Down
2 changes: 1 addition & 1 deletion google/resource_compute_target_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func canonicalizeInstanceRef(instanceRef string) string {

// Healthchecks need to exist before being referred to from the target pool.
func convertHealthChecks(healthChecks []interface{}, d *schema.ResourceData, config *Config) ([]string, error) {
if len(healthChecks) == 0 {
if healthChecks == nil || len(healthChecks) == 0 {
return []string{}, nil
}

Expand Down
6 changes: 3 additions & 3 deletions google/resource_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1706,7 +1706,7 @@ func expandMaintenancePolicy(d *schema.ResourceData, meta interface{}) *containe
if cluster != nil && cluster.MaintenancePolicy != nil {
resourceVersion = cluster.MaintenancePolicy.ResourceVersion
}
exclusions := make(map[string]containerBeta.TimeWindow)
exclusions := make(map[string]containerBeta.TimeWindow, 0)
if cluster != nil && cluster.MaintenancePolicy != nil && cluster.MaintenancePolicy.Window != nil {
exclusions = cluster.MaintenancePolicy.Window.MaintenanceExclusions
}
Expand Down Expand Up @@ -1993,7 +1993,7 @@ func flattenPrivateClusterConfig(c *containerBeta.PrivateClusterConfig) []map[st

func flattenIPAllocationPolicy(c *containerBeta.Cluster, d *schema.ResourceData, config *Config) []map[string]interface{} {
// If IP aliasing isn't enabled, none of the values in this block can be set.
if c == nil || c.IpAllocationPolicy == nil || !c.IpAllocationPolicy.UseIpAliases {
if c == nil || c.IpAllocationPolicy == nil || c.IpAllocationPolicy.UseIpAliases == false {
return nil
}

Expand Down Expand Up @@ -2224,7 +2224,7 @@ func containerClusterPrivateClusterConfigCustomDiff(d *schema.ResourceDiff, meta
return nil
}
config := pccList[0].(map[string]interface{})
if config["enable_private_nodes"].(bool) {
if config["enable_private_nodes"].(bool) == true {
block := config["master_ipv4_cidr_block"]

// We can only apply this validation if we know the final value of the field, and we may
Expand Down
2 changes: 1 addition & 1 deletion google/resource_firestore_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func resourceFirestoreIndexImport(d *schema.ResourceData, meta interface{}) ([]*
)
}

d.Set("project", stringParts[1])
d.Set("project", fmt.Sprintf("%s", stringParts[1]))
return []*schema.ResourceData{d}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion google/resource_pubsub_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ func expandPubsubSubscriptionTopic(v interface{}, d TerraformResourceData, confi

topic := d.Get("topic").(string)

re := regexp.MustCompile(`projects\/(.*)\/topics\/(.*)`)
re := regexp.MustCompile("projects\\/(.*)\\/topics\\/(.*)")
match := re.FindStringSubmatch(topic)
if len(match) == 3 {
return topic, nil
Expand Down
2 changes: 1 addition & 1 deletion google/resource_security_center_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func resourceSecurityCenterSourceImport(d *schema.ResourceData, meta interface{}
)
}

d.Set("organization", stringParts[1])
d.Set("organization", fmt.Sprintf("%s", stringParts[1]))
return []*schema.ResourceData{d}, nil
}

Expand Down
4 changes: 2 additions & 2 deletions google/resource_spanner_database_iam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ func TestAccSpannerDatabaseIamPolicy(t *testing.T) {
// Test a few import formats
{
ResourceName: "google_spanner_database_iam_policy.foo",
ImportStateId: spannerDatabaseId{
ImportStateId: fmt.Sprintf("%s", spannerDatabaseId{
Instance: instance,
Database: database,
Project: project,
}.terraformId(),
}.terraformId()),
ImportState: true,
ImportStateVerify: true,
},
Expand Down
4 changes: 2 additions & 2 deletions google/resource_spanner_instance_iam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ func TestAccSpannerInstanceIamPolicy(t *testing.T) {
// Test a few import formats
{
ResourceName: "google_spanner_instance_iam_policy.foo",
ImportStateId: spannerInstanceId{
ImportStateId: fmt.Sprintf("%s", spannerInstanceId{
Instance: instance,
Project: project,
}.terraformId(),
}.terraformId()),
ImportState: true,
ImportStateVerify: true,
},
Expand Down
2 changes: 1 addition & 1 deletion google/resource_storage_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ func flattenCors(corsRules []*storage.BucketCors) []map[string]interface{} {

func expandBucketEncryption(configured interface{}) *storage.BucketEncryption {
encs := configured.([]interface{})
if len(encs) == 0 || encs[0] == nil {
if encs == nil || len(encs) == 0 || encs[0] == nil {
return nil
}
enc := encs[0].(map[string]interface{})
Expand Down
4 changes: 2 additions & 2 deletions google/resource_tpu_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ func validateHttpHeaders() schema.SchemaValidateFunc {
es = append(es, fmt.Errorf("Cannot set the Content-Length header on %s", k))
return
}
r := regexp.MustCompile(`(X-Google-|X-AppEngine-).*`)
for key := range headers {
if r.MatchString(key) {
match, _ := regexp.MatchString("(X-Google-|X-AppEngine-).*", key)
if match {
es = append(es, fmt.Errorf("Cannot set the %s header on %s", key, k))
return
}
Expand Down
5 changes: 4 additions & 1 deletion google/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,10 @@ func caseDiffSuppress(_, old, new string, _ *schema.ResourceData) bool {
// `old` is read from the server and always has the full range format (e.g. '80-80', '1024-2048').
// `new` can be either a single port or a port range.
func portRangeDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
return old == new+"-"+new
if old == new+"-"+new {
return true
}
return false
}

// Single-digit hour is equivalent to hour with leading zero e.g. suppress diff 1:00 => 01:00.
Expand Down
3 changes: 1 addition & 2 deletions google/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,8 @@ func TestProjectRegex(t *testing.T) {
{"", false},
{"example_", false},
}
r := regexp.MustCompile("^" + ProjectRegex + "$")
for _, test := range tests {
if got := r.MatchString(test.project); got != test.want {
if got, err := regexp.MatchString("^"+ProjectRegex+"$", test.project); err != nil || got != test.want {
t.Errorf("got %t, want %t for project %v", got, test.want, test.project)
}
}
Expand Down
Loading

0 comments on commit 69b755c

Please sign in to comment.