From 2fce519f570c9ac8304e9cb073076271e2429ba5 Mon Sep 17 00:00:00 2001 From: Paul Stack Date: Mon, 20 Feb 2017 20:12:17 +0200 Subject: [PATCH] provider/aws: Update of inspector_assessment_target should use ARN not (#12115) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 ``` --- ...esource_aws_inspector_assessment_target.go | 20 ++++--------- ...ce_aws_inspector_assessment_target_test.go | 29 +++++++++++++++++-- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/builtin/providers/aws/resource_aws_inspector_assessment_target.go b/builtin/providers/aws/resource_aws_inspector_assessment_target.go index 8b5db9ae4..b6c2c80c0 100644 --- a/builtin/providers/aws/resource_aws_inspector_assessment_target.go +++ b/builtin/providers/aws/resource_aws_inspector_assessment_target.go @@ -19,16 +19,16 @@ func resourceAWSInspectorAssessmentTarget() *schema.Resource { Delete: resourceAwsInspectorAssessmentTargetDelete, Schema: map[string]*schema.Schema{ - "name": &schema.Schema{ + "name": { Type: schema.TypeString, ForceNew: true, Required: true, }, - "arn": &schema.Schema{ + "arn": { Type: schema.TypeString, Computed: true, }, - "resource_group_arn": &schema.Schema{ + "resource_group_arn": { Type: schema.TypeString, Required: true, }, @@ -86,17 +86,9 @@ func resourceAwsInspectorAssessmentTargetUpdate(d *schema.ResourceData, meta int conn := meta.(*AWSClient).inspectorconn input := inspector.UpdateAssessmentTargetInput{ - AssessmentTargetArn: aws.String(d.Id()), - } - - 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)) + AssessmentTargetArn: aws.String(d.Id()), + AssessmentTargetName: aws.String(d.Get("name").(string)), + ResourceGroupArn: aws.String(d.Get("resource_group_arn").(string)), } _, err := conn.UpdateAssessmentTarget(&input) diff --git a/builtin/providers/aws/resource_aws_inspector_assessment_target_test.go b/builtin/providers/aws/resource_aws_inspector_assessment_target_test.go index a8eaba7ac..5f8f019e8 100644 --- a/builtin/providers/aws/resource_aws_inspector_assessment_target_test.go +++ b/builtin/providers/aws/resource_aws_inspector_assessment_target_test.go @@ -17,18 +17,24 @@ func TestAccAWSInspectorTarget_basic(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckAWSInspectorTargetAssessmentDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccAWSInspectorTargetAssessment, Check: resource.ComposeTestCheckFunc( testAccCheckAWSInspectorTargetExists("aws_inspector_assessment_target.foo"), ), }, - resource.TestStep{ + { Config: testAccCheckAWSInspectorTargetAssessmentModified, Check: resource.ComposeTestCheckFunc( 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" 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}" +}`