Skip to content
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

feat: Support custom log configuration #342

Conversation

oponomarov-tu
Copy link

Description

  1. Add an input variable to allow us to override the logConfiguration stanza for the ECS task for Atlantis.
  2. Use count instead of for_each for iam policy attachments.

Motivation and Context

  1. Custom log configuration is needed when, for example, running a sidecar container to ship logs to Elasticsearch / Humio / etc.
  2. Fix chicken-and-egg problem when running terraform plan for policies yet to be created (this will recreate policy attachments with indexes instead of keys).

Breaking Changes

resource "aws_iam_role_policy_attachment" "ecs_task_execution" will be recreated due to the nature of using index-based (count) vs. map-name-based (for_each) approach.

How Has This Been Tested?

  • I have updated at least one of the examples/* to demonstrate and validate my change(s)
  • I have tested and validated these changes using one or more of the provided examples/* projects
  • I have executed pre-commit run -a on my pull request

The changes have been tested with the latest version of module running in production. The recreated policy attachments had no influence on the running Atlantis instance.

Snippets:

data "aws_iam_policy_document" "ecs_cloudwatch" {
  version = "2012-10-17"
  statement {
    actions = [
      "logs:CreateLogGroup",
    ]
    resources = ["*"]
  }
}

resource "aws_iam_policy" "ecs_cloudwatch" {
  name        = "atlantis-ecs-cloudwatch-policy"
  path        = "/"
  description = "Allows Atlantis to create CloudWatch Log Groups"
  policy      = data.aws_iam_policy_document.ecs_cloudwatch.json
}

module "container_definition_fluentbit" {
  source  = "cloudposse/ecs-container-definition/aws"
  version = "v0.58.1"

  container_name  = "log-router"
  container_image = "amazon/aws-for-fluent-bit:stable"
  essential       = true

  firelens_configuration = {
    type = "fluentbit"

    options = {
      enable-ecs-log-metadata = "true",
      config-file-type        = "file",
      config-file-value       = "/fluent-bit/configs/parse-json.conf",
    }
  }

  log_configuration = {
    logDriver = "awslogs",
    options = {
      awslogs-create-group  = "true",
      awslogs-group         = "atlantis-humio",
      awslogs-region        = var.region,
      awslogs-stream-prefix = "humio-ingester",
    }
  }
}
module "atlantis" {
  source  = "terraform-aws-modules/atlantis/aws"
  version = "3.26.0"
  ...
  # IAM policies
  policies_arn = [
    "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy",
    ...
    aws_iam_policy.ecs_cloudwatch.arn,
  ]
  ... 
  # Extra container definitions
  extra_container_definitions = [module.container_definition_fluentbit.json_map_object]

  custom_log_configuration = {
    logDriver = "awsfirelens",
    options = {
      "Name" : "es",
      "Host" : "cloud.humio.com",
      "Port" : "9200",
      "HTTP_User" : "defaultRepoName",
      "Logstash_Format" : "On",
      "Type" : "flb_type",
      "Time_Key" : "@timestamp",
      "Replace_Dots" : "On",
      "Logstash_Prefix" : "atlantis",
      "Buffer_Size" : "5MB",
      "tls" : "On",
    }
    secretOptions = [
      {
        name      = "HTTP_Passwd",
        valueFrom = data.aws_ssm_parameter.humio_ingest_token.name,
      }
    ]
  }

@oponomarov-tu oponomarov-tu changed the title feat: support custom log configuration feat: Support custom log configuration Apr 20, 2023
@github-actions
Copy link

This PR has been automatically marked as stale because it has been open 30 days
with no activity. Remove stale label or comment or this PR will be closed in 10 days

@github-actions github-actions bot added the stale label May 21, 2023
@mightyguava
Copy link

@antonbabenko @bryantbiggs would you be able to take a look at this?

@github-actions github-actions bot removed the stale label May 23, 2023
@github-actions
Copy link

This PR has been automatically marked as stale because it has been open 30 days
with no activity. Remove stale label or comment or this PR will be closed in 10 days

@github-actions github-actions bot added the stale label Jun 22, 2023
@oponomarov-tu
Copy link
Author

Kind reminder.

@bryantbiggs
Copy link
Member

This will be handled with #297

@github-actions github-actions bot removed the stale label Jun 23, 2023
@github-actions
Copy link

This PR has been automatically marked as stale because it has been open 30 days
with no activity. Remove stale label or comment or this PR will be closed in 10 days

@github-actions github-actions bot added the stale label Jul 24, 2023
@mschirbel
Copy link

+1 for this change. when can we expect #297 to be implemented?

@github-actions github-actions bot removed the stale label Aug 2, 2023
@github-actions
Copy link

github-actions bot commented Sep 2, 2023

This PR has been automatically marked as stale because it has been open 30 days
with no activity. Remove stale label or comment or this PR will be closed in 10 days

@github-actions github-actions bot added the stale label Sep 2, 2023
@oponomarov-tu
Copy link
Author

Remove stale label.

@github-actions github-actions bot removed the stale label Sep 12, 2023
@github-actions
Copy link

This PR has been automatically marked as stale because it has been open 30 days
with no activity. Remove stale label or comment or this PR will be closed in 10 days

@github-actions github-actions bot added the stale label Oct 13, 2023
@oponomarov-tu
Copy link
Author

Remove stale label.

@antonbabenko
Copy link
Member

This issue has been resolved in version 4.0.0 🎉

Copy link

github-actions bot commented Dec 5, 2023

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants