From 4a5847f9ea6ed8ca378daf522704711baec51614 Mon Sep 17 00:00:00 2001 From: clint shryock Date: Tue, 1 Dec 2015 09:31:20 -0600 Subject: [PATCH] providers/aws: Vet aws --- ...rce_aws_autoscaling_lifecycle_hook_test.go | 1 - ...ource_aws_autoscaling_notification_test.go | 2 +- .../resource_aws_autoscaling_policy_test.go | 1 - .../resource_aws_cloudformation_stack_test.go | 1 - .../aws/resource_aws_instance_migrate.go | 2 -- .../aws/resource_aws_instance_test.go | 8 ++++---- .../aws/resource_aws_key_pair_migrate.go | 2 -- .../resource_aws_launch_configuration_test.go | 6 +++--- builtin/providers/aws/resource_aws_route.go | 20 ++++++++++--------- ...esource_aws_security_group_rule_migrate.go | 2 -- .../aws/resource_aws_vpc_dhcp_options.go | 2 -- 11 files changed, 19 insertions(+), 28 deletions(-) diff --git a/builtin/providers/aws/resource_aws_autoscaling_lifecycle_hook_test.go b/builtin/providers/aws/resource_aws_autoscaling_lifecycle_hook_test.go index f425570e9c..a32c0b1a1e 100644 --- a/builtin/providers/aws/resource_aws_autoscaling_lifecycle_hook_test.go +++ b/builtin/providers/aws/resource_aws_autoscaling_lifecycle_hook_test.go @@ -36,7 +36,6 @@ func testAccCheckLifecycleHookExists(n string, hook *autoscaling.LifecycleHook) return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { - rs = rs return fmt.Errorf("Not found: %s", n) } diff --git a/builtin/providers/aws/resource_aws_autoscaling_notification_test.go b/builtin/providers/aws/resource_aws_autoscaling_notification_test.go index 81fccfea34..242a9b23c5 100644 --- a/builtin/providers/aws/resource_aws_autoscaling_notification_test.go +++ b/builtin/providers/aws/resource_aws_autoscaling_notification_test.go @@ -144,7 +144,7 @@ func testAccCheckASGNDestroy(s *terraform.State) error { } if len(resp.NotificationConfigurations) != 0 { - fmt.Errorf("Error finding notification descriptions") + return fmt.Errorf("Error finding notification descriptions") } } diff --git a/builtin/providers/aws/resource_aws_autoscaling_policy_test.go b/builtin/providers/aws/resource_aws_autoscaling_policy_test.go index 0a7aeff916..6d402de85a 100644 --- a/builtin/providers/aws/resource_aws_autoscaling_policy_test.go +++ b/builtin/providers/aws/resource_aws_autoscaling_policy_test.go @@ -34,7 +34,6 @@ func testAccCheckScalingPolicyExists(n string, policy *autoscaling.ScalingPolicy return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { - rs = rs return fmt.Errorf("Not found: %s", n) } diff --git a/builtin/providers/aws/resource_aws_cloudformation_stack_test.go b/builtin/providers/aws/resource_aws_cloudformation_stack_test.go index 7ad24be344..0c99f8d54d 100644 --- a/builtin/providers/aws/resource_aws_cloudformation_stack_test.go +++ b/builtin/providers/aws/resource_aws_cloudformation_stack_test.go @@ -68,7 +68,6 @@ func testAccCheckCloudFormationStackExists(n string, stack *cloudformation.Stack return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { - rs = rs return fmt.Errorf("Not found: %s", n) } diff --git a/builtin/providers/aws/resource_aws_instance_migrate.go b/builtin/providers/aws/resource_aws_instance_migrate.go index 5d7075f759..c2ae3aaf2e 100644 --- a/builtin/providers/aws/resource_aws_instance_migrate.go +++ b/builtin/providers/aws/resource_aws_instance_migrate.go @@ -19,8 +19,6 @@ func resourceAwsInstanceMigrateState( default: return is, fmt.Errorf("Unexpected schema version: %d", v) } - - return is, nil } func migrateStateV0toV1(is *terraform.InstanceState) (*terraform.InstanceState, error) { diff --git a/builtin/providers/aws/resource_aws_instance_test.go b/builtin/providers/aws/resource_aws_instance_test.go index 3224f9b5e1..23c1e7b380 100644 --- a/builtin/providers/aws/resource_aws_instance_test.go +++ b/builtin/providers/aws/resource_aws_instance_test.go @@ -112,22 +112,22 @@ func TestAccAWSInstance_blockDevices(t *testing.T) { // Check if the root block device exists. if _, ok := blockDevices["/dev/sda1"]; !ok { - fmt.Errorf("block device doesn't exist: /dev/sda1") + return fmt.Errorf("block device doesn't exist: /dev/sda1") } // Check if the secondary block device exists. if _, ok := blockDevices["/dev/sdb"]; !ok { - fmt.Errorf("block device doesn't exist: /dev/sdb") + return fmt.Errorf("block device doesn't exist: /dev/sdb") } // Check if the third block device exists. if _, ok := blockDevices["/dev/sdc"]; !ok { - fmt.Errorf("block device doesn't exist: /dev/sdc") + return fmt.Errorf("block device doesn't exist: /dev/sdc") } // Check if the encrypted block device exists if _, ok := blockDevices["/dev/sdd"]; !ok { - fmt.Errorf("block device doesn't exist: /dev/sdd") + return fmt.Errorf("block device doesn't exist: /dev/sdd") } return nil diff --git a/builtin/providers/aws/resource_aws_key_pair_migrate.go b/builtin/providers/aws/resource_aws_key_pair_migrate.go index 0d56123aab..c937ac360f 100644 --- a/builtin/providers/aws/resource_aws_key_pair_migrate.go +++ b/builtin/providers/aws/resource_aws_key_pair_migrate.go @@ -17,8 +17,6 @@ func resourceAwsKeyPairMigrateState( default: return is, fmt.Errorf("Unexpected schema version: %d", v) } - - return is, nil } func migrateKeyPairStateV0toV1(is *terraform.InstanceState) (*terraform.InstanceState, error) { diff --git a/builtin/providers/aws/resource_aws_launch_configuration_test.go b/builtin/providers/aws/resource_aws_launch_configuration_test.go index c6a0086a14..1e914c86df 100644 --- a/builtin/providers/aws/resource_aws_launch_configuration_test.go +++ b/builtin/providers/aws/resource_aws_launch_configuration_test.go @@ -162,17 +162,17 @@ func testAccCheckAWSLaunchConfigurationAttributes(conf *autoscaling.LaunchConfig // Check if the root block device exists. if _, ok := blockDevices["/dev/sda1"]; !ok { - fmt.Errorf("block device doesn't exist: /dev/sda1") + return fmt.Errorf("block device doesn't exist: /dev/sda1") } // Check if the secondary block device exists. if _, ok := blockDevices["/dev/sdb"]; !ok { - fmt.Errorf("block device doesn't exist: /dev/sdb") + return fmt.Errorf("block device doesn't exist: /dev/sdb") } // Check if the third block device exists. if _, ok := blockDevices["/dev/sdc"]; !ok { - fmt.Errorf("block device doesn't exist: /dev/sdc") + return fmt.Errorf("block device doesn't exist: /dev/sdc") } // Check if the secondary block device exists. diff --git a/builtin/providers/aws/resource_aws_route.go b/builtin/providers/aws/resource_aws_route.go index 60c666ecde..3d6f5d25bb 100644 --- a/builtin/providers/aws/resource_aws_route.go +++ b/builtin/providers/aws/resource_aws_route.go @@ -1,6 +1,7 @@ package aws import ( + "errors" "fmt" "log" @@ -10,6 +11,11 @@ import ( "github.com/hashicorp/terraform/helper/schema" ) +// How long to sleep if a limit-exceeded event happens +var routeTargetValidationError = errors.New("Error: more than 1 target specified. Only 1 of gateway_id" + + "instance_id, network_interface_id, route_table_id or" + + "vpc_peering_connection_id is allowed.") + // AWS Route resource Schema declaration func resourceAwsRoute() *schema.Resource { return &schema.Resource{ @@ -94,9 +100,7 @@ func resourceAwsRouteCreate(d *schema.ResourceData, meta interface{}) error { } if numTargets > 1 { - fmt.Errorf("Error: more than 1 target specified. Only 1 of gateway_id" + - "instance_id, network_interface_id, route_table_id or" + - "vpc_peering_connection_id is allowed.") + return routeTargetValidationError } createOpts := &ec2.CreateRouteInput{} @@ -127,7 +131,7 @@ func resourceAwsRouteCreate(d *schema.ResourceData, meta interface{}) error { VpcPeeringConnectionId: aws.String(d.Get("vpc_peering_connection_id").(string)), } default: - fmt.Errorf("Error: invalid target type specified.") + return fmt.Errorf("Error: invalid target type specified.") } log.Printf("[DEBUG] Route create config: %s", createOpts) @@ -139,7 +143,7 @@ func resourceAwsRouteCreate(d *schema.ResourceData, meta interface{}) error { route, err := findResourceRoute(conn, d.Get("route_table_id").(string), d.Get("destination_cidr_block").(string)) if err != nil { - fmt.Errorf("Error: %s", err) + return err } d.SetId(routeIDHash(d, route)) @@ -187,9 +191,7 @@ func resourceAwsRouteUpdate(d *schema.ResourceData, meta interface{}) error { } if numTargets > 1 { - fmt.Errorf("Error: more than 1 target specified. Only 1 of gateway_id" + - "instance_id, network_interface_id, route_table_id or" + - "vpc_peering_connection_id is allowed.") + return routeTargetValidationError } // Formulate ReplaceRouteInput based on the target type @@ -221,7 +223,7 @@ func resourceAwsRouteUpdate(d *schema.ResourceData, meta interface{}) error { VpcPeeringConnectionId: aws.String(d.Get("vpc_peering_connection_id").(string)), } default: - fmt.Errorf("Error: invalid target type specified.") + return fmt.Errorf("Error: invalid target type specified.") } log.Printf("[DEBUG] Route replace config: %s", replaceOpts) diff --git a/builtin/providers/aws/resource_aws_security_group_rule_migrate.go b/builtin/providers/aws/resource_aws_security_group_rule_migrate.go index 0b57f3f171..12788054e3 100644 --- a/builtin/providers/aws/resource_aws_security_group_rule_migrate.go +++ b/builtin/providers/aws/resource_aws_security_group_rule_migrate.go @@ -26,8 +26,6 @@ func resourceAwsSecurityGroupRuleMigrateState( default: return is, fmt.Errorf("Unexpected schema version: %d", v) } - - return is, nil } func migrateSGRuleStateV0toV1(is *terraform.InstanceState) (*terraform.InstanceState, error) { diff --git a/builtin/providers/aws/resource_aws_vpc_dhcp_options.go b/builtin/providers/aws/resource_aws_vpc_dhcp_options.go index 36b4b1f810..de7b74108a 100644 --- a/builtin/providers/aws/resource_aws_vpc_dhcp_options.go +++ b/builtin/providers/aws/resource_aws_vpc_dhcp_options.go @@ -223,8 +223,6 @@ func resourceAwsVpcDhcpOptionsDelete(d *schema.ResourceData, meta interface{}) e // Any other error, we want to quit the retry loop immediately return resource.RetryError{Err: err} } - - return nil }) }