Various linter cleanups (conversions, unused, misspellings) (#2681)

<!-- This change is generated by MagicModules. -->
/cc @rileykarson
This commit is contained in:
The Magician 2018-12-14 18:16:33 -08:00 committed by Nathan McKinley
parent 3439746a46
commit 29c665d865
22 changed files with 15 additions and 300 deletions

View File

@ -36,10 +36,6 @@ func (w *ComposerOperationWaiter) Conf() *resource.StateChangeConf {
}
}
func composerOperationWait(service *composer.Service, op *composer.Operation, project, activity string) error {
return composerOperationWaitTime(service, op, project, activity, 10)
}
func composerOperationWaitTime(service *composer.Service, op *composer.Operation, project, activity string, timeoutMin int) error {
if op.Done {
if op.Error != nil {

View File

@ -78,7 +78,7 @@ func dataSourceGoogleComputeAddressRead(d *schema.ResourceData, meta interface{}
d.Set("project", project)
d.Set("region", region)
d.SetId(strconv.FormatUint(uint64(address.Id), 10))
d.SetId(strconv.FormatUint(address.Id, 10))
return nil
}

View File

@ -59,6 +59,6 @@ func dataSourceGoogleComputeGlobalAddressRead(d *schema.ResourceData, meta inter
d.Set("self_link", address.SelfLink)
d.Set("project", project)
d.SetId(strconv.FormatUint(uint64(address.Id), 10))
d.SetId(strconv.FormatUint(address.Id, 10))
return nil
}

View File

@ -4,7 +4,6 @@ import (
"fmt"
"github.com/hashicorp/terraform/helper/schema"
computeBeta "google.golang.org/api/compute/v0.beta"
"google.golang.org/api/compute/v1"
)
@ -124,7 +123,3 @@ func flattenSecondaryRanges(secondaryRanges []*compute.SubnetworkSecondaryRange)
func createSubnetID(s *compute.Subnetwork) string {
return fmt.Sprintf("%s/%s", s.Region, s.Name)
}
func createSubnetIDBeta(s *computeBeta.Subnetwork) string {
return fmt.Sprintf("%s/%s", s.Region, s.Name)
}

View File

@ -50,8 +50,6 @@ func dataSourceGoogleNetblockIpRangesRead(d *schema.ResourceData, meta interface
}
func netblock_request(name string) (string, error) {
const DNS_URL = "https://dns.google.com/resolve?name=%s&type=TXT"
response, err := http.Get(fmt.Sprintf("https://dns.google.com/resolve?name=%s&type=TXT", name))
if err != nil {
@ -79,7 +77,7 @@ func getCidrBlocks() (map[string][]string, error) {
return nil, err
}
splitedResponse := strings.Split(string(response), " ")
splitedResponse := strings.Split(response, " ")
for _, sp := range splitedResponse {
if strings.HasPrefix(sp, "include:") {
@ -101,7 +99,7 @@ func getCidrBlocks() (map[string][]string, error) {
return nil, err
}
splitedResponse = strings.Split(string(response), " ")
splitedResponse = strings.Split(response, " ")
for _, sp := range splitedResponse {
if strings.HasPrefix(sp, "ip") {

View File

@ -1,72 +0,0 @@
package google
import (
"fmt"
"log"
"time"
"github.com/hashicorp/terraform/helper/resource"
"google.golang.org/api/dns/v1"
)
type DnsOperationWaiter struct {
Service *dns.ManagedZoneOperationsService
Op *dns.Operation
Project string
}
func (w *DnsOperationWaiter) RefreshFunc() resource.StateRefreshFunc {
return func() (interface{}, string, error) {
var op *dns.Operation
var err error
if w.Op.ZoneContext != nil {
op, err = w.Service.Get(w.Project, w.Op.ZoneContext.NewValue.Name, w.Op.Id).Do()
} else {
return nil, "", fmt.Errorf("unsupported DNS operation %q", w.Op.Id)
}
if err != nil {
return nil, "", err
}
log.Printf("[DEBUG] Got %q when asking for operation %q", op.Status, w.Op.Id)
return op, op.Status, nil
}
}
func (w *DnsOperationWaiter) Conf() *resource.StateChangeConf {
return &resource.StateChangeConf{
Pending: []string{"pending"},
Target: []string{"done"},
Refresh: w.RefreshFunc(),
}
}
func dnsOperationWait(service *dns.Service, op *dns.Operation, project, activity string) error {
return dnsOperationWaitTime(service, op, project, activity, 4)
}
func dnsOperationWaitTime(service *dns.Service, op *dns.Operation, project, activity string, timeoutMin int) error {
if op.Status == "done" {
return nil
}
w := &DnsOperationWaiter{
Service: service.ManagedZoneOperations,
Op: op,
Project: project,
}
state := w.Conf()
state.Delay = 10 * time.Second
state.Timeout = time.Duration(timeoutMin) * time.Minute
state.MinTimeout = 2 * time.Second
_, err := state.WaitForState()
if err != nil {
return fmt.Errorf("Error waiting for %s: %s", activity, err)
}
return nil
}

View File

@ -36,10 +36,6 @@ func (w *RedisOperationWaiter) Conf() *resource.StateChangeConf {
}
}
func redisOperationWait(service *redis.Service, op *redis.Operation, project, activity string) error {
return redisOperationWaitTime(service, op, project, activity, 4)
}
func redisOperationWaitTime(service *redis.Service, op *redis.Operation, project, activity string, timeoutMin int) error {
if op.Done {
if op.Error != nil {

View File

@ -121,7 +121,7 @@ func TestAccComputeAttachedDisk_count(t *testing.T) {
// testCheckAttachedDiskIsNowDetached queries a compute instance and iterates through the attached
// disks to confirm that a specific disk is no longer attached to the instance
//
// This is being used instead of a CheckDestory method because destory will delete both the compute
// This is being used instead of a CheckDestroy method because destroy will delete both the compute
// instance and the disk, whereas destroying just the attached disk should only detach the disk but
// leave the instance and disk around. So just using a normal check destroy could end up with a
// situation where the detach fails but since the instance/disk get destroyed we wouldn't notice.

View File

@ -10,7 +10,6 @@ import (
"strings"
computeBeta "google.golang.org/api/compute/v0.beta"
"google.golang.org/api/compute/v1"
)
@ -312,35 +311,6 @@ func testAccCheckComputeFirewallExists(n string, firewall *compute.Firewall) res
}
}
func testAccCheckComputeBetaFirewallExists(n string, firewall *computeBeta.Firewall) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.Primary.ID == "" {
return fmt.Errorf("No ID is set")
}
config := testAccProvider.Meta().(*Config)
found, err := config.clientComputeBeta.Firewalls.Get(
config.Project, rs.Primary.ID).Do()
if err != nil {
return err
}
if found.Name != rs.Primary.ID {
return fmt.Errorf("Firewall not found")
}
*firewall = *found
return nil
}
}
func testAccCheckComputeFirewallHasPriority(firewall *compute.Firewall, priority int) resource.TestCheckFunc {
return func(s *terraform.State) error {
if firewall.Priority != int64(priority) {
@ -402,18 +372,6 @@ func testAccCheckComputeFirewallServiceAccounts(sourceSa, targetSa string, firew
}
}
func testAccCheckComputeFirewallBetaApiVersion(firewall *computeBeta.Firewall) resource.TestCheckFunc {
return func(s *terraform.State) error {
// The self-link of the network field is used to determine which API was used when fetching
// the state from the API.
if !strings.Contains(firewall.Network, "compute/beta") {
return fmt.Errorf("firewall beta API was not used")
}
return nil
}
}
func testAccCheckComputeFirewallApiVersion(firewall *compute.Firewall) resource.TestCheckFunc {
return func(s *terraform.State) error {
// The self-link of the network field is used to determine which API was used when fetching

View File

@ -355,31 +355,6 @@ func flattenNamedPortsBeta(namedPorts []*computeBeta.NamedPort) []map[string]int
}
func flattenVersions(versions []*computeBeta.InstanceGroupManagerVersion) []map[string]interface{} {
result := make([]map[string]interface{}, 0, len(versions))
for _, version := range versions {
versionMap := make(map[string]interface{})
versionMap["name"] = version.Name
versionMap["instance_template"] = ConvertSelfLinkToV1(version.InstanceTemplate)
versionMap["target_size"] = flattenFixedOrPercent(version.TargetSize)
result = append(result, versionMap)
}
return result
}
func flattenFixedOrPercent(fixedOrPercent *computeBeta.FixedOrPercent) []map[string]interface{} {
result := make(map[string]interface{})
if value := fixedOrPercent.Percent; value > 0 {
result["percent"] = value
} else if value := fixedOrPercent.Fixed; value > 0 {
result["fixed"] = fixedOrPercent.Fixed
} else {
return []map[string]interface{}{}
}
return []map[string]interface{}{result}
}
func getManager(d *schema.ResourceData, meta interface{}) (*computeBeta.InstanceGroupManager, error) {
config := meta.(*Config)
zonalID, err := parseInstanceGroupManagerId(d.Id())
@ -706,7 +681,7 @@ func resourceComputeInstanceGroupManagerDelete(d *schema.ResourceData, meta inte
return fmt.Errorf("Error, instance group isn't shrinking during delete")
}
log.Printf("[INFO] timeout occured, but instance group is shrinking (%d < %d)", instanceGroupSize, currentSize)
log.Printf("[INFO] timeout occurred, but instance group is shrinking (%d < %d)", instanceGroupSize, currentSize)
currentSize = instanceGroupSize
err = computeSharedOperationWait(config.clientCompute, op, zonalID.Project, "Deleting InstanceGroupManager")
}

View File

@ -44,7 +44,7 @@ func validatePeerAddr(i interface{}, val string) ([]string, []error) {
return nil, nil
}
// invalidPeerAddrs is a collection of IP addres ranges that represent
// invalidPeerAddrs is a collection of IP address ranges that represent
// a conflict with RFC 5735 (https://tools.ietf.org/html/rfc5735#page-3).
// CIDR range notations in the RFC were converted to a (from, to) pair
// for easy checking with bytes.Compare.

View File

@ -1345,23 +1345,6 @@ resource "google_container_cluster" "with_master_auth" {
}`, clusterName)
}
func testAccContainerCluster_updateMasterAuthNoCert() string {
return fmt.Sprintf(`
resource "google_container_cluster" "with_master_auth" {
name = "cluster-test-%s"
zone = "us-central1-a"
initial_node_count = 3
master_auth {
username = "mr.yoda"
password = "adoy.rm.123456789"
client_certificate_config {
issue_client_certificate = false
}
}
}`, acctest.RandString(10))
}
func testAccContainerCluster_withMasterAuthNoCert() string {
return fmt.Sprintf(`
resource "google_container_cluster" "with_master_auth_no_cert" {

View File

@ -274,7 +274,7 @@ func resourceDataprocCluster() *schema.Resource {
// get a diff. To make this easier, 'properties' simply contains the computed
// values (including overrides) for all properties, whilst override_properties
// is only for properties the user specifically wants to override. If nothing
// is overriden, this will be empty.
// is overridden, this will be empty.
},
},
},

View File

@ -282,7 +282,7 @@ func resourceGoogleProjectRead(d *schema.ResourceData, meta interface{}) error {
}
d.Set("project_id", pid)
d.Set("number", strconv.FormatInt(int64(p.ProjectNumber), 10))
d.Set("number", strconv.FormatInt(p.ProjectNumber, 10))
d.Set("name", p.Name)
d.Set("labels", p.Labels)

View File

@ -132,69 +132,6 @@ func resourceGoogleServiceAccountUpdate(d *schema.ResourceData, meta interface{}
return nil
}
// Retrieve the existing IAM Policy for a service account
func getServiceAccountIamPolicy(sa string, config *Config) (*iam.Policy, error) {
p, err := config.clientIAM.Projects.ServiceAccounts.GetIamPolicy(sa).Do()
if err != nil {
return nil, fmt.Errorf("Error retrieving IAM policy for service account %q: %s", sa, err)
}
return p, nil
}
// Convert a map of roles->members to a list of Binding
func saRolesToMembersBinding(m map[string]map[string]bool) []*iam.Binding {
bindings := make([]*iam.Binding, 0)
for role, members := range m {
b := iam.Binding{
Role: role,
Members: make([]string, 0),
}
for m := range members {
b.Members = append(b.Members, m)
}
bindings = append(bindings, &b)
}
return bindings
}
// Map a role to a map of members, allowing easy merging of multiple bindings.
func saRolesToMembersMap(bindings []*iam.Binding) map[string]map[string]bool {
bm := make(map[string]map[string]bool)
// Get each binding
for _, b := range bindings {
// Initialize members map
if _, ok := bm[b.Role]; !ok {
bm[b.Role] = make(map[string]bool)
}
// Get each member (user/principal) for the binding
for _, m := range b.Members {
// Add the member
bm[b.Role][m] = true
}
}
return bm
}
// Merge multiple Bindings such that Bindings with the same Role result in
// a single Binding with combined Members
func saMergeBindings(bindings []*iam.Binding) []*iam.Binding {
bm := saRolesToMembersMap(bindings)
rb := make([]*iam.Binding, 0)
for role, members := range bm {
var b iam.Binding
b.Role = role
b.Members = make([]string, 0)
for m := range members {
b.Members = append(b.Members, m)
}
rb = append(rb, &b)
}
return rb
}
func resourceGoogleServiceAccountImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
config := meta.(*Config)
parseImportId([]string{

View File

@ -63,7 +63,7 @@ func TestAccServiceAccount_basic(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
},
// The third step explicitely adds the same default project to the service account configuration
// The third step explicitly adds the same default project to the service account configuration
// and ensure the service account is not recreated by comparing the value of its unique_id with the one from the previous step
{
Config: testAccServiceAccountWithProject(project, accountId, displayName2),
@ -108,21 +108,3 @@ resource "google_service_account" "acceptance" {
}
`, project, account, name)
}
func testAccServiceAccountPolicy(account, project string) string {
return fmt.Sprintf(`
resource "google_service_account" "acceptance" {
account_id = "%v"
display_name = "%v"
}
data "google_iam_policy" "service_account" {
binding {
role = "roles/iam.serviceAccountActor"
members = [
"serviceAccount:%v@%v.iam.gserviceaccount.com",
]
}
}
`, account, account, account, project)
}

View File

@ -84,7 +84,7 @@ func resourceIamBindingRead(newUpdaterFunc newResourceIamUpdaterFunc) schema.Rea
p, err := updater.GetResourceIamPolicy()
if err != nil {
if isGoogleApiErrorWithCode(err, 404) {
log.Printf("[DEBUG]: Binding for role %q not found for non-existant resource %s, removing from state file.", updater.DescribeResource(), eBinding.Role)
log.Printf("[DEBUG]: Binding for role %q not found for non-existent resource %s, removing from state file.", updater.DescribeResource(), eBinding.Role)
d.SetId("")
return nil
}

View File

@ -115,7 +115,7 @@ func resourceIamMemberRead(newUpdaterFunc newResourceIamUpdaterFunc) schema.Read
p, err := updater.GetResourceIamPolicy()
if err != nil {
if isGoogleApiErrorWithCode(err, 404) {
log.Printf("[DEBUG]: Binding of member %q with role %q does not exist for non-existant resource %s, removing from state.", eMember.Members[0], eMember.Role, updater.DescribeResource())
log.Printf("[DEBUG]: Binding of member %q with role %q does not exist for non-existent resource %s, removing from state.", eMember.Members[0], eMember.Role, updater.DescribeResource())
d.SetId("")
return nil
}
@ -201,7 +201,7 @@ func resourceIamMemberDelete(newUpdaterFunc newResourceIamUpdaterFunc) schema.De
})
if err != nil {
if isGoogleApiErrorWithCode(err, 404) {
log.Printf("[DEBUG]: Member %q for binding for role %q does not exist for non-existant resource %q.", member.Members[0], member.Role, updater.GetResourceId())
log.Printf("[DEBUG]: Member %q for binding for role %q does not exist for non-existent resource %q.", member.Members[0], member.Role, updater.GetResourceId())
return nil
}
return err

View File

@ -84,7 +84,7 @@ func ResourceIamPolicyRead(newUpdaterFunc newResourceIamUpdaterFunc) schema.Read
policy, err := updater.GetResourceIamPolicy()
if err != nil {
if isGoogleApiErrorWithCode(err, 404) {
log.Printf("[DEBUG]: Policy does not exist for non-existant resource %q", updater.GetResourceId())
log.Printf("[DEBUG]: Policy does not exist for non-existent resource %q", updater.GetResourceId())
return nil
}
return err

View File

@ -66,10 +66,6 @@ func (s *kmsCryptoKeyId) cryptoKeyId() string {
return fmt.Sprintf("%s/cryptoKeys/%s", s.KeyRingId.keyRingId(), s.Name)
}
func (s *kmsCryptoKeyId) parentId() string {
return s.KeyRingId.keyRingId()
}
func (s *kmsCryptoKeyId) terraformId() string {
return fmt.Sprintf("%s/%s", s.KeyRingId.terraformId(), s.Name)
}

View File

@ -93,7 +93,7 @@ func resourceKmsKeyRingCreate(d *schema.ResourceData, meta interface{}) error {
d.SetId(keyRingId.keyRingId())
return nil
}, time.Duration(30*time.Second))
}, 30*time.Second)
if err != nil {
return err
}

View File

@ -11,7 +11,6 @@ import (
"github.com/hashicorp/errwrap"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
computeBeta "google.golang.org/api/compute/v0.beta"
"google.golang.org/api/compute/v1"
"google.golang.org/api/googleapi"
@ -43,20 +42,6 @@ func getRegion(d TerraformResourceData, config *Config) (string, error) {
return getRegionFromSchema("region", "zone", d, config)
}
func getRegionFromInstanceState(is *terraform.InstanceState, config *Config) (string, error) {
res, ok := is.Attributes["region"]
if ok && res != "" {
return res, nil
}
if config.Region != "" {
return config.Region, nil
}
return "", fmt.Errorf("region: required field is not set")
}
// getProject reads the "project" field from the given resource data and falls
// back to the provider's value if not given. If the provider's value is not
// given, an error is returned.
@ -78,20 +63,6 @@ func getProjectFromDiff(d *schema.ResourceDiff, config *Config) (string, error)
return "", fmt.Errorf("%s: required field is not set", "project")
}
func getProjectFromInstanceState(is *terraform.InstanceState, config *Config) (string, error) {
res, ok := is.Attributes["project"]
if ok && res != "" {
return res, nil
}
if config.Project != "" {
return config.Project, nil
}
return "", fmt.Errorf("project: required field is not set")
}
func getZonalResourceFromRegion(getResource func(string) (interface{}, error), region string, compute *compute.Service, project string) (interface{}, error) {
zoneList, err := compute.Zones.List(project).Do()
if err != nil {