-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add rules packages datasource for AWS Inspector #3175
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
85370aa
Add rules packages datasource
MattiasGees 5f8b98d
Fix little bug
MattiasGees 02835c9
Modify code with PR comments
MattiasGees 51063cd
Add docs
MattiasGees 907333e
Change order
MattiasGees f762880
Rename test datasource
MattiasGees File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package aws | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccAWSInspectorRulesPackages_basic(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccCheckAWSInspectorRulesPackagesConfig, | ||
Check: resource.TestCheckResourceAttrSet("data.aws_inspector_rules_packages.test", "arns.#"), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
const testAccCheckAWSInspectorRulesPackagesConfig = ` | ||
data "aws_inspector_rules_packages" "rules_packages" { } | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -214,6 +214,7 @@ func Provider() terraform.ResourceProvider { | |
"aws_region": dataSourceAwsRegion(), | ||
"aws_route_table": dataSourceAwsRouteTable(), | ||
"aws_route53_zone": dataSourceAwsRoute53Zone(), | ||
"aws_inspector_rules_packages": dataSourceAwsInspectorRulesPackages(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor nitpick: Can you lexicographically sort this please? |
||
"aws_s3_bucket": dataSourceAwsS3Bucket(), | ||
"aws_s3_bucket_object": dataSourceAwsS3BucketObject(), | ||
"aws_sns_topic": dataSourceAwsSnsTopic(), | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
.test
here needs to either be updated to.rules_packages
to match the name intestAccCheckAWSInspectorRulesPackagesConfig
or the data source to be namedtest
in the configurationThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed it to test