provider/aws: Update of inspector_assessment_target should use ARN not (#12115)

Name

fixes: #12112

```
% make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSInspectorTarget_basic'                                                  ✚
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2017/02/20 19:08:18 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSInspectorTarget_basic -timeout 120m
=== RUN   TestAccAWSInspectorTarget_basic
--- PASS: TestAccAWSInspectorTarget_basic (33.58s)
PASS
ok  	github.com/hashicorp/terraform/builtin/providers/aws	33.607s
```
This commit is contained in:
Paul Stack 2017-02-20 20:12:17 +02:00 committed by GitHub
parent facc50d308
commit 2fce519f57
2 changed files with 33 additions and 16 deletions

View File

@ -19,16 +19,16 @@ func resourceAWSInspectorAssessmentTarget() *schema.Resource {
Delete: resourceAwsInspectorAssessmentTargetDelete, Delete: resourceAwsInspectorAssessmentTargetDelete,
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
"name": &schema.Schema{ "name": {
Type: schema.TypeString, Type: schema.TypeString,
ForceNew: true, ForceNew: true,
Required: true, Required: true,
}, },
"arn": &schema.Schema{ "arn": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"resource_group_arn": &schema.Schema{ "resource_group_arn": {
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Required: true,
}, },
@ -86,17 +86,9 @@ func resourceAwsInspectorAssessmentTargetUpdate(d *schema.ResourceData, meta int
conn := meta.(*AWSClient).inspectorconn conn := meta.(*AWSClient).inspectorconn
input := inspector.UpdateAssessmentTargetInput{ input := inspector.UpdateAssessmentTargetInput{
AssessmentTargetArn: aws.String(d.Id()), AssessmentTargetArn: aws.String(d.Id()),
} AssessmentTargetName: aws.String(d.Get("name").(string)),
ResourceGroupArn: aws.String(d.Get("resource_group_arn").(string)),
if d.HasChange("name") {
_, n := d.GetChange("name")
input.AssessmentTargetName = aws.String(n.(string))
}
if d.HasChange("resource_group_arn") {
_, n := d.GetChange("resource_group_arn")
input.AssessmentTargetName = aws.String(n.(string))
} }
_, err := conn.UpdateAssessmentTarget(&input) _, err := conn.UpdateAssessmentTarget(&input)

View File

@ -17,18 +17,24 @@ func TestAccAWSInspectorTarget_basic(t *testing.T) {
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckAWSInspectorTargetAssessmentDestroy, CheckDestroy: testAccCheckAWSInspectorTargetAssessmentDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccAWSInspectorTargetAssessment, Config: testAccAWSInspectorTargetAssessment,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckAWSInspectorTargetExists("aws_inspector_assessment_target.foo"), testAccCheckAWSInspectorTargetExists("aws_inspector_assessment_target.foo"),
), ),
}, },
resource.TestStep{ {
Config: testAccCheckAWSInspectorTargetAssessmentModified, Config: testAccCheckAWSInspectorTargetAssessmentModified,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckAWSInspectorTargetExists("aws_inspector_assessment_target.foo"), testAccCheckAWSInspectorTargetExists("aws_inspector_assessment_target.foo"),
), ),
}, },
{
Config: testAccCheckAWSInspectorTargetAssessmentUpdatedResourceGroup,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSInspectorTargetExists("aws_inspector_assessment_target.foo"),
),
},
}, },
}) })
} }
@ -99,3 +105,22 @@ resource "aws_inspector_assessment_target" "foo" {
name = "bar" name = "bar"
resource_group_arn = "${aws_inspector_resource_group.foo.arn}" resource_group_arn = "${aws_inspector_resource_group.foo.arn}"
}` }`
var testAccCheckAWSInspectorTargetAssessmentUpdatedResourceGroup = `
resource "aws_inspector_resource_group" "foo" {
tags {
Name = "bar"
}
}
resource "aws_inspector_resource_group" "bar" {
tags {
Name = "test"
}
}
resource "aws_inspector_assessment_target" "foo" {
name = "bar"
resource_group_arn = "${aws_inspector_resource_group.bar.arn}"
}`