Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update upgrade guide #2665

Merged
merged 14 commits into from
Nov 13, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package google
import (
"fmt"
"log"
"sort"
"strings"
"time"

Expand All @@ -16,53 +15,6 @@ import (
"google.golang.org/api/compute/v1"
)

func resourceComputeInstanceGroupManagerExactlyOneTargetSizeDiff(diff *schema.ResourceDiff, v interface{}) error {
exactlyOneOfList := []string{"version.%d.target_size.%d.fixed", "version.%d.target_size.%d.percent"}
errorList := make([]string, 0)
versionBlocks := diff.Get("version").([]interface{})
if len(versionBlocks) == 0 {
return nil
}

for i := range versionBlocks {
targetBlocks := diff.Get(fmt.Sprintf("version.%d.target_size", i)).([]interface{})
if len(targetBlocks) == 0 {
continue
}

for j := range targetBlocks {
specified := make([]string, 0)
for _, exactlyOneOfKey := range exactlyOneOfList {
if val := diff.Get(fmt.Sprintf(exactlyOneOfKey, i, j)); val != 0 {
specified = append(specified, exactlyOneOfKey)
}
}

if len(specified) == 1 {
continue
}

sort.Strings(exactlyOneOfList)
keyList := formatStringsInList(exactlyOneOfList, i, j)
specified = formatStringsInList(specified, i, j)

if len(specified) == 0 {
errorList = append(errorList, fmt.Sprintf("version.%d.target_size: one of `%s` must be specified", i, strings.Join(keyList, ",")))
}

if len(specified) > 1 {
errorList = append(errorList, fmt.Sprintf("version.%d.target_size: only one of `%s` can be specified, but `%s` were specified", i, strings.Join(keyList, ","), strings.Join(specified, ",")))
}
}
}

if len(errorList) > 0 {
return fmt.Errorf(strings.Join(errorList, "\n\t* "))
}

return nil
}

func resourceComputeInstanceGroupManager() *schema.Resource {
return &schema.Resource{
Create: resourceComputeInstanceGroupManagerCreate,
Expand All @@ -72,9 +24,6 @@ func resourceComputeInstanceGroupManager() *schema.Resource {
Importer: &schema.ResourceImporter{
State: resourceInstanceGroupManagerStateImporter,
},
CustomizeDiff: customdiff.All(
resourceComputeInstanceGroupManagerExactlyOneTargetSizeDiff,
),
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(5 * time.Minute),
Update: schema.DefaultTimeout(5 * time.Minute),
Expand Down
104 changes: 0 additions & 104 deletions third_party/terraform/resources/resource_compute_instance_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package google
import (
"fmt"
"reflect"
"sort"
"strings"

"github.com/hashicorp/errwrap"
Expand Down Expand Up @@ -42,9 +41,6 @@ func resourceComputeInstanceTemplate() *schema.Resource {
CustomizeDiff: customdiff.All(
resourceComputeInstanceTemplateSourceImageCustomizeDiff,
resourceComputeInstanceTemplateScratchDiskCustomizeDiff,
resourceComputeInstanceTemplateAtLeastOneDiskSourceDiff,
resourceComputeInstanceTemplateAtLeastOneNetworkDiff,
resourceComputeInstanceTemplateAtLeastOneAccessConfigAttrDiff,
),
MigrateState: resourceComputeInstanceTemplateMigrateState,

Expand Down Expand Up @@ -554,106 +550,6 @@ func resourceComputeInstanceTemplateSourceImageCustomizeDiff(diff *schema.Resour
return nil
}

func resourceComputeInstanceTemplateAtLeastOneDiskSourceDiff(diff *schema.ResourceDiff, v interface{}) error {
atLeastOneOfList := []string{"disk.%d.source_image", "disk.%d.source"}
errorList := make([]string, 0)

disks := diff.Get("disk").([]interface{})
if len(disks) == 0 {
return nil
}

for i := range disks {
found := false
for _, atLeastOneOfKey := range atLeastOneOfList {
if val := diff.Get(fmt.Sprintf(atLeastOneOfKey, i)); val != "" {
found = true
}
}

if found == false {
sort.Strings(atLeastOneOfList)
keyList := formatStringsInList(atLeastOneOfList, i)
errorList = append(errorList, fmt.Sprintf("disk: one of `%s` must be specified", strings.Join(keyList, ",")))
}
}

if len(errorList) > 0 {
return fmt.Errorf(strings.Join(errorList, "\n\t* "))
}

return nil
}

func resourceComputeInstanceTemplateAtLeastOneNetworkDiff(diff *schema.ResourceDiff, v interface{}) error {
atLeastOneOfList := []string{"network_interface.%d.network", "network_interface.%d.subnetwork"}
errorList := make([]string, 0)

networkInterfaces := diff.Get("network_interface").([]interface{})
if len(networkInterfaces) == 0 {
return nil
}

for i := range networkInterfaces {
found := false
for _, atLeastOneOfKey := range atLeastOneOfList {
if val := diff.Get(fmt.Sprintf(atLeastOneOfKey, i)); val != "" {
found = true
}
}

if found == false {
sort.Strings(atLeastOneOfList)
keyList := formatStringsInList(atLeastOneOfList, i)
errorList = append(errorList, fmt.Sprintf("network_interface: one of `%s` must be specified", strings.Join(keyList, ",")))
}
}

if len(errorList) > 0 {
return fmt.Errorf(strings.Join(errorList, "\n\t* "))
}

return nil
}

func resourceComputeInstanceTemplateAtLeastOneAccessConfigAttrDiff(diff *schema.ResourceDiff, v interface{}) error {
atLeastOneOfList := []string{"network_interface.%d.access_config.%d.nat_ip", "network_interface.%d.access_config.%d.network_tier"}
errorList := make([]string, 0)

networkInterfaces := diff.Get("network_interface").([]interface{})
if len(networkInterfaces) == 0 {
return nil
}

for i := range networkInterfaces {
accessConfigs := diff.Get(fmt.Sprintf("network_interface.%d.access_config", i)).([]interface{})
if len(accessConfigs) == 0 {
continue
}

for j := range accessConfigs {
found := false
for _, atLeastOneOfKey := range atLeastOneOfList {
if val := diff.Get(fmt.Sprintf(atLeastOneOfKey, i, j)); val != "" {
found = true
}
}

if found == false {
sort.Strings(atLeastOneOfList)
keyList := formatStringsInList(atLeastOneOfList, i, j)
errorList = append(errorList, fmt.Sprintf("network_interface.%d.access_config: one of `%s` must be specified", i, strings.Join(keyList, ",")))
}
}
}

if len(errorList) > 0 {
return fmt.Errorf(strings.Join(errorList, "\n\t* "))
}

return nil
}

func resourceComputeInstanceTemplateScratchDiskCustomizeDiff(diff *schema.ResourceDiff, meta interface{}) error {
// separate func to allow unit testing
return resourceComputeInstanceTemplateScratchDiskCustomizeDiffFunc(diff)
Expand Down
33 changes: 0 additions & 33 deletions third_party/terraform/resources/resource_storage_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"log"
"math"
"runtime"
"sort"
"strconv"
"strings"
"time"
Expand All @@ -23,37 +22,6 @@ import (
"google.golang.org/api/storage/v1"
)

func resourceStorageBucketAtLeastOneCorsAttrDiff(diff *schema.ResourceDiff, v interface{}) error {
atLeastOneOfList := []string{"cors.%d.origin", "cors.%d.method", "cors.%d.response_header", "cors.%d.max_age_seconds"}
errorList := make([]string, 0)

corsBlocks := diff.Get("cors").([]interface{})
if len(corsBlocks) == 0 {
return nil
}

for i := range corsBlocks {
found := false
for _, atLeastOneOfKey := range atLeastOneOfList {
if val := diff.Get(fmt.Sprintf(atLeastOneOfKey, i)); val != "" {
found = true
}
}

if found == false {
sort.Strings(atLeastOneOfList)
keyList := formatStringsInList(atLeastOneOfList, i)
errorList = append(errorList, fmt.Sprintf("cors: one of `%s` must be specified", strings.Join(keyList, ",")))
}
}

if len(errorList) > 0 {
return fmt.Errorf(strings.Join(errorList, "\n\t* "))
}

return nil
}

func resourceStorageBucket() *schema.Resource {
return &schema.Resource{
Create: resourceStorageBucketCreate,
Expand All @@ -65,7 +33,6 @@ func resourceStorageBucket() *schema.Resource {
},
CustomizeDiff: customdiff.All(
customdiff.ForceNewIfChange("retention_policy.0.is_locked", isPolicyLocked),
resourceStorageBucketAtLeastOneCorsAttrDiff,
),

Schema: map[string]*schema.Schema{
Expand Down
Loading