generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 130
docs: added example for EFS CSI Driver in an EKS Cluster #2186
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
Show all changes
8 commits
Select commit
Hold shift + click to select a range
10d87c4
Create eks_addon_efs_csi_driver.tf
LearningNewbie 7f503ed
Update eks_addon.md.tmpl
LearningNewbie 52689b1
Update eks_addon.md
LearningNewbie d1afceb
Update eks_addon.md
LearningNewbie aa81080
Update eks_addon.md
LearningNewbie 120dfe4
Update eks_addon_efs_csi_driver.tf
LearningNewbie d4679a4
Merge branch 'hashicorp:main' into d-improve-eks-addon
LearningNewbie 06d03ff
Update eks_addon.md
LearningNewbie 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 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
82 changes: 82 additions & 0 deletions
82
examples/resources/awscc_eks_addon/eks_addon_efs_csi_driver.tf
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,82 @@ | ||
# AWS IAM expects the OIDC provider URL without the `https://` prefix in the condition block.This creates a local variable for it: | ||
|
||
locals { | ||
oidc_provider = replace(awscc_eks_cluster.eks_cluster.open_id_connect_issuer_url, "https://", "") | ||
} | ||
|
||
# Optional Custom policy for KMS support and EBS CSI Driver Role | ||
|
||
resource "awscc_iam_managed_policy" "efs_csi_kms_policy" { | ||
managed_policy_name = "AmazonEKS_EFS_CSI_KMS_Policy" | ||
policy_document = jsonencode({ | ||
Version = "2012-10-17" | ||
Statement = [ | ||
{ | ||
Effect = "Allow" | ||
Action = [ | ||
"kms:CreateGrant", | ||
"kms:ListGrants", | ||
"kms:RevokeGrant" | ||
] | ||
Resource = awscc_kms_key.example.arn | ||
Condition = { | ||
Bool = { | ||
"kms:GrantIsForAWSResource" = "true" | ||
} | ||
} | ||
}, | ||
{ | ||
Effect = "Allow" | ||
Action = [ | ||
"kms:Encrypt", | ||
"kms:Decrypt", | ||
"kms:ReEncrypt*", | ||
"kms:GenerateDataKey*", | ||
"kms:DescribeKey" | ||
] | ||
Resource = awscc_kms_key.example.arn | ||
} | ||
] | ||
}) | ||
} | ||
|
||
# Create IAM role for EBS CSI Driver | ||
resource "awscc_iam_role" "efs_csi_role" { | ||
role_name = "AmazonEKS_EFS_CSI_Driver_Role" | ||
assume_role_policy_document = jsonencode({ | ||
Statement = [{ | ||
Action = "sts:AssumeRoleWithWebIdentity" | ||
Effect = "Allow" | ||
Principal = { | ||
Federated = awscc_iam_oidc_provider.eks.arn | ||
# Example: "arn:aws:iam::111122223333:oidc-provider/oidc.eks.region-code.amazonaws.com/id/EXAMPLED539D4633E53DE1B71EXAMPLE" | ||
} | ||
Condition = { | ||
StringEquals = { | ||
"${local.oidc_provider}:sub" = "system:serviceaccount:kube-system:efs-csi-controller-sa" | ||
"${local.oidc_provider}:aud" = "sts.amazonaws.com" | ||
} | ||
} | ||
}] | ||
Version = "2012-10-17" | ||
}) | ||
|
||
managed_policy_arns = [ | ||
awscc_iam_managed_policy.efs_csi_kms_policy.arn, | ||
"arn:aws:iam::aws:policy/service-role/AmazonEFSCSIDriverPolicy" | ||
] | ||
} | ||
|
||
# Once the IAM role is ready, create EFS CSI addon | ||
|
||
resource "awscc_eks_addon" "efs_csi" { | ||
cluster_name = awscc_eks_cluster.cluster_name | ||
addon_name = "aws-efs-csi-driver" | ||
addon_version = "v2.1.4-eksbuild.1" #Change version to required | ||
service_account_role_arn = awscc_iam_role.efs_csi_role.arn | ||
resolve_conflicts = "OVERWRITE" | ||
tags = [{ | ||
key = "Modified By" | ||
value = "AWSCC" | ||
}] | ||
} |
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.
Thank you for creating this example. Could you please run
terraform fmt
on this file.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.
Sorry for being so late. Job Done !