|
| 1 | +data "aws_partition" "current" {} |
| 2 | + |
| 3 | +data "aws_caller_identity" "current" {} |
| 4 | + |
| 5 | +data "aws_region" "current" {} |
| 6 | + |
| 7 | +data "aws_eks_cluster" "eks_cluster" { |
| 8 | + name = var.eks_cluster_id |
| 9 | +} |
| 10 | + |
| 11 | +data "aws_iam_policy" "irsa" { |
| 12 | + arn = "arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy" |
| 13 | +} |
| 14 | + |
| 15 | +locals { |
| 16 | + name = "adot-exporter-for-eks-on-ec2" |
| 17 | + service_account = try(var.helm_config.service_account, "${local.name}-sa") |
| 18 | + |
| 19 | + set_values = [ |
| 20 | + { |
| 21 | + name = "serviceAccount.name" |
| 22 | + value = local.service_account |
| 23 | + }, |
| 24 | + { |
| 25 | + name = "serviceAccount.create" |
| 26 | + value = false |
| 27 | + } |
| 28 | + ] |
| 29 | + # https://github.com/aws-observability/aws-otel-helm-charts/tree/main/charts/adot-exporter-for-eks-on-ec2 |
| 30 | + default_helm_config = { |
| 31 | + name = local.name |
| 32 | + chart = "adot-exporter-for-eks-on-ec2" |
| 33 | + repository = "https://aws-observability.github.io/aws-otel-helm-charts" |
| 34 | + version = var.adot_otel_helm_chart_verison |
| 35 | + namespace = "amazon-metrics" |
| 36 | + values = local.default_helm_values |
| 37 | + description = "ADOT Helm Chart Deployment Configuration for Container Insights" |
| 38 | + } |
| 39 | + |
| 40 | + helm_config = merge( |
| 41 | + local.default_helm_config, |
| 42 | + var.helm_config |
| 43 | + ) |
| 44 | + |
| 45 | + default_helm_values = [templatefile("${path.module}/values.yaml", { |
| 46 | + aws_region = local.addon_context.aws_region_name |
| 47 | + cluster_name = local.addon_context.eks_cluster_id |
| 48 | + service_receivers = format("[\"%s\"]", var.service_receivers) |
| 49 | + service_exporters = format("[\"%s\"]", var.service_exporters) |
| 50 | + service_account = local.service_account |
| 51 | + })] |
| 52 | + |
| 53 | + irsa_config = { |
| 54 | + kubernetes_namespace = local.helm_config["namespace"] |
| 55 | + kubernetes_service_account = local.service_account |
| 56 | + create_kubernetes_namespace = try(local.helm_config["create_namespace"], true) |
| 57 | + create_kubernetes_service_account = true |
| 58 | + create_service_account_secret_token = try(local.helm_config["create_service_account_secret_token"], false) |
| 59 | + irsa_iam_policies = concat([data.aws_iam_policy.irsa.arn], var.irsa_policies) |
| 60 | + } |
| 61 | + |
| 62 | + eks_oidc_issuer_url = replace(data.aws_eks_cluster.eks_cluster.identity[0].oidc[0].issuer, "https://", "") |
| 63 | + |
| 64 | + addon_context = { |
| 65 | + aws_caller_identity_account_id = data.aws_caller_identity.current.account_id |
| 66 | + aws_caller_identity_arn = data.aws_caller_identity.current.arn |
| 67 | + aws_eks_cluster_endpoint = data.aws_eks_cluster.eks_cluster.endpoint |
| 68 | + aws_partition_id = data.aws_partition.current.partition |
| 69 | + aws_region_name = data.aws_region.current.name |
| 70 | + eks_cluster_id = var.eks_cluster_id |
| 71 | + eks_oidc_issuer_url = replace(data.aws_eks_cluster.eks_cluster.identity[0].oidc[0].issuer, "https://", "") |
| 72 | + eks_oidc_provider_arn = "arn:${data.aws_partition.current.partition}:iam::${data.aws_caller_identity.current.account_id}:oidc-provider/${local.eks_oidc_issuer_url}" |
| 73 | + tags = var.tags |
| 74 | + irsa_iam_role_path = var.irsa_iam_role_path |
| 75 | + irsa_iam_permissions_boundary = var.irsa_iam_permissions_boundary |
| 76 | + } |
| 77 | + |
| 78 | +} |
0 commit comments