github.com/recobe182/terraform@v0.8.5-0.20170117231232-49ab22a935b7/builtin/providers/aws/resource_aws_inspector_resource_group.go (about) 1 package aws 2 3 import ( 4 "log" 5 6 "github.com/aws/aws-sdk-go/aws" 7 "github.com/aws/aws-sdk-go/aws/awserr" 8 "github.com/aws/aws-sdk-go/service/inspector" 9 "github.com/hashicorp/terraform/helper/schema" 10 ) 11 12 func resourceAWSInspectorResourceGroup() *schema.Resource { 13 return &schema.Resource{ 14 Create: resourceAwsInspectorResourceGroupCreate, 15 Read: resourceAwsInspectorResourceGroupRead, 16 Delete: resourceAwsInspectorResourceGroupDelete, 17 18 Schema: map[string]*schema.Schema{ 19 "tags": &schema.Schema{ 20 ForceNew: true, 21 Type: schema.TypeMap, 22 Required: true, 23 }, 24 "arn": &schema.Schema{ 25 Type: schema.TypeString, 26 Computed: true, 27 }, 28 }, 29 } 30 } 31 32 func resourceAwsInspectorResourceGroupCreate(d *schema.ResourceData, meta interface{}) error { 33 conn := meta.(*AWSClient).inspectorconn 34 35 resp, err := conn.CreateResourceGroup(&inspector.CreateResourceGroupInput{ 36 ResourceGroupTags: tagsFromMapInspector(d.Get("tags").(map[string]interface{})), 37 }) 38 39 if err != nil { 40 return err 41 } 42 43 d.Set("arn", *resp.ResourceGroupArn) 44 45 d.SetId(*resp.ResourceGroupArn) 46 47 return resourceAwsInspectorResourceGroupRead(d, meta) 48 } 49 50 func resourceAwsInspectorResourceGroupRead(d *schema.ResourceData, meta interface{}) error { 51 conn := meta.(*AWSClient).inspectorconn 52 53 _, err := conn.DescribeResourceGroups(&inspector.DescribeResourceGroupsInput{ 54 ResourceGroupArns: []*string{ 55 aws.String(d.Id()), 56 }, 57 }) 58 59 if err != nil { 60 if inspectorerr, ok := err.(awserr.Error); ok && inspectorerr.Code() == "InvalidInputException" { 61 return nil 62 } else { 63 log.Printf("[ERROR] Error finding Inspector resource group: %s", err) 64 return err 65 } 66 } 67 68 return nil 69 } 70 71 func resourceAwsInspectorResourceGroupDelete(d *schema.ResourceData, meta interface{}) error { 72 d.Set("arn", "") 73 d.SetId("") 74 75 return nil 76 }