Skip to content
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

Ability to define roles with inline policy in the iam.Role resource #745

Merged
merged 2 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions apis/iam/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 30 additions & 2 deletions apis/iam/v1beta1/zz_role_types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions config/iam/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@ func Configure(p *config.Provider) {
})

p.AddResourceConfigurator("aws_iam_role", func(r *config.Resource) {
// Mutually exclusive with:
// aws_iam_policy_attachment
// aws_iam_role_policy_attachment
// aws_iam_role_policy
config.MoveToStatus(r.TerraformResource, "inline_policy", "managed_policy_arns")
r.MetaResource.ArgumentDocs["inline_policy"] = `Configuration block defining an exclusive set of IAM inline policies associated with the IAM role. See below. If no blocks are configured, Crossplane will not manage any inline policies in this resource. Configuring one empty block (i.e., inline_policy {}) will cause Crossplane to remove all inline policies added out of band on apply.`
r.MetaResource.ArgumentDocs["managed_policy_arns"] = `Set of exclusive IAM managed policy ARNs to attach to the IAM role. If this attribute is not configured, Crossplane will ignore policy attachments to this resource. When configured, Crossplane will align the role's managed policy attachments with this set by attaching or detaching managed policies. Configuring an empty set (i.e., managed_policy_arns = []) will cause Crossplane to remove all managed policy attachments.`
})

p.AddResourceConfigurator("aws_iam_instance_profile", func(r *config.Resource) {
Expand Down
36 changes: 36 additions & 0 deletions examples/iam/role-with-inline-policy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apiVersion: iam.aws.upbound.io/v1beta1
kind: Role
metadata:
annotations:
meta.upbound.io/example-id: iam/v1beta1/role
labels:
testing.upbound.io/example-name: role
name: role-with-inline-policy
spec:
forProvider:
assumeRolePolicy: |
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "eks.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
inlinePolicy:
- name: "my_inline_policy"
policy: |
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Resource": "*",
"Action": "ec2:Describe*"
}
]
}
70 changes: 68 additions & 2 deletions package/crds/iam.aws.upbound.io_roles.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,35 @@ spec:
description: Whether to force detaching any policies the role
has before destroying it. Defaults to false.
type: boolean
inlinePolicy:
description: Configuration block defining an exclusive set of
IAM inline policies associated with the IAM role. See below.
If no blocks are configured, Crossplane will not manage any
inline policies in this resource. Configuring one empty block
(i.e., inline_policy {}) will cause Crossplane to remove all
inline policies added out of band on apply.
items:
properties:
name:
description: Friendly name of the role. See IAM Identifiers
for more information.
type: string
policy:
description: Policy document as a JSON formatted string.
type: string
type: object
type: array
managedPolicyArns:
description: Set of exclusive IAM managed policy ARNs to attach
to the IAM role. If this attribute is not configured, Crossplane
will ignore policy attachments to this resource. When configured,
Crossplane will align the role's managed policy attachments
with this set by attaching or detaching managed policies. Configuring
an empty set (i.e., managed_policy_arns = []) will cause Crossplane
to remove all managed policy attachments.
items:
type: string
type: array
maxSessionDuration:
description: Maximum session duration (in seconds) that you want
to set for the specified role. If you do not specify a value
Expand Down Expand Up @@ -120,6 +149,35 @@ spec:
description: Whether to force detaching any policies the role
has before destroying it. Defaults to false.
type: boolean
inlinePolicy:
description: Configuration block defining an exclusive set of
IAM inline policies associated with the IAM role. See below.
If no blocks are configured, Crossplane will not manage any
inline policies in this resource. Configuring one empty block
(i.e., inline_policy {}) will cause Crossplane to remove all
inline policies added out of band on apply.
items:
properties:
name:
description: Friendly name of the role. See IAM Identifiers
for more information.
type: string
policy:
description: Policy document as a JSON formatted string.
type: string
type: object
type: array
managedPolicyArns:
description: Set of exclusive IAM managed policy ARNs to attach
turkenf marked this conversation as resolved.
Show resolved Hide resolved
to the IAM role. If this attribute is not configured, Crossplane
will ignore policy attachments to this resource. When configured,
Crossplane will align the role's managed policy attachments
with this set by attaching or detaching managed policies. Configuring
an empty set (i.e., managed_policy_arns = []) will cause Crossplane
to remove all managed policy attachments.
items:
type: string
type: array
maxSessionDuration:
description: Maximum session duration (in seconds) that you want
to set for the specified role. If you do not specify a value
Expand Down Expand Up @@ -369,7 +427,10 @@ spec:
inlinePolicy:
description: Configuration block defining an exclusive set of
IAM inline policies associated with the IAM role. See below.
Configuring one empty block (i.e.
If no blocks are configured, Crossplane will not manage any
inline policies in this resource. Configuring one empty block
(i.e., inline_policy {}) will cause Crossplane to remove all
inline policies added out of band on apply.
items:
properties:
name:
Expand All @@ -383,7 +444,12 @@ spec:
type: array
managedPolicyArns:
description: Set of exclusive IAM managed policy ARNs to attach
to the IAM role. Configuring an empty set (i.e.
to the IAM role. If this attribute is not configured, Crossplane
will ignore policy attachments to this resource. When configured,
Crossplane will align the role's managed policy attachments
with this set by attaching or detaching managed policies. Configuring
an empty set (i.e., managed_policy_arns = []) will cause Crossplane
to remove all managed policy attachments.
items:
type: string
type: array
Expand Down