Giter VIP home page Giter VIP logo

terraform-aws-resource-naming's Introduction

terraform-aws-resource-naming

Terraform Version Release Last Commit Issues Pull Requests License Open Source Love

Table of Content

Prerequisites

  • Terraform
    • This module was created using Terraform 0.11.6 on 2018/04/10
    • The latest stable version of Terraform which this module tested working is Terraform 0.12.0 on 2019/05/28

Quick Start

For most of the resources, AWS does not allow us to create multiple resources with the same name. That is the reason why we need to make them unique.

This module will help you to generate a unique resource name by adding random_id value as a suffix to the name prefix you specified. Not just adding, but this module will also calculate how many random characters should be added to the prefix so it will not exceed maximum character allowed from AWS. Check the list below for AWS services supported by this module.

Supported resources:

  • autoscaling_group
  • autoscaling_policy
  • autoscaling_schedule
  • cloudwatch_event_rule
  • cloudwatch_log_group
  • cloudwatch_metric_alarm
  • codebuild_project
  • codecommit_repository
  • codepipeline
  • db_instance
  • db_parameter_group
  • dynamodb_table
  • ecr_repository
  • ecs_cluster
  • ecs_service
  • ecs_task_definition
  • elasticache_cluster
  • elasticache_parameter_group
  • elasticsearch_domain
  • iam_instance_profile
  • iam_role
  • instance
  • key_pair
  • kinesis_firehose_delivery_stream
  • lambda_function
  • launch_configuration
  • lb
  • lb_target_group
  • s3_bucket
  • secretsmanager_secret
  • security_group
  • sns_topic
  • sqs_queue
  • waf_byte_match_set
  • waf_geo_match_set
  • waf_ipset
  • waf_rate_based_rule
  • waf_regex_match_set
  • waf_regex_pattern_set
  • waf_rule
  • waf_rule_group
  • waf_size_constraint_set
  • waf_sql_injection_match_set
  • waf_web_acl
  • waf_xss_match_set
  • wafregional_byte_match_set
  • wafregional_geo_match_set
  • wafregional_ipset
  • wafregional_rate_based_rule
  • wafregional_regex_match_set
  • wafregional_regex_pattern_set
  • wafregional_rule
  • wafregional_rule_group
  • wafregional_size_constraint_set
  • wafregional_sql_injection_match_set
  • wafregional_web_acl
  • wafregional_xss_match_set

Notes:

  • If character length of your name prefix already exceeds maximum character allowed from AWS, this module will not do anything about it. Executing terraform apply will most likely to fail.

Usage

You need to know what resource you want to provision (resource_type) and what the name prefix (name_prefix) is. Then provide the information to this module's variables:

provider "random" {
  version = ">= 1.2.0, < 3.0.0"
}

module "aws-resource-naming_lambda_role" {
  source        = "github.com/traveloka/terraform-aws-resource-naming"
  version       = "v0.17.1"
  name_prefix   = "LambdaRole_DailyScheduler"
  resource_type = "iam_role"
}

resource "aws_iam_role" "lambda_role" {
  name        = "${module.aws-resource-naming_lambda_role.name}"
  path        = "/lambda-role/"                                       
  description = "Lambda Role for Daily Scheduler"

  assume_role_policy   = "${data.aws_iam_policy_document.lambda_assume_role_policy.json}"
}

data "aws_iam_policy_document" "lambda_assume_role_policy" {
  statement = {
    actions = ["sts:AssumeRole"]
    effect  = "Allow"

    principals = {
      type        = "Service"
      identifiers = ["lambda.amazonaws.com"]
    }
  }
}

To understand better on how to implement this module, you can go into examples folder and try them.

Examples

Module Definition

Providers

Name Version
random >= 1.2.0, < 3.0.0

Inputs

Name Description Type Default Required
keepers Arbitrary map of values that, when changed, will trigger a new id to be generated. map {} no
name_prefix Arbitrary string to prefix the output value with. Adding trailing dash/hypen will not give any effect, it will be added by the module automatically. string n/a yes
resource_type AWS Resource type that the name will be generated by this module. string n/a yes

Outputs

Name Description
name The generated name with random_id presented in padded hexadecimal digits as suffix.

Dependencies

This module does not have any dependencies to other modules.

Contributing

Can not see the resource you want to provision on the list above? Open CONTRIBUTING to learn how to add it by yourself!

License

Apache 2 Licensed. See LICENSE for full details.

terraform-aws-resource-naming's People

Contributors

abihf avatar andysaputra avatar bernard-sh avatar fajrinazis avatar isen-ng avatar jainpiyush19 avatar jinhong- avatar radengoots avatar rafikurnia avatar sshvetsov avatar sumodirjo avatar tuananh-nguyen avatar

Watchers

 avatar

Forkers

jainpiyush19

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.