forked from hashicorp/terraform-provider-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_source_aws_inspector_rules_packages.go
56 lines (44 loc) · 1.16 KB
/
data_source_aws_inspector_rules_packages.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
package aws
import (
"errors"
"fmt"
"log"
"sort"
"time"
"github.com/aws/aws-sdk-go/service/inspector"
"github.com/hashicorp/terraform/helper/schema"
)
func dataSourceAwsInspectorRulesPackages() *schema.Resource {
return &schema.Resource{
Read: dataSourceAwsInspectorRulesPackagesRead,
Schema: map[string]*schema.Schema{
"arns": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
}
}
func dataSourceAwsInspectorRulesPackagesRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).inspectorconn
log.Printf("[DEBUG] Reading Rules Packages.")
d.SetId(time.Now().UTC().String())
var arns []string
input := &inspector.ListRulesPackagesInput{}
err := conn.ListRulesPackagesPages(input, func(page *inspector.ListRulesPackagesOutput, lastPage bool) bool {
for _, arn := range page.RulesPackageArns {
arns = append(arns, *arn)
}
return !lastPage
})
if err != nil {
return fmt.Errorf("Error fetching Rules Packages: %s", err)
}
if len(arns) == 0 {
return errors.New("No rules packages found.")
}
sort.Strings(arns)
d.Set("arns", arns)
return nil
}