Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/go_modules/test/src/go_modules-f6…
Browse files Browse the repository at this point in the history
…632a53ef
  • Loading branch information
goruha authored Nov 13, 2024
2 parents 54af18a + ef2c73b commit f25fa3c
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 124 deletions.
54 changes: 0 additions & 54 deletions .github/auto-release.yml

This file was deleted.

Binary file modified .github/banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions .github/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ repository:
description: Terraform module to provision a standard ALB for HTTP/HTTP traffic
homepage: https://cloudposse.com/accelerate
topics: terraform, terraform-module, aws, alb, load-balancer, ecs, ec2, layer7, ingress, tls, acm, http, https, elb, hcl2




7 changes: 4 additions & 3 deletions .github/workflows/chatops.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ permissions:
pull-requests: write
id-token: write
contents: write
statuses: write

jobs:
terraform-module:
test:
uses: cloudposse/.github/.github/workflows/shared-terraform-chatops.yml@main
secrets:
github_access_token: ${{ secrets.REPO_ACCESS_TOKEN }}
if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, '/terratest') }}
secrets: inherit
58 changes: 30 additions & 28 deletions README.md

Large diffs are not rendered by default.

58 changes: 30 additions & 28 deletions docs/terraform.md

Large diffs are not rendered by default.

33 changes: 29 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
locals {
# cidrnetmask returns an error for IPv6 addresses
# cidrhost works with both IPv4 and IPv6, and returns an error if the argument is not a valid IPv4/IPv6 CIDR prefix
http_ingress_cidr_blocks_v4 = [for cidr in var.http_ingress_cidr_blocks : cidr if can(cidrnetmask(cidr))]
http_ingress_cidr_blocks_v6 = var.ip_address_type == "dualstack" ? [for cidr in var.http_ingress_cidr_blocks : cidr if !can(cidrnetmask(cidr)) && can(cidrhost(cidr, 0))] : []
https_ingress_cidr_blocks_v4 = [for cidr in var.https_ingress_cidr_blocks : cidr if can(cidrnetmask(cidr))]
https_ingress_cidr_blocks_v6 = var.ip_address_type == "dualstack" ? [for cidr in var.https_ingress_cidr_blocks : cidr if !can(cidrnetmask(cidr)) && can(cidrhost(cidr, 0))] : []
}


resource "aws_security_group" "default" {
count = module.this.enabled && var.security_group_enabled ? 1 : 0
description = "Controls access to the ALB (HTTP/HTTPS)"
Expand All @@ -22,7 +32,8 @@ resource "aws_security_group_rule" "http_ingress" {
from_port = var.http_port
to_port = var.http_port
protocol = "tcp"
cidr_blocks = var.http_ingress_cidr_blocks
cidr_blocks = local.http_ingress_cidr_blocks_v4
ipv6_cidr_blocks = local.http_ingress_cidr_blocks_v6
prefix_list_ids = var.http_ingress_prefix_list_ids
security_group_id = one(aws_security_group.default[*].id)
}
Expand All @@ -33,7 +44,8 @@ resource "aws_security_group_rule" "https_ingress" {
from_port = var.https_port
to_port = var.https_port
protocol = "tcp"
cidr_blocks = var.https_ingress_cidr_blocks
cidr_blocks = local.https_ingress_cidr_blocks_v4
ipv6_cidr_blocks = local.https_ingress_cidr_blocks_v6
prefix_list_ids = var.https_ingress_prefix_list_ids
security_group_id = one(aws_security_group.default[*].id)
}
Expand Down Expand Up @@ -90,6 +102,7 @@ resource "aws_lb" "default" {
drop_invalid_header_fields = var.drop_invalid_header_fields
preserve_host_header = var.preserve_host_header
xff_header_processing_mode = var.xff_header_processing_mode
client_keep_alive = var.client_keep_alive

access_logs {
bucket = try(element(compact([var.access_logs_s3_bucket_id, module.access_logs.bucket_id]), 0), "")
Expand Down Expand Up @@ -203,8 +216,8 @@ resource "aws_lb_listener" "https" {
tags = merge(module.this.tags, var.listener_additional_tags)

default_action {
target_group_arn = var.listener_https_fixed_response != null ? null : one(aws_lb_target_group.default[*].arn)
type = var.listener_https_fixed_response != null ? "fixed-response" : "forward"
target_group_arn = var.listener_https_fixed_response != null || var.listener_https_redirect != null ? null : one(aws_lb_target_group.default[*].arn)
type = var.listener_https_fixed_response != null ? "fixed-response" : var.listener_https_redirect != null ? "redirect" : "forward"

dynamic "fixed_response" {
for_each = var.listener_https_fixed_response != null ? [var.listener_https_fixed_response] : []
Expand All @@ -214,6 +227,18 @@ resource "aws_lb_listener" "https" {
status_code = fixed_response.value["status_code"]
}
}

dynamic "redirect" {
for_each = var.listener_https_redirect != null ? [var.listener_https_redirect] : []
content {
host = redirect.value["host"]
path = redirect.value["path"]
port = redirect.value["port"]
protocol = redirect.value["protocol"]
query = redirect.value["query"]
status_code = redirect.value["status_code"]
}
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions test/src/examples_complete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ func TestExamplesComplete(t *testing.T) {

// Run `terraform output` to get the value of an output variable
defaultTargetGroupArn := terraform.Output(t, terraformOptions, "default_target_group_arn")
// Verify we're getting back the outputs we expect something like "arn:aws:elasticloadbalancing:us-east-2:126450723953:targetgroup/eg-test-alb-11514-default/89e9fe401fc63cf7
assert.Contains(t, defaultTargetGroupArn, "arn:aws:elasticloadbalancing:us-east-2:126450723953:targetgroup/eg-test-alb-"+attributes[0]+"-default")
// Verify we're getting back the outputs we expect something like "arn:aws:elasticloadbalancing:us-east-2:799847381734:targetgroup/eg-test-alb-11514-default/89e9fe401fc63cf7
assert.Contains(t, defaultTargetGroupArn, "arn:aws:elasticloadbalancing:us-east-2:799847381734:targetgroup/eg-test-alb-"+attributes[0]+"-default")

// Run `terraform output` to get the value of an output variable
httpListenerArn := terraform.Output(t, terraformOptions, "http_listener_arn")
// Verify we're getting back the outputs we expect
assert.Contains(t, httpListenerArn, "arn:aws:elasticloadbalancing:us-east-2:126450723953:listener/app/eg-test-alb-"+attributes[0])
assert.Contains(t, httpListenerArn, "arn:aws:elasticloadbalancing:us-east-2:799847381734:listener/app/eg-test-alb-"+attributes[0])
}
39 changes: 37 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,13 @@ variable "http_redirect" {

variable "http_ingress_cidr_blocks" {
type = list(string)
default = ["0.0.0.0/0"]
default = ["0.0.0.0/0", "::/0"]
description = "List of CIDR blocks to allow in HTTP security group"

validation {
condition = alltrue([for cidr in var.http_ingress_cidr_blocks : can(cidrhost(cidr, 0))])
error_message = "Each entry in http_ingress_cidr_blocks must be a valid CIDR block."
}
}

variable "http_ingress_prefix_list_ids" {
Expand Down Expand Up @@ -70,8 +75,13 @@ variable "https_enabled" {

variable "https_ingress_cidr_blocks" {
type = list(string)
default = ["0.0.0.0/0"]
default = ["0.0.0.0/0", "::/0"]
description = "List of CIDR blocks to allow in HTTPS security group"

validation {
condition = alltrue([for cidr in var.https_ingress_cidr_blocks : can(cidrhost(cidr, 0))])
error_message = "Each entry in https_ingress_cidr_blocks must be a valid CIDR block."
}
}

variable "https_ingress_prefix_list_ids" {
Expand Down Expand Up @@ -132,6 +142,11 @@ variable "ip_address_type" {
type = string
default = "ipv4"
description = "The type of IP addresses used by the subnets for your load balancer. The possible values are `ipv4` and `dualstack`."

validation {
condition = contains(["ipv4", "dualstack"], var.ip_address_type)
error_message = "ip_address_type must be either `ipv4` or `dualstack`."
}
}

variable "deletion_protection_enabled" {
Expand Down Expand Up @@ -274,6 +289,20 @@ variable "listener_https_fixed_response" {
default = null
}

variable "listener_https_redirect" {
description = "Have the HTTPS listener return a redirect response for the default action."
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lb_listener#status_code-2
type = object({
host = optional(string)
path = optional(string)
port = optional(string)
protocol = optional(string)
query = optional(string)
status_code = string
})
default = null
}

variable "lifecycle_configuration_rules" {
type = list(object({
enabled = bool
Expand Down Expand Up @@ -360,3 +389,9 @@ variable "xff_header_processing_mode" {
default = "append"
description = "Determines how the load balancer modifies the X-Forwarded-For header in the HTTP request before sending the request to the target. The possible values are append, preserve, and remove. Only valid for Load Balancers of type application. The default is append"
}

variable "client_keep_alive" {
type = number
default = 3600
description = "Client keep alive value in seconds. The valid range is 60-604800 seconds. The default is 3600 seconds."
}
4 changes: 2 additions & 2 deletions versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 4.0"
version = ">= 5.46"
}
}
}
}

0 comments on commit f25fa3c

Please sign in to comment.