Created
August 3, 2022 13:04
-
-
Save wzooff/319c20a2e7ab0b45d22b8a8b2af4cdd7 to your computer and use it in GitHub Desktop.
External DNS with IRSA
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
| module "iam_assumable_role_external_dns" { | |
| source = "terraform-aws-modules/iam/aws//modules/iam-assumable-role-with-oidc" | |
| version = "~> v3.16.0" | |
| create_role = true | |
| role_name = "eks-${data.aws_eks_cluster.this.name}-external-dns" | |
| role_description = "IRSA for external-dns in eks ${data.aws_eks_cluster.this.name} cluster" | |
| //noinspection HILUnresolvedReference | |
| provider_url = replace(data.aws_eks_cluster.this.identity.0.oidc.0.issuer, "https://", "") | |
| oidc_fully_qualified_subjects = ["system:serviceaccount:kube-external-dns:admin-public-external-dns"] # sa will be created diring chart installation | |
| //tags = local.common_tags | |
| } | |
| resource "aws_iam_role_policy" "external_dns_access" { # inline | |
| name = "external-dns-access" | |
| role = module.iam_assumable_role_external_dns.this_iam_role_name | |
| # Terraform's "jsonencode" function converts a | |
| # Terraform expression result to valid JSON syntax. | |
| policy = jsonencode({ | |
| "Version": "2012-10-17", | |
| "Statement": [ | |
| { | |
| "Effect": "Allow", | |
| "Action": [ | |
| "route53:ChangeResourceRecordSets" | |
| ], | |
| "Resource": [ | |
| "arn:aws:route53:::hostedzone/*" | |
| ] | |
| }, | |
| { | |
| "Effect": "Allow", | |
| "Action": [ | |
| "route53:ListHostedZones", | |
| "route53:ListResourceRecordSets" | |
| ], | |
| "Resource": [ | |
| "*" | |
| ] | |
| } | |
| ] | |
| }) | |
| } | |
| # https://github.com/kubernetes-sigs/external-dns/tree/master/charts/external-dns | |
| resource "helm_release" "external_dns" { | |
| name = "admin-public" | |
| chart = "external-dns" | |
| repository = "https://kubernetes-sigs.github.io/external-dns/" | |
| namespace = "kube-external-dns" | |
| create_namespace = true | |
| set { | |
| name = "serviceAccount.annotations.eks\\.amazonaws\\.com/role-arn" | |
| value = module.iam_assumable_role_external_dns.this_iam_role_arn | |
| } | |
| set { | |
| name = "domainFilters[0]" | |
| value = var.admin_domain | |
| } | |
| set { | |
| name = "txtOwnerId" | |
| value = "eks-${data.aws_eks_cluster.this.id}-external-dns" | |
| } | |
| set { | |
| name = "tolerations[0].effect" | |
| value = "NoSchedule" | |
| } | |
| set { | |
| name = "tolerations[0].key" | |
| value = "nodegroup-role" | |
| } | |
| set { | |
| name = "tolerations[0].value" | |
| value = "control-plane" | |
| } | |
| set { | |
| name = "nodeSelector.role" | |
| value = "control-plane" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment