Skip to content

Instantly share code, notes, and snippets.

@ngaffa
Last active March 10, 2023 20:18
Show Gist options
  • Save ngaffa/c35c21116d0b960f483cdaac9f4d6f92 to your computer and use it in GitHub Desktop.
Save ngaffa/c35c21116d0b960f483cdaac9f4d6f92 to your computer and use it in GitHub Desktop.
Fargate Profile Example
# Create a Fargate Profile
resource "aws_eks_fargate_profile" "fp_local_default" {
cluster_name = data.terraform_remote_state.stack.outputs.eks_cluster_name
fargate_profile_name = "fargate"
pod_execution_role_arn = aws_iam_role.fargate_pod_execution_role.arn
subnet_ids = local.subnet_ids_list
selector {
namespace = "fargate-*"
}
}
# Create a Role with principal service: eks-fargate-pods.amazonaws.com
resource "aws_iam_role" "fargate_pod_execution_role" {
name = "role-${data.terraform_remote_state.stack.outputs.eks_cluster_name}-eks-fargate-pod-execution-role"
force_detach_policies = true
assume_role_policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Condition": {
"ArnLike": {
"aws:SourceArn": "arn:aws:eks:${data.aws_region.current.name}:${var.account_id}:fargateprofile/${var.cluster_name}/*"
}
},
"Principal": {
"Service": "eks-fargate-pods.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
POLICY
}
# Create a policy attachment with this role and this policy arn:aws:iam::aws:policy/AmazonEKSFargatePodExecutionRolePolicy
resource "aws_iam_role_policy_attachment" "AmazonEKSFargatePodExecutionRolePolicy" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSFargatePodExecutionRolePolicy"
role = aws_iam_role.fargate_pod_execution_role.name
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment