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

Consider Removing Access Logs Module #107

Closed
wants to merge 2 commits into from

Conversation

ekristen
Copy link

@ekristen ekristen commented Nov 29, 2021

what

  • Removed access_logs module

why

  • Disabling the access_logs module by supplying existing bucket_id results in errors from terraform and count for the alb_service_account not knowing how many resources to create because terraform hasn't been created yet.
  • This makes the module more simple while allowing someone to easily spin up the same module code at the same level as the alb module and pass in the bucket information

important

  • this could be considered a breaking change and necessary to rev the major, however it wouldn't be difficult to migrate the module state up one level as an upgrade path

example

module "access_logs" {
  source                             = "cloudposse/lb-s3-bucket/aws"
  version                            = "0.14.1"
  enabled                            = module.this.enabled && var.access_logs_enabled && var.access_logs_s3_bucket_id == null
  attributes                         = compact(concat(module.this.attributes, ["alb", "access", "logs"]))
  lifecycle_rule_enabled             = var.lifecycle_rule_enabled
  enable_glacier_transition          = var.enable_glacier_transition
  expiration_days                    = var.expiration_days
  glacier_transition_days            = var.glacier_transition_days
  noncurrent_version_expiration_days = var.noncurrent_version_expiration_days
  noncurrent_version_transition_days = var.noncurrent_version_transition_days
  standard_transition_days           = var.standard_transition_days
  force_destroy                      = var.alb_access_logs_s3_bucket_force_destroy
  context                            = module.this.context
}

module "alb" {
    source = "cloudposse/alb/aws"
    # Cloud Posse recommends pinning every module to a specific version
    # version     = "x.x.x"
    namespace                               = var.namespace
    stage                                   = var.stage
    name                                    = var.name
    attributes                              = var.attributes
    delimiter                               = var.delimiter
    vpc_id                                  = module.vpc.vpc_id
    security_group_ids                      = [module.vpc.vpc_default_security_group_id]
    subnet_ids                              = module.subnets.public_subnet_ids
    internal                                = var.internal
    http_enabled                            = var.http_enabled
    http_redirect                           = var.http_redirect
    access_logs_enabled                     = var.access_logs_enabled
    access_logs_s3_bucket_id                = module.access_logs.bucket_id
    cross_zone_load_balancing_enabled       = var.cross_zone_load_balancing_enabled
    http2_enabled                           = var.http2_enabled
    idle_timeout                            = var.idle_timeout
    ip_address_type                         = var.ip_address_type
    deletion_protection_enabled             = var.deletion_protection_enabled
    deregistration_delay                    = var.deregistration_delay
    health_check_path                       = var.health_check_path
    health_check_timeout                    = var.health_check_timeout
    health_check_healthy_threshold          = var.health_check_healthy_threshold
    health_check_unhealthy_threshold        = var.health_check_unhealthy_threshold
    health_check_interval                   = var.health_check_interval
    health_check_matcher                    = var.health_check_matcher
    target_group_port                       = var.target_group_port
    target_group_target_type                = var.target_group_target_type
    stickiness                              = var.stickiness
    tags                                    = var.tags
  }

@ekristen ekristen requested review from a team as code owners November 29, 2021 20:17
@ekristen ekristen requested review from Gowiem and dylanbannon and removed request for a team November 29, 2021 20:17
Copy link

@bridgecrew bridgecrew bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bridgecrew has found infrastructure configuration errors in this PR ⬇️

@@ -83,7 +67,7 @@ resource "aws_lb" "default" {
drop_invalid_header_fields = var.drop_invalid_header_fields

access_logs {
bucket = try(element(compact([var.access_logs_s3_bucket_id, module.access_logs.bucket_id]), 0), "")
bucket = var.access_logs_s3_bucket_id
Copy link

@bridgecrew bridgecrew bot Nov 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOW   Ensure ALB redirects HTTP requests into HTTPS ones
    Resource: aws_lb.default | ID: BC_AWS_NETWORKING_49

How to Fix

resource "aws_lb" "lb_good" {
}


resource "aws_lb_listener" "listener_good" {
  load_balancer_arn = aws_lb.lb_good.arn
  port              = "80"
  protocol          = "HTTP"

  default_action {
    type = "redirect"

    redirect {
      port        = "443"
      protocol    = "HTTPS"
      status_code = "HTTP_301"
    }

  }
}

Description

TBA

Dependent Resources



Path Resource Connecting Attribute
/main.tf aws_lb_listener.http_forward load_balancer_arn
/main.tf aws_lb_listener.http_redirect load_balancer_arn
/main.tf aws_lb_listener.https load_balancer_arn

@@ -83,7 +67,7 @@ resource "aws_lb" "default" {
drop_invalid_header_fields = var.drop_invalid_header_fields

access_logs {
bucket = try(element(compact([var.access_logs_s3_bucket_id, module.access_logs.bucket_id]), 0), "")
bucket = var.access_logs_s3_bucket_id
Copy link

@bridgecrew bridgecrew bot Nov 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MEDIUM   Ensure public facing ALB are protected by AWS Web Application Firewall v2 (AWS WAFv2)
    Resource: aws_lb.default | ID: BC_AWS_NETWORKING_58

Description

TBD Dependent Resources

Path Resource Connecting Attribute
/main.tf aws_lb_listener.http_forward load_balancer_arn
/main.tf aws_lb_listener.http_redirect load_balancer_arn
/main.tf aws_lb_listener.https load_balancer_arn

@mergify
Copy link

mergify bot commented Jun 27, 2022

This pull request is now in conflict. Could you fix it @ekristen? 🙏

@Gowiem
Copy link
Member

Gowiem commented Nov 15, 2023

@ekristen while I agree, this probably should have been built with composition in mind instead of inheritence... I think we're probably stuck with this for now and it's not worth making the breaking change. I think the thing to fix would be this:

Disabling the access_logs module by supplying existing bucket_id results in errors from terraform and count for the alb_service_account not knowing how many resources to create because terraform hasn't been created yet.

Are you still interested in this update? Want to discuss what fixing that looks like and take a crack at that? If not, no worries, but I think we will close this PR since it has sat open and untouched for a while without much interest sadly.

@Gowiem Gowiem closed this Nov 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants