Skip to content

tomarv2/terraform-aws-target-group

Repository files navigation

Terraform module for AWS Target Group

Versions

  • Module tested for Terraform 1.0.1.
  • AWS provider version 4.35
  • main branch: Provider versions not pinned to keep up with Terraform releases.
  • tags releases: Tags are pinned with versions (use ).

Usage

Option 1:

terrafrom init
terraform plan -var='teamid=tryme' -var='prjid=project1'
terraform apply -var='teamid=tryme' -var='prjid=project1'
terraform destroy -var='teamid=tryme' -var='prjid=project1'

Note: With this option please take care of remote state storage

Option 2:

Recommended method (store remote state in S3 using prjid and teamid to create directory structure):

  • Create python 3.8+ virtual environment
python3 -m venv <venv name>
  • Install package:
pip install tfremote --upgrade
  • Set below environment variables:
export TF_AWS_BUCKET=<remote state bucket name>
export TF_AWS_BUCKET_REGION=us-west-2
export TF_AWS_PROFILE=<profile from ~/.ws/credentials>

or

  • Set below environment variables:
export TF_AWS_BUCKET=<remote state bucket name>
export TF_AWS_BUCKET_REGION=us-west-2
export AWS_ACCESS_KEY_ID=<aws_access_key_id>
export AWS_SECRET_ACCESS_KEY=<aws_secret_access_key>
  • Updated examples directory with required values.

  • Run and verify the output before deploying:

tf -c=aws plan -var='teamid=foo' -var='prjid=bar'
  • Run below to deploy:
tf -c=aws apply -var='teamid=foo' -var='prjid=bar'
  • Run below to destroy:
tf -c=aws destroy -var='teamid=foo' -var='prjid=bar'

Note: Read more on tfremote

Target Group
module "target_group" {
  source = "../"

  account_id           = "12345679012"
  lb_protocol          = "HTTP"
  lb_port              = [80]
  healthcheck_path     = "/"
  healthy_threshold    = "2"
  healthcheck_matcher  = "200"
  healthcheck_timeout  = "15"
  unhealthy_threshold  = "3"
  healthcheck_interval = "30"
  #-----------------------------------------------
  # Note: Do not change teamid and prjid once set.
  teamid = var.teamid
  prjid  = var.prjid
}

Please refer to examples directory link for references.

Requirements

Name Version
terraform >= 1.0.1
aws ~> 4.35

Providers

Name Version
aws ~> 4.35

Modules

Name Source Version
global git::git@github.com:tomarv2/terraform-global.git//aws v0.0.1

Resources

Name Type
aws_lb_target_group.target_group resource
aws_caller_identity.current data source
aws_region.current data source

Inputs

Name Description Type Default Required
config Target groups configuration map(any) {} no
extra_tags Additional tags to associate map(string) {} no

Outputs

Name Description
arn Target group ARN
config Target group configuration
port Target group port