generated from terraform-modules/template_aws_submodules
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
153 additions
and
20 deletions.
There are no files selected for viewing
122 changes: 122 additions & 0 deletions
122
examples/full-cluster-tf-upgrade/1.25/common-services/cloudwatch-agent.tf
This file contains 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,122 @@ | ||
| # https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Container-Insights-prerequisites.html | ||
| # https://registry.terraform.io/modules/bailey84j/cloudwatch-agent/kubernetes/latest | ||
| # cannot let this create the role, as it tries to attache a policy that does not exist | ||
| # we need this policy: arn:aws-us-gov:iam::aws:policy/CloudWatchAgentServerPolicy | ||
|
|
||
| # need to hack the module for now | ||
| # main.tf | ||
| ## container { | ||
| ## name = "${var.name}-agent" | ||
| ## # image = "amazon/${var.image_name}:${var.image_version}" | ||
| ## image = "${var.image_name}:${var.image_version}" | ||
| # | ||
| # also want to do the same for the role, to allow a different managed role(s) besides | ||
| # the appsync one to be used | ||
|
|
||
| module "cloudwatch-agent" { | ||
| source = "bailey84j/cloudwatch-agent/kubernetes" | ||
| version = "1.0.1" | ||
|
|
||
| eks_cluster_name = var.cluster_name | ||
| create_namespace = false | ||
| image_name = split(":", local.image_output["cloudwatch-agent"].dest_full_path)[0] | ||
| image_version = local.image_output["cloudwatch-agent"].tag | ||
| create_iam_role = false | ||
| iam_role_arn = module.role_cloudwatch-agent.iam_role_arn | ||
|
|
||
| tags = merge( | ||
| local.base_tags, | ||
| local.common_tags, | ||
| var.application_tags, | ||
| ) | ||
| } | ||
|
|
||
| locals { | ||
| cloudwatch_agent_namespace = "kube-system" | ||
| cloudwatch_agent_name = "cloudwatch" | ||
| } | ||
|
|
||
| data "aws_iam_policy" "policy_cloudwatch-agent" { | ||
| name = "CloudWatchAgentServerPolicy" | ||
| } | ||
|
|
||
| module "role_cloudwatch-agent" { | ||
| source = "terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks" | ||
|
|
||
| role_description = "EKS IAM Role for ${var.cluster_name} for service account ${local.cloudwatch_agent_namespace}:${local.cloudwatch_agent_name}" | ||
| role_name = format("%v%v-irsa__%v", local._prefixes["eks"], var.cluster_name, local.cloudwatch_agent_name) | ||
|
|
||
| role_policy_arns = { | ||
| policy = data.aws_iam_policy.policy_cloudwatch-agent.arn | ||
| } | ||
|
|
||
| oidc_providers = { | ||
| main = { | ||
| provider_arn = local.oidc_provider_arn | ||
| namespace_service_accounts = [format("%v:%v", local.cloudwatch_agent_namespace, local.cloudwatch_agent_name)] | ||
| } | ||
| } | ||
|
|
||
| tags = merge( | ||
| local.base_tags, | ||
| local.common_tags, | ||
| var.application_tags, | ||
| { | ||
| "eks:namespace" = local.cloudwatch_agent_namespace | ||
| "eks:user" = local.cloudwatch_agent_name | ||
| } | ||
| ) | ||
| } | ||
|
|
||
| ## module "role_cloudwatch-agent" { | ||
| ## source = "git@github.e.it.census.gov:terraform-modules/aws-iam-role.git?ref=tf-upgrade" | ||
| ## | ||
| ## role_description = "EKS IAM Role for ${var.cluster_name} for service account ${local.cloudwatch_agent_namespace}:${local.cloudwatch_agent_name}" | ||
| ## role_name = format("%v%v-irsa__%v", local._prefixes["eks"], var.cluster_name, local.cloudwatch_agent_name) | ||
| ## enable_ldap_creation = false | ||
| ## assume_policy_document = data.aws_iam_policy_document.assume_role_cloudwatch-agent.json | ||
| ## attached_policies = [aws_iam_policy.policy_cloudwatch-agent.arn] | ||
| ## | ||
| ## tags = merge( | ||
| ## local.base_tags, | ||
| ## local.common_tags, | ||
| ## var.tags, | ||
| ## var.application_tags, | ||
| ## { | ||
| ## "eks:namespace" = var.namespace | ||
| ## "eks:user" = var.name | ||
| ## } | ||
| ## ) | ||
| ## } | ||
| ## | ||
| ## data "aws_iam_policy_document" "assume_role_cloudwatch-agent" { | ||
| ## statement { | ||
| ## actions = ["sts:AssumeRoleWithWebIdentity"] | ||
| ## effect = "Allow" | ||
| ## | ||
| ## condition { | ||
| ## test = "StringEquals" | ||
| ## variable = "${local.oidc_provider_url}:sub" | ||
| ## values = ["system:serviceaccount:${local.cloudwatch_agent_namespace}:${local.cloudwatch_agent_name}"] | ||
| ## } | ||
| ## | ||
| ## principals { | ||
| ## identifiers = [local.oidc_provider_arn] | ||
| ## type = "Federated" | ||
| ## } | ||
| ## } | ||
| ## } | ||
| ## | ||
|
|
||
| ## "cloudwatch-agent" = { | ||
| ## name = "cloudwatch-agent" | ||
| ## image = "docker.io/amazon/cloudwatch-agent" | ||
| ## dest_path = null | ||
| ## source_registry = "docker.io" | ||
| ## source_image = "amazon/cloudwatch-agent" | ||
| ## source_tag = null | ||
| ## # tag = "latest" | ||
| ## tag = "1.300026.2b172" | ||
| ## enabled = true | ||
| ## } | ||
| ## } |
This file contains 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
This file contains 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