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