Skip to content

Terraform Module to define a consistent naming convention

License

Notifications You must be signed in to change notification settings

getzoop/tf-module-label

 
 

Repository files navigation

Terraform Module | Label

A versão 2.x.x do módulo suporta o Terraform 1.0.x, caso precise utilizar um Terraform mais antigo a versão 1.x.x do módulo suporta o Terrraform 0.12.34.

Terraform module designed to generate consistent label names and tags for resources, based on Zoop's AWS tagging model, available here.

Usage

It's recommended to use one tf-module-label for each group of resources logically related:

module "asg_label" {
  source  = "[email protected]:getzoop/tf-module-label.git?ref=v1"

  application        = "transaction-api"
  product            = "authorizer"
  namespace          = "asg"
  environment        = var.environment
  business_owner     = "plataformas-transacionais"
  organization_owner = "digital-payments"

  tags = {
    repo          = "https://github.com/getzoop/zoop-payments-api"
    shutdown      = var.environment == "production" ? false : true
    shutdown_hour = "21:00"
    wakeup_hour   = "08:30"
    disered       = var.asg_desired
    min           = var.asg_min_size
  }
}

❗ Shutdown tags must be configured, as describte at this guideline.

Now reference the label module when creating resources:

module "asg" {
  source = "[email protected]:getzoop/tf-module-asg-mixed-instances.git?ref=v0"

  name                 = "${module.asg_label.id}-${var.commit_hash}"
  image_id             = data.aws_ami.ami.id
  iam_instance_profile = aws_iam_instance_profile.app.id

  vpc_zone_identifier = data.terraform_remote_state.vpc.outputs.private_subnets
  vpc_security_group_ids = [
    module.sg_app.this_security_group_id,
    data.terraform_remote_state.vpc.outputs.sg_ssh,
    data.terraform_remote_state.vpc.outputs.sg_services,
  ]

  min_size         = var.asg_min_size
  max_size         = var.asg_max_size
  desired_capacity = local.asg_desired

  wait_for_elb_capacity     = local.asg_desired
  wait_for_capacity_timeout = var.wait_for_capacity_timeout

  on_demand_base_capacity                  = var.on_demand_base_capacity
  on_demand_percentage_above_base_capacity = var.on_demand_percentage_above_base_capacity


  instance_type           = var.instance_type
  instance_type_overrides = var.instance_type_overrides

  ebs_volume_size = var.ebs_volume_size

  target_group_arns = [aws_lb_target_group.tg.arn]
  load_balancers    = [aws_elb.internal.name]

  health_check_type         = "ELB"
  health_check_grace_period = 120

  enabled_metrics = var.enabled_metrics

  tags = module.asg_label.tags
}

Cat Jumps 😸

It's possible to instance values used by module, e.g.:

application:

module.asg_label.application

product:

module.asg_label.product

namespace:

module.asg_label.namespace

namespace:

module.asg_label.namespace

product:

module.asg_label.product

domain_name:

module.asg_label.domain_name

Requirements

Name Version
terraform ~> 1.0.10

Providers

Name Version
local ~> 2.1.0

Modules

No modules.

Resources

No resources.

Inputs

Name Description Type Default Required
application Application name, e.g. 'mycool-api' or 'jenkins'.
Sugetion: Use same name of github's project.
(Required)
string n/a yes
attributes Additional attributes, e.g. '1', 'blue', 'green' list(string) [] no
backup_status Inform if the resource will need a backup.
Defined values: “true” or “false”.
When “true”, communicate the area responsible for the backup to insert it.
bool false no
business_owner Payment area of the resource.
Check and follow definitions at organization-owner
(Required)
string n/a yes
delimiter n/a string "-" no
environment Environment, e.g. 'production', 'staging', 'homolog'.
(Required)
string n/a yes
monitoring_status Inform whether the resource will need to be monitored.
Defined values: “true” or “false”.
When “true”, communicate the area responsible for monitoring to insert it.
bool false no
object_name AWS object name, e.g. 'ec2' or 'iam'.
(Required)
string n/a yes
organization_owner Big areas that englobes multiple business-owners.
Check and follow definitions at organization-owner
(Required)
string n/a yes
product Product that application is part of, e.g. 'webhook', 'pix'.
(Required)
string n/a yes
tags Additional tags, e.g. 'map('shutdown','true')' map(string) {} no

Outputs

Name Description
application Normalized application name.
attributes Normalized attributes.
business-owner Normalized business-owner name.
domain_name Domain name to be used on Route 53 DNS records.
environment Normalized environment.
id Disambiguated ID.
object_name Normalized object name.
organization-owner Normalized organization-owner name.
product Normalized product.
tags Normalized Tag map.

Examples

environment namespace application attributes product generated id
production rds transaction-api 01 authorizer zp-production-rds-transaction-api-01

About

Terraform Module to define a consistent naming convention

Resources

License

Stars

Watchers

Forks

Languages

  • HCL 100.0%