-
Notifications
You must be signed in to change notification settings - Fork 175
Split aws_iam_role_policy_attachment #839
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
Merged
Merged
Changes from all commits
Commits
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
39 changes: 39 additions & 0 deletions
39
pkg/remote/aws/iam_role_policy_attachment_details_fetcher.go
This file contains hidden or 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,39 @@ | ||
package aws | ||
|
||
import ( | ||
"github.com/cloudskiff/driftctl/pkg/resource" | ||
"github.com/cloudskiff/driftctl/pkg/resource/aws" | ||
"github.com/cloudskiff/driftctl/pkg/terraform" | ||
) | ||
|
||
type IamRolePolicyAttachmentDetailsFetcher struct { | ||
reader terraform.ResourceReader | ||
deserializer *resource.Deserializer | ||
} | ||
|
||
func NewIamRolePolicyAttachmentDetailsFetcher(provider terraform.ResourceReader, deserializer *resource.Deserializer) *IamRolePolicyAttachmentDetailsFetcher { | ||
return &IamRolePolicyAttachmentDetailsFetcher{ | ||
reader: provider, | ||
deserializer: deserializer, | ||
} | ||
} | ||
|
||
func (r *IamRolePolicyAttachmentDetailsFetcher) ReadDetails(res resource.Resource) (resource.Resource, error) { | ||
ctyVal, err := r.reader.ReadResource(terraform.ReadResourceArgs{ | ||
Ty: aws.AwsIamRolePolicyAttachmentResourceType, | ||
ID: res.TerraformId(), | ||
Attributes: map[string]string{ | ||
"role": *res.Attributes().GetString("role"), | ||
"policy_arn": *res.Attributes().GetString("policy_arn"), | ||
}, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
deserializedRes, err := r.deserializer.DeserializeOne(aws.AwsIamRolePolicyAttachmentResourceType, *ctyVal) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return deserializedRes, nil | ||
} |
This file contains hidden or 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,69 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go/service/iam" | ||
"github.com/cloudskiff/driftctl/pkg/remote/aws/repository" | ||
remoteerror "github.com/cloudskiff/driftctl/pkg/remote/error" | ||
"github.com/cloudskiff/driftctl/pkg/resource" | ||
resourceaws "github.com/cloudskiff/driftctl/pkg/resource/aws" | ||
) | ||
|
||
type IamRolePolicyAttachmentEnumerator struct { | ||
repository repository.IAMRepository | ||
factory resource.ResourceFactory | ||
} | ||
|
||
func NewIamRolePolicyAttachmentEnumerator(repository repository.IAMRepository, factory resource.ResourceFactory) *IamRolePolicyAttachmentEnumerator { | ||
return &IamRolePolicyAttachmentEnumerator{ | ||
repository, | ||
factory, | ||
} | ||
} | ||
|
||
func (e *IamRolePolicyAttachmentEnumerator) SupportedType() resource.ResourceType { | ||
return resourceaws.AwsIamRolePolicyAttachmentResourceType | ||
} | ||
|
||
func (e *IamRolePolicyAttachmentEnumerator) Enumerate() ([]resource.Resource, error) { | ||
roles, err := e.repository.ListAllRoles() | ||
if err != nil { | ||
return nil, remoteerror.NewResourceEnumerationErrorWithType(err, string(e.SupportedType()), resourceaws.AwsIamRoleResourceType) | ||
} | ||
|
||
results := make([]resource.Resource, 0) | ||
rolesNotIgnored := make([]*iam.Role, 0) | ||
|
||
for _, role := range roles { | ||
if role.RoleName != nil && awsIamRoleShouldBeIgnored(*role.RoleName) { | ||
continue | ||
} | ||
rolesNotIgnored = append(rolesNotIgnored, role) | ||
} | ||
|
||
if len(rolesNotIgnored) == 0 { | ||
return results, nil | ||
} | ||
|
||
policyAttachments, err := e.repository.ListAllRolePolicyAttachments(rolesNotIgnored) | ||
if err != nil { | ||
return nil, remoteerror.NewResourceEnumerationError(err, string(e.SupportedType())) | ||
} | ||
|
||
for _, attachedPol := range policyAttachments { | ||
results = append( | ||
results, | ||
e.factory.CreateAbstractResource( | ||
string(e.SupportedType()), | ||
fmt.Sprintf("%s-%s", *attachedPol.PolicyName, attachedPol.RoleName), | ||
map[string]interface{}{ | ||
"role": attachedPol.RoleName, | ||
"policy_arn": *attachedPol.PolicyArn, | ||
}, | ||
), | ||
) | ||
} | ||
|
||
return results, nil | ||
} |
This file was deleted.
Oops, something went wrong.
168 changes: 0 additions & 168 deletions
168
pkg/remote/aws/iam_role_policy_attachment_supplier_test.go
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
Oops, something went wrong.
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.
I know we already did that in every other details fetchers, but is there a reason to not use the resource type defined by the enumerator ? We could just call
res.TerraformType()
here