-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #402 from cloudskiff/issue_366_lotoussa
Fix aws_iam_policy_attachment false-positives
- Loading branch information
Showing
7 changed files
with
147 additions
and
20 deletions.
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
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
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,25 @@ | ||
package aws | ||
|
||
import ( | ||
"github.com/cloudskiff/driftctl/pkg/resource" | ||
) | ||
|
||
func (r *AwsIamPolicyAttachment) NormalizeForState() (resource.Resource, error) { | ||
if r.Groups != nil && len(*r.Groups) == 0 { | ||
r.Groups = nil | ||
} | ||
if r.Users != nil && len(*r.Users) == 0 { | ||
r.Users = nil | ||
} | ||
return r, nil | ||
} | ||
|
||
func (r *AwsIamPolicyAttachment) NormalizeForProvider() (resource.Resource, error) { | ||
if r.Groups != nil && len(*r.Groups) == 0 { | ||
r.Groups = nil | ||
} | ||
if r.Users != nil && len(*r.Users) == 0 { | ||
r.Users = nil | ||
} | ||
return r, 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,25 @@ | ||
package aws_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cloudskiff/driftctl/test/acceptance" | ||
) | ||
|
||
func TestAcc_AwsIamPolicyAttachment_WithGroupsUsers(t *testing.T) { | ||
acceptance.Run(t, acceptance.AccTestCase{ | ||
Paths: []string{"./testdata/acc/aws_iam_policy_attachment"}, | ||
Args: []string{"scan", "--filter", "Type=='aws_iam_policy_attachment'"}, | ||
Checks: []acceptance.AccCheck{ | ||
{ | ||
Check: func(result *acceptance.ScanResult, stdout string, err error) { | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
result.AssertDriftCountTotal(0) | ||
result.Equal(1, result.Summary().TotalManaged) | ||
}, | ||
}, | ||
}, | ||
}) | ||
} |
21 changes: 21 additions & 0 deletions
21
pkg/resource/aws/testdata/acc/aws_iam_policy_attachment/.terraform.lock.hcl
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
pkg/resource/aws/testdata/acc/aws_iam_policy_attachment/iam_policy_attachment.tf
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,46 @@ | ||
resource "aws_iam_role" "yaddi" { | ||
name = "driftctl-lambda-role2" | ||
path = "/service-role/" | ||
assume_role_policy = <<EOF | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Principal": { | ||
"Service": "lambda.amazonaws.com" | ||
}, | ||
"Effect": "Allow", | ||
"Sid": "" | ||
} | ||
] | ||
} | ||
EOF | ||
} | ||
|
||
resource "aws_iam_policy" "yadda" { | ||
name = "policy" | ||
|
||
policy = <<EOF | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"sqs:ReceiveMessage", | ||
"sqs:DeleteMessage", | ||
"sqs:GetQueueAttributes" | ||
], | ||
"Resource": "*" | ||
} | ||
] | ||
} | ||
EOF | ||
} | ||
|
||
resource "aws_iam_policy_attachment" "yaddattach" { | ||
name = "yaddattachment2" | ||
roles = [aws_iam_role.yaddi.name] | ||
policy_arn = aws_iam_policy.yadda.arn | ||
} |
10 changes: 10 additions & 0 deletions
10
pkg/resource/aws/testdata/acc/aws_iam_policy_attachment/providers.tf
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,10 @@ | ||
provider "aws" { | ||
region = "us-east-1" | ||
} | ||
terraform { | ||
required_providers { | ||
aws = { | ||
version = "~> 3.19.0" | ||
} | ||
} | ||
} |