diff --git a/builtin/providers/aws/resource_aws_ssm_association.go b/builtin/providers/aws/resource_aws_ssm_association.go index afcac84539..cb3af1d687 100644 --- a/builtin/providers/aws/resource_aws_ssm_association.go +++ b/builtin/providers/aws/resource_aws_ssm_association.go @@ -48,21 +48,20 @@ func resourceAwsSsmAssociationCreate(d *schema.ResourceData, meta interface{}) e } if v, ok := d.GetOk("parameters"); ok { - assosciationInput.Parameters = expandDocumentParameters(v.(map[string]interface{})) + assosciationInput.Parameters = expandSSMDocumentParameters(v.(map[string]interface{})) } resp, err := ssmconn.CreateAssociation(assosciationInput) - if err != nil { return errwrap.Wrapf("[ERROR] Error creating SSM association: {{err}}", err) } - if resp.AssociationDescription != nil { - d.SetId(*resp.AssociationDescription.Name) - } else { + if resp.AssociationDescription == nil { return fmt.Errorf("[ERROR] AssociationDescription was nil") } + d.SetId(*resp.AssociationDescription.Name) + return resourceAwsSsmAssociationRead(d, meta) } @@ -81,18 +80,15 @@ func resourceAwsSsmAssociationRead(d *schema.ResourceData, meta interface{}) err if err != nil { return errwrap.Wrapf("[ERROR] Error reading SSM association: {{err}}", err) } - - if resp.AssociationDescription != nil { - association := resp.AssociationDescription - - d.Set("instance_id", association.InstanceId) - d.Set("name", association.Name) - d.Set("parameters", association.Parameters) - - } else { + if resp.AssociationDescription == nil { return fmt.Errorf("[ERROR] AssociationDescription was nil") } + association := resp.AssociationDescription + d.Set("instance_id", association.InstanceId) + d.Set("name", association.Name) + d.Set("parameters", association.Parameters) + return nil } @@ -115,7 +111,7 @@ func resourceAwsSsmAssociationDelete(d *schema.ResourceData, meta interface{}) e return nil } -func expandDocumentParameters(params map[string]interface{}) map[string][]*string { +func expandSSMDocumentParameters(params map[string]interface{}) map[string][]*string { var docParams = make(map[string][]*string) for k, v := range params { var values []*string diff --git a/builtin/providers/aws/resource_aws_ssm_association_test.go b/builtin/providers/aws/resource_aws_ssm_association_test.go index 3a8e1ec895..42454cd396 100644 --- a/builtin/providers/aws/resource_aws_ssm_association_test.go +++ b/builtin/providers/aws/resource_aws_ssm_association_test.go @@ -98,10 +98,9 @@ resource "aws_security_group" "tf_test_foo" { } resource "aws_instance" "foo" { - # eu-west-1 - ami = "ami-f77ac884" - availability_zone = "eu-west-1a" - instance_type = "t2.small" + ami = "ami-4fccb37f" + availability_zone = "us-west-2a" + instance_type = "m1.small" security_groups = ["${aws_security_group.tf_test_foo.name}"] }