forked from hashicorp/terraform-provider-aws
/
data_source_aws_db_event_categories.go
66 lines (52 loc) · 1.53 KB
/
data_source_aws_db_event_categories.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
package aws
import (
"fmt"
"log"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/rds"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
)
func dataSourceAwsDbEventCategories() *schema.Resource {
return &schema.Resource{
Read: dataSourceAwsDbEventCategoriesRead,
Schema: map[string]*schema.Schema{
"source_type": {
Type: schema.TypeString,
Optional: true,
},
"event_categories": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},
},
}
}
func dataSourceAwsDbEventCategoriesRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).rdsconn
req := &rds.DescribeEventCategoriesInput{}
if sourceType := d.Get("source_type").(string); sourceType != "" {
req.SourceType = aws.String(sourceType)
}
log.Printf("[DEBUG] Describe Event Categories %s\n", req)
resp, err := conn.DescribeEventCategories(req)
if err != nil {
return err
}
if resp == nil || len(resp.EventCategoriesMapList) == 0 {
return fmt.Errorf("Event Categories not found")
}
eventCategories := make([]string, 0)
for _, eventMap := range resp.EventCategoriesMapList {
for _, v := range eventMap.EventCategories {
eventCategories = append(eventCategories, aws.StringValue(v))
}
}
d.SetId(resource.UniqueId())
if err := d.Set("event_categories", eventCategories); err != nil {
return fmt.Errorf("Error setting Event Categories: %s", err)
}
return nil
}