├── test ├── .gitignore ├── src │ ├── .gitignore │ ├── go.mod │ ├── Makefile │ └── examples_complete_test.go ├── Makefile.alpine └── Makefile ├── .github ├── ISSUE_TEMPLATE │ ├── question.md │ ├── config.yml │ ├── bug_report.md │ └── feature_request.md ├── renovate.json ├── PULL_REQUEST_TEMPLATE.md ├── workflows │ ├── auto-release.yml │ ├── chatops.yml │ ├── validate-codeowners.yml │ ├── auto-context.yml │ ├── auto-readme.yml │ └── auto-format.yml ├── auto-release.yml ├── CODEOWNERS └── mergify.yml ├── versions.tf ├── .gitignore ├── docs ├── targets.md └── terraform.md ├── Makefile ├── examples └── complete │ ├── fixtures.us-east-2.tfvars │ ├── fixtures-mixed-instance-policy.us-east-2.tfvars │ ├── outputs.tf │ ├── main.tf │ ├── variables.tf │ └── context.tf ├── outputs.tf ├── autoscaling.tf ├── README.yaml ├── main.tf ├── context.tf ├── LICENSE ├── variables.tf └── README.md /test/.gitignore: -------------------------------------------------------------------------------- 1 | .test-harness 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/src/.gitignore: -------------------------------------------------------------------------------- 1 | .gopath 2 | vendor/ 3 | -------------------------------------------------------------------------------- /test/Makefile.alpine: -------------------------------------------------------------------------------- 1 | ifneq (,$(wildcard /sbin/apk)) 2 | ## Install all dependencies for alpine 3 | deps:: init 4 | @apk add --update terraform-docs@cloudposse json2hcl@cloudposse 5 | endif 6 | -------------------------------------------------------------------------------- /test/src/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/cloudposse/terraform-aws-ec2-autoscale-group 2 | 3 | go 1.14 4 | 5 | require ( 6 | github.com/gruntwork-io/terratest v0.31.1 7 | github.com/stretchr/testify v1.5.1 8 | ) 9 | -------------------------------------------------------------------------------- /versions.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = ">= 0.13" 3 | 4 | required_providers { 5 | aws = { 6 | source = "hashicorp/aws" 7 | version = ">= 2.0" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Local .terraform directories 2 | **/.terraform/* 3 | 4 | # .tfstate files 5 | *.tfstate 6 | *.tfstate.* 7 | 8 | **/.idea 9 | **/*.iml 10 | 11 | **/.build-harness 12 | **/build-harness 13 | -------------------------------------------------------------------------------- /.github/renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "config:base", 4 | ":preserveSemverRanges" 5 | ], 6 | "labels": ["auto-update"], 7 | "enabledManagers": ["terraform"], 8 | "terraform": { 9 | "ignorePaths": ["**/context.tf", "examples/**"] 10 | } 11 | } 12 | 13 | -------------------------------------------------------------------------------- /docs/targets.md: -------------------------------------------------------------------------------- 1 | 2 | ## Makefile Targets 3 | ```text 4 | Available targets: 5 | 6 | help Help screen 7 | help/all Display help for all targets 8 | help/short This help short screen 9 | lint Lint terraform code 10 | 11 | ``` 12 | 13 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | SHELL := /bin/bash 2 | 3 | # List of targets the `readme` target should call before generating the readme 4 | export README_DEPS ?= docs/targets.md docs/terraform.md 5 | 6 | -include $(shell curl -sSL -o .build-harness "https://git.io/build-harness"; echo .build-harness) 7 | 8 | ## Lint terraform code 9 | lint: 10 | $(SELF) terraform/install terraform/get-modules terraform/get-plugins terraform/lint terraform/validate 11 | -------------------------------------------------------------------------------- /examples/complete/fixtures.us-east-2.tfvars: -------------------------------------------------------------------------------- 1 | region = "us-east-2" 2 | 3 | availability_zones = ["us-east-2a", "us-east-2b"] 4 | 5 | namespace = "eg" 6 | 7 | stage = "test" 8 | 9 | name = "ec2-autoscale-group" 10 | 11 | image_id = "ami-00c03f7f7f2ec15c3" 12 | 13 | instance_type = "t2.small" 14 | 15 | health_check_type = "EC2" 16 | 17 | wait_for_capacity_timeout = "10m" 18 | 19 | max_size = 3 20 | 21 | min_size = 2 22 | 23 | cpu_utilization_high_threshold_percent = 80 24 | 25 | cpu_utilization_low_threshold_percent = 20 26 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | 3 | contact_links: 4 | 5 | - name: Community Slack Team 6 | url: https://cloudposse.com/slack/ 7 | about: |- 8 | Please ask and answer questions here. 9 | 10 | - name: Office Hours 11 | url: https://cloudposse.com/office-hours/ 12 | about: |- 13 | Join us every Wednesday for FREE Office Hours (lunch & learn). 14 | 15 | - name: DevOps Accelerator Program 16 | url: https://cloudposse.com/accelerate/ 17 | about: |- 18 | Own your infrastructure in record time. We build it. You drive it. 19 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## what 2 | * Describe high-level what changed as a result of these commits (i.e. in plain-english, what do these changes mean?) 3 | * Use bullet points to be concise and to the point. 4 | 5 | ## why 6 | * Provide the justifications for the changes (e.g. business case). 7 | * Describe why these changes were made (e.g. why do these commits fix the problem?) 8 | * Use bullet points to be concise and to the point. 9 | 10 | ## references 11 | * Link to any supporting github issues or helpful documentation to add some context (e.g. stackoverflow). 12 | * Use `closes #123`, if this PR closes a GitHub issue `#123` 13 | 14 | -------------------------------------------------------------------------------- /examples/complete/fixtures-mixed-instance-policy.us-east-2.tfvars: -------------------------------------------------------------------------------- 1 | region = "us-east-2" 2 | 3 | availability_zones = ["us-east-2a", "us-east-2b"] 4 | 5 | namespace = "eg" 6 | 7 | stage = "test" 8 | 9 | name = "ec2-autoscale-group" 10 | 11 | image_id = "ami-00c03f7f7f2ec15c3" 12 | 13 | instance_type = "t2.small" 14 | 15 | health_check_type = "EC2" 16 | 17 | wait_for_capacity_timeout = "10m" 18 | 19 | max_size = 3 20 | 21 | min_size = 2 22 | 23 | cpu_utilization_high_threshold_percent = 80 24 | 25 | cpu_utilization_low_threshold_percent = 20 26 | 27 | mixed_instances_policy = { 28 | instances_distribution = null 29 | override = [{ 30 | instance_type = "t3.small" 31 | weighted_capacity = null 32 | }, { 33 | instance_type = "t3a.small" 34 | weighted_capacity = null 35 | }] 36 | } -------------------------------------------------------------------------------- /.github/workflows/auto-release.yml: -------------------------------------------------------------------------------- 1 | name: auto-release 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | - master 8 | - production 9 | 10 | jobs: 11 | publish: 12 | runs-on: ubuntu-latest 13 | steps: 14 | # Get PR from merged commit to master 15 | - uses: actions-ecosystem/action-get-merged-pull-request@v1 16 | id: get-merged-pull-request 17 | with: 18 | github_token: ${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }} 19 | # Drafts your next Release notes as Pull Requests are merged into "main" 20 | - uses: release-drafter/release-drafter@v5 21 | with: 22 | publish: ${{ !contains(steps.get-merged-pull-request.outputs.labels, 'no-release') }} 23 | prerelease: false 24 | config-name: auto-release.yml 25 | env: 26 | GITHUB_TOKEN: ${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }} 27 | -------------------------------------------------------------------------------- /test/src/Makefile: -------------------------------------------------------------------------------- 1 | export TF_CLI_ARGS_init ?= -get-plugins=true 2 | export TERRAFORM_VERSION ?= $(shell curl -s https://checkpoint-api.hashicorp.com/v1/check/terraform | jq -r -M '.current_version' | cut -d. -f1-2) 3 | 4 | .DEFAULT_GOAL : all 5 | 6 | .PHONY: all 7 | ## Default target 8 | all: test 9 | 10 | .PHONY : init 11 | ## Initialize tests 12 | init: 13 | @exit 0 14 | 15 | .PHONY : test 16 | ## Run tests 17 | test: init 18 | go mod download 19 | go test -v -timeout 60m -run TestExamplesComplete 20 | 21 | ## Run tests in docker container 22 | docker/test: 23 | docker run --name terratest --rm -it -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_SESSION_TOKEN -e GITHUB_TOKEN \ 24 | -e PATH="/usr/local/terraform/$(TERRAFORM_VERSION)/bin:/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" \ 25 | -v $(CURDIR)/../../:/module/ cloudposse/test-harness:latest -C /module/test/src test 26 | 27 | .PHONY : clean 28 | ## Clean up files 29 | clean: 30 | rm -rf ../../examples/complete/*.tfstate* 31 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: 'bug' 6 | assignees: '' 7 | 8 | --- 9 | 10 | Found a bug? Maybe our [Slack Community](https://slack.cloudposse.com) can help. 11 | 12 | [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com) 13 | 14 | ## Describe the Bug 15 | A clear and concise description of what the bug is. 16 | 17 | ## Expected Behavior 18 | A clear and concise description of what you expected to happen. 19 | 20 | ## Steps to Reproduce 21 | Steps to reproduce the behavior: 22 | 1. Go to '...' 23 | 2. Run '....' 24 | 3. Enter '....' 25 | 4. See error 26 | 27 | ## Screenshots 28 | If applicable, add screenshots or logs to help explain your problem. 29 | 30 | ## Environment (please complete the following information): 31 | 32 | Anything that will help us triage the bug will help. Here are some ideas: 33 | - OS: [e.g. Linux, OSX, WSL, etc] 34 | - Version [e.g. 10.15] 35 | 36 | ## Additional Context 37 | Add any other context about the problem here. -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature Request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: 'feature request' 6 | assignees: '' 7 | 8 | --- 9 | 10 | Have a question? Please checkout our [Slack Community](https://slack.cloudposse.com) or visit our [Slack Archive](https://archive.sweetops.com/). 11 | 12 | [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com) 13 | 14 | ## Describe the Feature 15 | 16 | A clear and concise description of what the bug is. 17 | 18 | ## Expected Behavior 19 | 20 | A clear and concise description of what you expected to happen. 21 | 22 | ## Use Case 23 | 24 | Is your feature request related to a problem/challenge you are trying to solve? Please provide some additional context of why this feature or capability will be valuable. 25 | 26 | ## Describe Ideal Solution 27 | 28 | A clear and concise description of what you want to happen. If you don't know, that's okay. 29 | 30 | ## Alternatives Considered 31 | 32 | Explain what alternative solutions or features you've considered. 33 | 34 | ## Additional Context 35 | 36 | Add any other context or screenshots about the feature request here. 37 | -------------------------------------------------------------------------------- /.github/workflows/chatops.yml: -------------------------------------------------------------------------------- 1 | name: chatops 2 | on: 3 | issue_comment: 4 | types: [created] 5 | 6 | jobs: 7 | default: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | - name: "Handle common commands" 12 | uses: cloudposse/actions/github/slash-command-dispatch@0.30.0 13 | with: 14 | token: ${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }} 15 | reaction-token: ${{ secrets.GITHUB_TOKEN }} 16 | repository: cloudposse/actions 17 | commands: rebuild-readme, terraform-fmt 18 | permission: triage 19 | issue-type: pull-request 20 | 21 | test: 22 | runs-on: ubuntu-latest 23 | steps: 24 | - name: "Checkout commit" 25 | uses: actions/checkout@v2 26 | - name: "Run tests" 27 | uses: cloudposse/actions/github/slash-command-dispatch@0.30.0 28 | with: 29 | token: ${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }} 30 | reaction-token: ${{ secrets.GITHUB_TOKEN }} 31 | repository: cloudposse/actions 32 | commands: test 33 | permission: triage 34 | issue-type: pull-request 35 | reactions: false 36 | 37 | 38 | -------------------------------------------------------------------------------- /.github/auto-release.yml: -------------------------------------------------------------------------------- 1 | name-template: 'v$RESOLVED_VERSION' 2 | tag-template: '$RESOLVED_VERSION' 3 | version-template: '$MAJOR.$MINOR.$PATCH' 4 | version-resolver: 5 | major: 6 | labels: 7 | - 'major' 8 | minor: 9 | labels: 10 | - 'minor' 11 | - 'enhancement' 12 | patch: 13 | labels: 14 | - 'auto-update' 15 | - 'patch' 16 | - 'fix' 17 | - 'bugfix' 18 | - 'bug' 19 | - 'hotfix' 20 | - 'no-release' 21 | default: 'minor' 22 | 23 | categories: 24 | - title: '🚀 Enhancements' 25 | labels: 26 | - 'enhancement' 27 | - 'patch' 28 | - title: '🐛 Bug Fixes' 29 | labels: 30 | - 'fix' 31 | - 'bugfix' 32 | - 'bug' 33 | - 'hotfix' 34 | - title: '🤖 Automatic Updates' 35 | labels: 36 | - 'auto-update' 37 | 38 | change-template: | 39 |
40 | $TITLE @$AUTHOR (#$NUMBER) 41 | 42 | $BODY 43 |
44 | 45 | template: | 46 | $CHANGES 47 | 48 | replacers: 49 | # Remove irrelevant information from Renovate bot 50 | - search: '/(?<=---\s)\s*^#.*(Renovate configuration|Configuration)(?:.|\n)*?This PR has been generated .*/gm' 51 | replace: '' 52 | # Remove Renovate bot banner image 53 | - search: '/\[!\[[^\]]*Renovate\][^\]]*\](\([^)]*\))?\s*\n+/gm' 54 | replace: '' 55 | -------------------------------------------------------------------------------- /.github/workflows/validate-codeowners.yml: -------------------------------------------------------------------------------- 1 | name: Validate Codeowners 2 | on: 3 | workflow_dispatch: 4 | 5 | pull_request: 6 | 7 | jobs: 8 | validate-codeowners: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: "Checkout source code at current commit" 12 | uses: actions/checkout@v2 13 | - uses: mszostok/codeowners-validator@v0.7.1 14 | if: github.event.pull_request.head.repo.full_name == github.repository 15 | name: "Full check of CODEOWNERS" 16 | with: 17 | # For now, remove "files" check to allow CODEOWNERS to specify non-existent 18 | # files so we can use the same CODEOWNERS file for Terraform and non-Terraform repos 19 | # checks: "files,syntax,owners,duppatterns" 20 | checks: "syntax,owners,duppatterns" 21 | owner_checker_allow_unowned_patterns: "false" 22 | # GitHub access token is required only if the `owners` check is enabled 23 | github_access_token: "${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }}" 24 | - uses: mszostok/codeowners-validator@v0.7.1 25 | if: github.event.pull_request.head.repo.full_name != github.repository 26 | name: "Syntax check of CODEOWNERS" 27 | with: 28 | checks: "syntax,duppatterns" 29 | owner_checker_allow_unowned_patterns: "false" 30 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Use this file to define individuals or teams that are responsible for code in a repository. 2 | # Read more: 3 | # 4 | # Order is important: the last matching pattern has the highest precedence 5 | 6 | # These owners will be the default owners for everything 7 | * @cloudposse/engineering @cloudposse/contributors 8 | 9 | # Cloud Posse must review any changes to Makefiles 10 | **/Makefile @cloudposse/engineering 11 | **/Makefile.* @cloudposse/engineering 12 | 13 | # Cloud Posse must review any changes to GitHub actions 14 | .github/* @cloudposse/engineering 15 | 16 | # Cloud Posse must review any changes to standard context definition, 17 | # but some changes can be rubber-stamped. 18 | **/*.tf @cloudposse/engineering @cloudposse/contributors @cloudposse/approvers 19 | README.yaml @cloudposse/engineering @cloudposse/contributors @cloudposse/approvers 20 | README.md @cloudposse/engineering @cloudposse/contributors @cloudposse/approvers 21 | docs/*.md @cloudposse/engineering @cloudposse/contributors @cloudposse/approvers 22 | 23 | # Cloud Posse Admins must review all changes to CODEOWNERS or the mergify configuration 24 | .github/mergify.yml @cloudposse/admins 25 | .github/CODEOWNERS @cloudposse/admins 26 | -------------------------------------------------------------------------------- /test/Makefile: -------------------------------------------------------------------------------- 1 | TEST_HARNESS ?= https://github.com/cloudposse/test-harness.git 2 | TEST_HARNESS_BRANCH ?= master 3 | TEST_HARNESS_PATH = $(realpath .test-harness) 4 | BATS_ARGS ?= --tap 5 | BATS_LOG ?= test.log 6 | 7 | # Define a macro to run the tests 8 | define RUN_TESTS 9 | @echo "Running tests in $(1)" 10 | @cd $(1) && bats $(BATS_ARGS) $(addsuffix .bats,$(addprefix $(TEST_HARNESS_PATH)/test/terraform/,$(TESTS))) 11 | endef 12 | 13 | default: all 14 | 15 | -include Makefile.* 16 | 17 | ## Provision the test-harnesss 18 | .test-harness: 19 | [ -d $@ ] || git clone --depth=1 -b $(TEST_HARNESS_BRANCH) $(TEST_HARNESS) $@ 20 | 21 | ## Initialize the tests 22 | init: .test-harness 23 | 24 | ## Install all dependencies (OS specific) 25 | deps:: 26 | @exit 0 27 | 28 | ## Clean up the test harness 29 | clean: 30 | [ "$(TEST_HARNESS_PATH)" == "/" ] || rm -rf $(TEST_HARNESS_PATH) 31 | 32 | ## Run all tests 33 | all: module examples/complete 34 | 35 | ## Run basic sanity checks against the module itself 36 | module: export TESTS ?= installed lint get-modules module-pinning get-plugins provider-pinning validate terraform-docs input-descriptions output-descriptions 37 | module: deps 38 | $(call RUN_TESTS, ../) 39 | 40 | ## Run tests against example 41 | examples/complete: export TESTS ?= installed lint get-modules get-plugins validate 42 | examples/complete: deps 43 | $(call RUN_TESTS, ../$@) 44 | -------------------------------------------------------------------------------- /.github/mergify.yml: -------------------------------------------------------------------------------- 1 | # https://docs.mergify.io/conditions.html 2 | # https://docs.mergify.io/actions.html 3 | pull_request_rules: 4 | - name: "approve automated PRs that have passed checks" 5 | conditions: 6 | - "author~=^(cloudpossebot|renovate\\[bot\\])$" 7 | - "base=master" 8 | - "-closed" 9 | - "head~=^(auto-update|renovate)/.*" 10 | - "check-success=test/bats" 11 | - "check-success=test/readme" 12 | - "check-success=test/terratest" 13 | - "check-success=validate-codeowners" 14 | actions: 15 | review: 16 | type: "APPROVE" 17 | bot_account: "cloudposse-mergebot" 18 | message: "We've automatically approved this PR because the checks from the automated Pull Request have passed." 19 | 20 | - name: "merge automated PRs when approved and tests pass" 21 | conditions: 22 | - "author~=^(cloudpossebot|renovate\\[bot\\])$" 23 | - "base=master" 24 | - "-closed" 25 | - "head~=^(auto-update|renovate)/.*" 26 | - "check-success=test/bats" 27 | - "check-success=test/readme" 28 | - "check-success=test/terratest" 29 | - "check-success=validate-codeowners" 30 | - "#approved-reviews-by>=1" 31 | - "#changes-requested-reviews-by=0" 32 | - "#commented-reviews-by=0" 33 | actions: 34 | merge: 35 | method: "squash" 36 | 37 | - name: "delete the head branch after merge" 38 | conditions: 39 | - "merged" 40 | actions: 41 | delete_head_branch: {} 42 | 43 | - name: "ask to resolve conflict" 44 | conditions: 45 | - "conflict" 46 | - "-closed" 47 | actions: 48 | comment: 49 | message: "This pull request is now in conflict. Could you fix it @{{author}}? 🙏" 50 | 51 | - name: "remove outdated reviews" 52 | conditions: 53 | - "base=master" 54 | actions: 55 | dismiss_reviews: 56 | changes_requested: true 57 | approved: true 58 | message: "This Pull Request has been updated, so we're dismissing all reviews." 59 | 60 | - name: "close Pull Requests without files changed" 61 | conditions: 62 | - "#files=0" 63 | actions: 64 | close: 65 | message: "This pull request has been automatically closed by Mergify because there are no longer any changes." 66 | -------------------------------------------------------------------------------- /.github/workflows/auto-context.yml: -------------------------------------------------------------------------------- 1 | name: "auto-context" 2 | on: 3 | schedule: 4 | # Update context.tf nightly 5 | - cron: '0 3 * * *' 6 | 7 | jobs: 8 | update: 9 | if: github.event_name == 'schedule' 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@v2 13 | 14 | - name: Update context.tf 15 | shell: bash 16 | id: update 17 | env: 18 | GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" 19 | run: | 20 | if [[ -f context.tf ]]; then 21 | echo "Discovered existing context.tf! Fetching most recent version to see if there is an update." 22 | curl -o context.tf -fsSL https://raw.githubusercontent.com/cloudposse/terraform-null-label/master/exports/context.tf 23 | if git diff --no-patch --exit-code context.tf; then 24 | echo "No changes detected! Exiting the job..." 25 | else 26 | echo "context.tf file has changed. Update examples and rebuild README.md." 27 | make init 28 | make github/init/context.tf 29 | make readme/build 30 | echo "::set-output name=create_pull_request::true" 31 | fi 32 | else 33 | echo "This module has not yet been updated to support the context.tf pattern! Please update in order to support automatic updates." 34 | fi 35 | 36 | - name: Create Pull Request 37 | if: steps.update.outputs.create_pull_request == 'true' 38 | uses: cloudposse/actions/github/create-pull-request@0.30.0 39 | with: 40 | token: ${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }} 41 | committer: 'cloudpossebot <11232728+cloudpossebot@users.noreply.github.com>' 42 | author: 'cloudpossebot <11232728+cloudpossebot@users.noreply.github.com>' 43 | commit-message: Update context.tf from origin source 44 | title: Update context.tf 45 | body: |- 46 | ## what 47 | This is an auto-generated PR that updates the `context.tf` file to the latest version from `cloudposse/terraform-null-label` 48 | 49 | ## why 50 | To support all the features of the `context` interface. 51 | 52 | branch: auto-update/context.tf 53 | base: master 54 | delete-branch: true 55 | labels: | 56 | auto-update 57 | context 58 | -------------------------------------------------------------------------------- /test/src/examples_complete_test.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/gruntwork-io/terratest/modules/terraform" 7 | "github.com/stretchr/testify/assert" 8 | ) 9 | 10 | // Test the Terraform module in examples/complete using Terratest. 11 | func TestExamplesComplete(t *testing.T) { 12 | t.Parallel() 13 | 14 | terraformOptions := &terraform.Options{ 15 | // The path to where our Terraform code is located 16 | TerraformDir: "../../examples/complete", 17 | Upgrade: true, 18 | // Variables to pass to our Terraform code using -var-file options 19 | VarFiles: []string{"fixtures.us-east-2.tfvars"}, 20 | } 21 | 22 | // At the end of the test, run `terraform destroy` to clean up any resources that were created 23 | defer terraform.Destroy(t, terraformOptions) 24 | 25 | // This will run `terraform init` and `terraform apply` and fail the test if there are any errors 26 | terraform.InitAndApply(t, terraformOptions) 27 | 28 | // Run `terraform output` to get the value of an output variable 29 | vpcCidr := terraform.Output(t, terraformOptions, "vpc_cidr") 30 | // Verify we're getting back the outputs we expect 31 | assert.Equal(t, "172.16.0.0/16", vpcCidr) 32 | 33 | // Run `terraform output` to get the value of an output variable 34 | privateSubnetCidrs := terraform.OutputList(t, terraformOptions, "private_subnet_cidrs") 35 | // Verify we're getting back the outputs we expect 36 | assert.Equal(t, []string{"172.16.0.0/19", "172.16.32.0/19"}, privateSubnetCidrs) 37 | 38 | // Run `terraform output` to get the value of an output variable 39 | publicSubnetCidrs := terraform.OutputList(t, terraformOptions, "public_subnet_cidrs") 40 | // Verify we're getting back the outputs we expect 41 | assert.Equal(t, []string{"172.16.96.0/19", "172.16.128.0/19"}, publicSubnetCidrs) 42 | 43 | // Run `terraform output` to get the value of an output variable 44 | autoscalingGroupName := terraform.Output(t, terraformOptions, "autoscaling_group_name") 45 | // Verify we're getting back the outputs we expect 46 | assert.Contains(t, autoscalingGroupName, "eg-test-ec2-autoscale-group") 47 | 48 | // Run `terraform output` to get the value of an output variable 49 | launchTemplateArn := terraform.Output(t, terraformOptions, "launch_template_arn") 50 | // Verify we're getting back the outputs we expect 51 | assert.Contains(t, launchTemplateArn, "arn:aws:ec2:us-east-2:126450723953:launch-template") 52 | } 53 | -------------------------------------------------------------------------------- /examples/complete/outputs.tf: -------------------------------------------------------------------------------- 1 | output "public_subnet_cidrs" { 2 | value = module.subnets.public_subnet_cidrs 3 | description = "Public subnet CIDRs" 4 | } 5 | 6 | output "private_subnet_cidrs" { 7 | value = module.subnets.private_subnet_cidrs 8 | description = "Private subnet CIDRs" 9 | } 10 | 11 | output "vpc_cidr" { 12 | value = module.vpc.vpc_cidr_block 13 | description = "VPC ID" 14 | } 15 | 16 | output "launch_template_id" { 17 | description = "The ID of the launch template" 18 | value = module.autoscale_group.launch_template_id 19 | } 20 | 21 | output "launch_template_arn" { 22 | description = "The ARN of the launch template" 23 | value = module.autoscale_group.launch_template_arn 24 | } 25 | 26 | output "autoscaling_group_id" { 27 | description = "The autoscaling group id" 28 | value = module.autoscale_group.autoscaling_group_id 29 | } 30 | 31 | output "autoscaling_group_name" { 32 | description = "The autoscaling group name" 33 | value = module.autoscale_group.autoscaling_group_name 34 | } 35 | 36 | output "autoscaling_group_arn" { 37 | description = "The ARN for this AutoScaling Group" 38 | value = module.autoscale_group.autoscaling_group_arn 39 | } 40 | 41 | output "autoscaling_group_min_size" { 42 | description = "The minimum size of the autoscale group" 43 | value = module.autoscale_group.autoscaling_group_min_size 44 | } 45 | 46 | output "autoscaling_group_max_size" { 47 | description = "The maximum size of the autoscale group" 48 | value = module.autoscale_group.autoscaling_group_max_size 49 | } 50 | 51 | output "autoscaling_group_desired_capacity" { 52 | description = "The number of Amazon EC2 instances that should be running in the group" 53 | value = module.autoscale_group.autoscaling_group_desired_capacity 54 | } 55 | 56 | output "autoscaling_group_default_cooldown" { 57 | description = "Time between a scaling activity and the succeeding scaling activity" 58 | value = module.autoscale_group.autoscaling_group_default_cooldown 59 | } 60 | 61 | output "autoscaling_group_health_check_grace_period" { 62 | description = "Time after instance comes into service before checking health" 63 | value = module.autoscale_group.autoscaling_group_health_check_grace_period 64 | } 65 | 66 | output "autoscaling_group_health_check_type" { 67 | description = "`EC2` or `ELB`. Controls how health checking is done" 68 | value = module.autoscale_group.autoscaling_group_health_check_type 69 | } 70 | -------------------------------------------------------------------------------- /outputs.tf: -------------------------------------------------------------------------------- 1 | output "launch_template_id" { 2 | description = "The ID of the launch template" 3 | value = join("", aws_launch_template.default.*.id) 4 | } 5 | 6 | output "launch_template_arn" { 7 | description = "The ARN of the launch template" 8 | value = join("", aws_launch_template.default.*.arn) 9 | } 10 | 11 | output "autoscaling_group_id" { 12 | description = "The AutoScaling Group id" 13 | value = join("", aws_autoscaling_group.default.*.id) 14 | } 15 | 16 | output "autoscaling_group_name" { 17 | description = "The AutoScaling Group name" 18 | value = join("", aws_autoscaling_group.default.*.name) 19 | } 20 | 21 | output "autoscaling_group_tags" { 22 | description = "A list of tag settings associated with the AutoScaling Group" 23 | value = module.this.enabled ? aws_autoscaling_group.default[0].tags : [] 24 | } 25 | 26 | output "autoscaling_group_arn" { 27 | description = "ARN of the AutoScaling Group" 28 | value = join("", aws_autoscaling_group.default.*.arn) 29 | } 30 | 31 | output "autoscaling_group_min_size" { 32 | description = "The minimum size of the autoscale group" 33 | value = join("", aws_autoscaling_group.default.*.min_size) 34 | } 35 | 36 | output "autoscaling_group_max_size" { 37 | description = "The maximum size of the autoscale group" 38 | value = join("", aws_autoscaling_group.default.*.max_size) 39 | } 40 | 41 | output "autoscaling_group_desired_capacity" { 42 | description = "The number of Amazon EC2 instances that should be running in the group" 43 | value = join("", aws_autoscaling_group.default.*.desired_capacity) 44 | } 45 | 46 | output "autoscaling_group_default_cooldown" { 47 | description = "Time between a scaling activity and the succeeding scaling activity" 48 | value = join("", aws_autoscaling_group.default.*.default_cooldown) 49 | } 50 | 51 | output "autoscaling_group_health_check_grace_period" { 52 | description = "Time after instance comes into service before checking health" 53 | value = join("", aws_autoscaling_group.default.*.health_check_grace_period) 54 | } 55 | 56 | output "autoscaling_group_health_check_type" { 57 | description = "`EC2` or `ELB`. Controls how health checking is done" 58 | value = join("", aws_autoscaling_group.default.*.health_check_type) 59 | } 60 | 61 | output "autoscaling_policy_scale_down_arn" { 62 | description = "ARN of the AutoScaling policy scale down" 63 | value = join("", aws_autoscaling_policy.scale_down.*.arn) 64 | } 65 | 66 | output "autoscaling_policy_scale_up_arn" { 67 | description = "ARN of the AutoScaling policy scale up" 68 | value = join("", aws_autoscaling_policy.scale_up.*.arn) 69 | } 70 | -------------------------------------------------------------------------------- /.github/workflows/auto-readme.yml: -------------------------------------------------------------------------------- 1 | name: "auto-readme" 2 | on: 3 | workflow_dispatch: 4 | 5 | schedule: 6 | # Example of job definition: 7 | # .---------------- minute (0 - 59) 8 | # | .------------- hour (0 - 23) 9 | # | | .---------- day of month (1 - 31) 10 | # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... 11 | # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat 12 | # | | | | | 13 | # * * * * * user-name command to be executed 14 | 15 | # Update README.md nightly at 4am UTC 16 | - cron: '0 4 * * *' 17 | 18 | jobs: 19 | update: 20 | if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' 21 | runs-on: ubuntu-latest 22 | steps: 23 | - uses: actions/checkout@v2 24 | 25 | - name: Find default branch name 26 | id: defaultBranch 27 | shell: bash 28 | env: 29 | GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" 30 | run: | 31 | default_branch=$(gh repo view --json defaultBranchRef --jq .defaultBranchRef.name) 32 | printf "::set-output name=defaultBranch::%s\n" "${default_branch}" 33 | printf "defaultBranchRef.name=%s\n" "${default_branch}" 34 | 35 | - name: Update readme 36 | shell: bash 37 | id: update 38 | env: 39 | GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" 40 | DEF: "${{ steps.defaultBranch.outputs.defaultBranch }}" 41 | run: | 42 | make init 43 | make readme/build 44 | # Ignore changes if they are only whitespace 45 | if ! git diff --quiet README.md && git diff --ignore-all-space --ignore-blank-lines --quiet README.md; then 46 | git restore README.md 47 | echo Ignoring whitespace-only changes in README 48 | fi 49 | 50 | - name: Create Pull Request 51 | # This action will not create or change a pull request if there are no changes to make. 52 | # If a PR of the auto-update/readme branch is open, this action will just update it, not create a new PR. 53 | uses: cloudposse/actions/github/create-pull-request@0.30.0 54 | with: 55 | token: ${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }} 56 | commit-message: Update README.md and docs 57 | title: Update README.md and docs 58 | body: |- 59 | ## what 60 | This is an auto-generated PR that updates the README.md and docs 61 | 62 | ## why 63 | To have most recent changes of README.md and doc from origin templates 64 | 65 | branch: auto-update/readme 66 | base: ${{ steps.defaultBranch.outputs.defaultBranch }} 67 | delete-branch: true 68 | labels: | 69 | auto-update 70 | no-release 71 | readme 72 | -------------------------------------------------------------------------------- /examples/complete/main.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = var.region 3 | } 4 | 5 | module "vpc" { 6 | source = "cloudposse/vpc/aws" 7 | version = "0.18.1" 8 | cidr_block = "172.16.0.0/16" 9 | 10 | context = module.this.context 11 | } 12 | 13 | module "subnets" { 14 | source = "cloudposse/dynamic-subnets/aws" 15 | version = "0.38.0" 16 | availability_zones = var.availability_zones 17 | vpc_id = module.vpc.vpc_id 18 | igw_id = module.vpc.igw_id 19 | cidr_block = module.vpc.vpc_cidr_block 20 | nat_gateway_enabled = false 21 | nat_instance_enabled = false 22 | 23 | context = module.this.context 24 | } 25 | 26 | module "autoscale_group" { 27 | source = "../../" 28 | 29 | image_id = var.image_id 30 | instance_type = var.instance_type 31 | instance_market_options = var.instance_market_options 32 | mixed_instances_policy = var.mixed_instances_policy 33 | subnet_ids = module.subnets.public_subnet_ids 34 | health_check_type = var.health_check_type 35 | min_size = var.min_size 36 | max_size = var.max_size 37 | wait_for_capacity_timeout = var.wait_for_capacity_timeout 38 | associate_public_ip_address = true 39 | user_data_base64 = base64encode(local.userdata) 40 | metadata_http_tokens_required = true 41 | 42 | tags = { 43 | Tier = "1" 44 | KubernetesCluster = "us-east-2.testing.cloudposse.co" 45 | } 46 | 47 | # Auto-scaling policies and CloudWatch metric alarms 48 | autoscaling_policies_enabled = true 49 | cpu_utilization_high_threshold_percent = var.cpu_utilization_high_threshold_percent 50 | cpu_utilization_low_threshold_percent = var.cpu_utilization_low_threshold_percent 51 | 52 | block_device_mappings = [ 53 | { 54 | device_name = "/dev/sdb" 55 | no_device = null 56 | virtual_name = null 57 | ebs = { 58 | delete_on_termination = true 59 | encrypted = true 60 | volume_size = 8 61 | volume_type = "gp2" 62 | iops = null 63 | kms_key_id = null 64 | snapshot_id = null 65 | } 66 | } 67 | ] 68 | 69 | context = module.this.context 70 | } 71 | 72 | # https://www.terraform.io/docs/configuration/expressions.html#string-literals 73 | locals { 74 | userdata = <<-USERDATA 75 | #!/bin/bash 76 | cat <<"__EOF__" > /home/ec2-user/.ssh/config 77 | Host * 78 | StrictHostKeyChecking no 79 | __EOF__ 80 | chmod 600 /home/ec2-user/.ssh/config 81 | chown ec2-user:ec2-user /home/ec2-user/.ssh/config 82 | USERDATA 83 | } 84 | -------------------------------------------------------------------------------- /examples/complete/variables.tf: -------------------------------------------------------------------------------- 1 | variable "region" { 2 | type = string 3 | description = "AWS Region" 4 | } 5 | 6 | variable "availability_zones" { 7 | type = list(string) 8 | description = "List of availability zones" 9 | } 10 | 11 | variable "image_id" { 12 | type = string 13 | description = "The EC2 image ID to launch" 14 | } 15 | 16 | variable "instance_type" { 17 | type = string 18 | description = "Instance type to launch" 19 | } 20 | 21 | variable "health_check_type" { 22 | type = string 23 | description = "Controls how health checking is done. Valid values are `EC2` or `ELB`" 24 | } 25 | 26 | variable "wait_for_capacity_timeout" { 27 | type = string 28 | description = "A maximum duration that Terraform should wait for ASG instances to be healthy before timing out. (See also Waiting for Capacity below.) Setting this to '0' causes Terraform to skip all Capacity Waiting behavior" 29 | } 30 | 31 | variable "max_size" { 32 | type = number 33 | description = "The maximum size of the autoscale group" 34 | } 35 | 36 | variable "min_size" { 37 | type = number 38 | description = "The minimum size of the autoscale group" 39 | } 40 | 41 | variable "cpu_utilization_high_threshold_percent" { 42 | type = number 43 | description = "CPU utilization high threshold" 44 | } 45 | 46 | variable "cpu_utilization_low_threshold_percent" { 47 | type = number 48 | description = "CPU utilization low threshold" 49 | } 50 | 51 | variable "instance_market_options" { 52 | description = "The market (purchasing) option for the instances" 53 | 54 | type = object({ 55 | market_type = string 56 | spot_options = object({ 57 | block_duration_minutes = number 58 | instance_interruption_behavior = string 59 | max_price = number 60 | spot_instance_type = string 61 | valid_until = string 62 | }) 63 | }) 64 | 65 | default = null 66 | } 67 | 68 | variable mixed_instances_policy { 69 | description = "policy to used mixed group of on demand/spot of differing types. Launch template is automatically generated. https://www.terraform.io/docs/providers/aws/r/autoscaling_group.html#mixed_instances_policy-1" 70 | 71 | type = object({ 72 | instances_distribution = object({ 73 | on_demand_allocation_strategy = string 74 | on_demand_base_capacity = number 75 | on_demand_percentage_above_base_capacity = number 76 | spot_allocation_strategy = string 77 | spot_instance_pools = number 78 | spot_max_price = string 79 | }) 80 | override = list(object({ 81 | instance_type = string 82 | weighted_capacity = number 83 | })) 84 | }) 85 | default = null 86 | } 87 | -------------------------------------------------------------------------------- /.github/workflows/auto-format.yml: -------------------------------------------------------------------------------- 1 | name: Auto Format 2 | on: 3 | pull_request_target: 4 | types: [opened, synchronize] 5 | 6 | jobs: 7 | auto-format: 8 | runs-on: ubuntu-latest 9 | container: cloudposse/build-harness:latest 10 | steps: 11 | # Checkout the pull request branch 12 | # "An action in a workflow run can’t trigger a new workflow run. For example, if an action pushes code using 13 | # the repository’s GITHUB_TOKEN, a new workflow will not run even when the repository contains 14 | # a workflow configured to run when push events occur." 15 | # However, using a personal access token will cause events to be triggered. 16 | # We need that to ensure a status gets posted after the auto-format commit. 17 | # We also want to trigger tests if the auto-format made no changes. 18 | - uses: actions/checkout@v2 19 | if: github.event.pull_request.state == 'open' 20 | name: Privileged Checkout 21 | with: 22 | token: ${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }} 23 | repository: ${{ github.event.pull_request.head.repo.full_name }} 24 | # Check out the PR commit, not the merge commit 25 | # Use `ref` instead of `sha` to enable pushing back to `ref` 26 | ref: ${{ github.event.pull_request.head.ref }} 27 | 28 | # Do all the formatting stuff 29 | - name: Auto Format 30 | if: github.event.pull_request.state == 'open' 31 | shell: bash 32 | env: 33 | GITHUB_TOKEN: "${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }}" 34 | run: make BUILD_HARNESS_PATH=/build-harness PACKAGES_PREFER_HOST=true -f /build-harness/templates/Makefile.build-harness pr/auto-format/host 35 | 36 | # Commit changes (if any) to the PR branch 37 | - name: Commit changes to the PR branch 38 | if: github.event.pull_request.state == 'open' 39 | shell: bash 40 | id: commit 41 | env: 42 | SENDER: ${{ github.event.sender.login }} 43 | run: | 44 | set -x 45 | output=$(git diff --name-only) 46 | 47 | if [ -n "$output" ]; then 48 | echo "Changes detected. Pushing to the PR branch" 49 | git config --global user.name 'cloudpossebot' 50 | git config --global user.email '11232728+cloudpossebot@users.noreply.github.com' 51 | git add -A 52 | git commit -m "Auto Format" 53 | # Prevent looping by not pushing changes in response to changes from cloudpossebot 54 | [[ $SENDER == "cloudpossebot" ]] || git push 55 | # Set status to fail, because the push should trigger another status check, 56 | # and we use success to indicate the checks are finished. 57 | printf "::set-output name=%s::%s\n" "changed" "true" 58 | exit 1 59 | else 60 | printf "::set-output name=%s::%s\n" "changed" "false" 61 | echo "No changes detected" 62 | fi 63 | 64 | - name: Auto Test 65 | uses: cloudposse/actions/github/repository-dispatch@0.30.0 66 | # match users by ID because logins (user names) are inconsistent, 67 | # for example in the REST API Renovate Bot is `renovate[bot]` but 68 | # in GraphQL it is just `renovate`, plus there is a non-bot 69 | # user `renovate` with ID 1832810. 70 | # Mergify bot: 37929162 71 | # Renovate bot: 29139614 72 | # Cloudpossebot: 11232728 73 | # Need to use space separators to prevent "21" from matching "112144" 74 | if: > 75 | contains(' 37929162 29139614 11232728 ', format(' {0} ', github.event.pull_request.user.id)) 76 | && steps.commit.outputs.changed == 'false' && github.event.pull_request.state == 'open' 77 | with: 78 | token: ${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }} 79 | repository: cloudposse/actions 80 | event-type: test-command 81 | client-payload: |- 82 | { "slash_command":{"args": {"unnamed": {"all": "all", "arg1": "all"}}}, 83 | "pull_request": ${{ toJSON(github.event.pull_request) }}, 84 | "github":{"payload":{"repository": ${{ toJSON(github.event.repository) }}, 85 | "comment": {"id": ""} 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /autoscaling.tf: -------------------------------------------------------------------------------- 1 | # https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/ec2-metricscollected.html 2 | locals { 3 | autoscaling_enabled = module.this.enabled && var.autoscaling_policies_enabled 4 | } 5 | 6 | resource "aws_autoscaling_policy" "scale_up" { 7 | count = local.autoscaling_enabled ? 1 : 0 8 | name = "${module.this.id}${module.this.delimiter}scale${module.this.delimiter}up" 9 | scaling_adjustment = var.scale_up_scaling_adjustment 10 | adjustment_type = var.scale_up_adjustment_type 11 | policy_type = var.scale_up_policy_type 12 | cooldown = var.scale_up_cooldown_seconds 13 | autoscaling_group_name = join("", aws_autoscaling_group.default.*.name) 14 | } 15 | 16 | resource "aws_autoscaling_policy" "scale_down" { 17 | count = local.autoscaling_enabled ? 1 : 0 18 | name = "${module.this.id}${module.this.delimiter}scale${module.this.delimiter}down" 19 | scaling_adjustment = var.scale_down_scaling_adjustment 20 | adjustment_type = var.scale_down_adjustment_type 21 | policy_type = var.scale_down_policy_type 22 | cooldown = var.scale_down_cooldown_seconds 23 | autoscaling_group_name = join("", aws_autoscaling_group.default.*.name) 24 | } 25 | 26 | locals { 27 | default_ec2_alarms = { 28 | cpu_high = { 29 | alarm_name = "${module.this.id}${module.this.delimiter}cpu${module.this.delimiter}utilization${module.this.delimiter}high" 30 | comparison_operator = "GreaterThanOrEqualToThreshold" 31 | evaluation_periods = var.cpu_utilization_high_evaluation_periods 32 | metric_name = "CPUUtilization" 33 | namespace = "AWS/EC2" 34 | period = var.cpu_utilization_high_period_seconds 35 | statistic = var.cpu_utilization_high_statistic 36 | threshold = var.cpu_utilization_high_threshold_percent 37 | dimensions_name = "AutoScalingGroupName" 38 | dimensions_target = join("", aws_autoscaling_group.default.*.name) 39 | alarm_description = "Scale up if CPU utilization is above ${var.cpu_utilization_high_threshold_percent} for ${var.cpu_utilization_high_period_seconds} * ${var.cpu_utilization_high_evaluation_periods} seconds" 40 | alarm_actions = [join("", aws_autoscaling_policy.scale_up.*.arn)] 41 | treat_missing_data = "missing" 42 | ok_actions = [] 43 | insufficient_data_actions = [] 44 | }, 45 | cpu_low = { 46 | alarm_name = "${module.this.id}${module.this.delimiter}cpu${module.this.delimiter}utilization${module.this.delimiter}low" 47 | comparison_operator = "LessThanOrEqualToThreshold" 48 | evaluation_periods = var.cpu_utilization_low_evaluation_periods 49 | metric_name = "CPUUtilization" 50 | namespace = "AWS/EC2" 51 | period = var.cpu_utilization_low_period_seconds 52 | statistic = var.cpu_utilization_low_statistic 53 | threshold = var.cpu_utilization_low_threshold_percent 54 | dimensions_name = "AutoScalingGroupName" 55 | dimensions_target = join("", aws_autoscaling_group.default.*.name) 56 | alarm_description = "Scale down if the CPU utilization is below ${var.cpu_utilization_low_threshold_percent} for ${var.cpu_utilization_low_period_seconds} * ${var.cpu_utilization_high_evaluation_periods} seconds" 57 | alarm_actions = [join("", aws_autoscaling_policy.scale_down.*.arn)] 58 | treat_missing_data = "missing" 59 | ok_actions = [] 60 | insufficient_data_actions = [] 61 | } 62 | } 63 | 64 | default_alarms = var.autoscaling_policies_enabled && var.default_alarms_enabled ? local.default_ec2_alarms : {} 65 | all_alarms = module.this.enabled ? merge(local.default_alarms, var.custom_alarms) : {} 66 | } 67 | 68 | resource "aws_cloudwatch_metric_alarm" "all_alarms" { 69 | for_each = local.all_alarms 70 | alarm_name = format("%s%s", "${module.this.id}${module.this.delimiter}", each.value.alarm_name) 71 | comparison_operator = each.value.comparison_operator 72 | evaluation_periods = each.value.evaluation_periods 73 | metric_name = each.value.metric_name 74 | namespace = each.value.namespace 75 | period = each.value.period 76 | statistic = each.value.statistic 77 | threshold = each.value.threshold 78 | treat_missing_data = each.value.treat_missing_data 79 | ok_actions = each.value.ok_actions 80 | insufficient_data_actions = each.value.insufficient_data_actions 81 | dimensions = { 82 | (each.value.dimensions_name) = (each.value.dimensions_target) 83 | } 84 | 85 | alarm_description = each.value.alarm_description 86 | alarm_actions = each.value.alarm_actions 87 | tags = var.tags 88 | } 89 | -------------------------------------------------------------------------------- /README.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # This is the canonical configuration for the `README.md` 3 | # Run `make readme` to rebuild the `README.md` 4 | # 5 | 6 | # Name of this project 7 | name: terraform-aws-ec2-autoscale-group 8 | # Logo for this project 9 | #logo: docs/logo.png 10 | 11 | # License of this project 12 | license: "APACHE2" 13 | # Canonical GitHub repo 14 | github_repo: cloudposse/terraform-aws-ec2-autoscale-group 15 | # Badges to display 16 | badges: 17 | - name: "Latest Release" 18 | image: "https://img.shields.io/github/release/cloudposse/terraform-aws-ec2-autoscale-group.svg" 19 | url: "https://github.com/cloudposse/terraform-aws-ec2-autoscale-group/releases/latest" 20 | - name: "Slack Community" 21 | image: "https://slack.cloudposse.com/badge.svg" 22 | url: "https://slack.cloudposse.com" 23 | related: 24 | - name: "terraform-aws-ec2-instance" 25 | description: "Terraform module for providing a general purpose EC2 instance" 26 | url: "https://github.com/cloudposse/terraform-aws-ec2-instance" 27 | - name: "terraform-aws-ec2-bastion-server" 28 | description: "Terraform module to define a generic bastion host with parameterized user data" 29 | url: "https://github.com/cloudposse/terraform-aws-ec2-bastion-server" 30 | - name: "terraform-aws-ec2-admin-server" 31 | description: "Terraform module for providing an EC2 instance capable of running admin tasks" 32 | url: "https://github.com/cloudposse/terraform-aws-ec2-admin-server" 33 | - name: "terraform-aws-ec2-instance-group" 34 | description: "Terraform module for provisioning multiple general purpose EC2 hosts for stateful applications" 35 | url: "https://github.com/cloudposse/terraform-aws-ec2-instance-group" 36 | - name: "terraform-aws-ec2-ami-snapshot" 37 | description: "Terraform module to easily generate AMI snapshots to create replica instances" 38 | url: "https://github.com/cloudposse/terraform-aws-ec2-ami-snapshot" 39 | # Short description of this project 40 | description: |- 41 | Terraform module to provision [Auto Scaling Group](https://www.terraform.io/docs/providers/aws/r/autoscaling_group.html) and [Launch Template](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-launch-templates.html) on AWS. 42 | 43 | The module also creates AutoScaling Policies and CloudWatch Metric Alarms to monitor CPU utilization on the EC2 instances and scale the number of instance in the AutoScaling Group up or down. 44 | If you don't want to use the provided functionality, or want to provide your own policies, disable it by setting the variable `autoscaling_policies_enabled` to `false`. 45 | 46 | At present, although you can set the created AutoScaling Policy type to any legal value, in practice [only `SimpleScaling` is supported](https://github.com/cloudposse/terraform-aws-ec2-autoscale-group/issues/55). 47 | To use a `StepScaling` or `TargetTrackingScaling` policy, create it yourself and then pass it in the `alarm_actions` field of `custom_alarms`. 48 | 49 | # How to use this project 50 | usage: |2- 51 | 52 | ```hcl 53 | locals { 54 | userdata = <<-USERDATA 55 | #!/bin/bash 56 | cat <<"__EOF__" > /home/ec2-user/.ssh/config 57 | Host * 58 | StrictHostKeyChecking no 59 | __EOF__ 60 | chmod 600 /home/ec2-user/.ssh/config 61 | chown ec2-user:ec2-user /home/ec2-user/.ssh/config 62 | USERDATA 63 | } 64 | 65 | module "autoscale_group" { 66 | source = "cloudposse/ec2-autoscale-group/aws" 67 | # Cloud Posse recommends pinning every module to a specific version 68 | # version = "x.x.x" 69 | 70 | namespace = var.namespace 71 | stage = var.stage 72 | environment = var.environment 73 | name = var.name 74 | 75 | image_id = "ami-08cab282f9979fc7a" 76 | instance_type = "t2.small" 77 | security_group_ids = ["sg-xxxxxxxx"] 78 | subnet_ids = ["subnet-xxxxxxxx", "subnet-yyyyyyyy", "subnet-zzzzzzzz"] 79 | health_check_type = "EC2" 80 | min_size = 2 81 | max_size = 3 82 | wait_for_capacity_timeout = "5m" 83 | associate_public_ip_address = true 84 | user_data_base64 = base64encode(local.userdata) 85 | 86 | # All inputs to `block_device_mappings` have to be defined 87 | block_device_mappings = [ 88 | { 89 | device_name = "/dev/sda1" 90 | no_device = "false" 91 | virtual_name = "root" 92 | ebs = { 93 | encrypted = true 94 | volume_size = 200 95 | delete_on_termination = true 96 | iops = null 97 | kms_key_id = null 98 | snapshot_id = null 99 | volume_type = "standard" 100 | } 101 | } 102 | ] 103 | 104 | tags = { 105 | Tier = "1" 106 | KubernetesCluster = "us-west-2.testing.cloudposse.co" 107 | } 108 | 109 | # Auto-scaling policies and CloudWatch metric alarms 110 | autoscaling_policies_enabled = true 111 | cpu_utilization_high_threshold_percent = "70" 112 | cpu_utilization_low_threshold_percent = "20" 113 | } 114 | ``` 115 | 116 | To enable custom_alerts the map needs to be defined like so : 117 | ```hlc 118 | alarms = { 119 | alb_scale_up = { 120 | alarm_name = "${module.default_label.id}-alb-target-response-time-for-scale-up" 121 | comparison_operator = "GreaterThanThreshold" 122 | evaluation_periods = var.alb_target_group_alarms_evaluation_periods 123 | metric_name = "TargetResponseTime" 124 | namespace = "AWS/ApplicationELB" 125 | period = var.alb_target_group_alarms_period 126 | statistic = "Average" 127 | threshold = var.alb_target_group_alarms_response_time_max_threshold 128 | dimensions_name = "LoadBalancer" 129 | dimensions_target = data.alb.arn_suffix 130 | treat_missing_data = "missing" 131 | ok_actions = var.alb_target_group_alarms_ok_actions 132 | insufficient_data_actions = var.alb_target_group_alarms_insufficient_data_actions 133 | alarm_description = "ALB Target response time is over ${var.alb_target_group_alarms_response_time_max_threshold} for more than ${var.alb_target_group_alarms_period}" 134 | alarm_actions = [module.autoscaling.scale_up_policy_arn] 135 | } 136 | } 137 | ``` 138 | All those keys are required to be there so if the alarm you are setting does not requiere one or more keys you can just set to empty but do not remove the keys otherwise you could get a weird merge error due to the maps being of different sizes. 139 | 140 | include: 141 | - "docs/targets.md" 142 | - "docs/terraform.md" 143 | # Contributors to this project 144 | contributors: 145 | - name: "Erik Osterman" 146 | github: "osterman" 147 | - name: "Andriy Knysh" 148 | github: "aknysh" 149 | - name: "Igor Rodionov" 150 | github: "goruha" 151 | - name: "RB" 152 | github: "nitrocode" 153 | -------------------------------------------------------------------------------- /main.tf: -------------------------------------------------------------------------------- 1 | resource "aws_launch_template" "default" { 2 | count = module.this.enabled ? 1 : 0 3 | 4 | name_prefix = format("%s%s", module.this.id, module.this.delimiter) 5 | 6 | dynamic "block_device_mappings" { 7 | for_each = var.block_device_mappings 8 | content { 9 | device_name = lookup(block_device_mappings.value, "device_name", null) 10 | no_device = lookup(block_device_mappings.value, "no_device", null) 11 | virtual_name = lookup(block_device_mappings.value, "virtual_name", null) 12 | 13 | dynamic "ebs" { 14 | for_each = lookup(block_device_mappings.value, "ebs", null) == null ? [] : ["ebs"] 15 | content { 16 | delete_on_termination = lookup(block_device_mappings.value.ebs, "delete_on_termination", null) 17 | encrypted = lookup(block_device_mappings.value.ebs, "encrypted", null) 18 | iops = lookup(block_device_mappings.value.ebs, "iops", null) 19 | kms_key_id = lookup(block_device_mappings.value.ebs, "kms_key_id", null) 20 | snapshot_id = lookup(block_device_mappings.value.ebs, "snapshot_id", null) 21 | volume_size = lookup(block_device_mappings.value.ebs, "volume_size", null) 22 | volume_type = lookup(block_device_mappings.value.ebs, "volume_type", null) 23 | } 24 | } 25 | } 26 | } 27 | 28 | dynamic "credit_specification" { 29 | for_each = var.credit_specification != null ? [var.credit_specification] : [] 30 | content { 31 | cpu_credits = lookup(credit_specification.value, "cpu_credits", null) 32 | } 33 | } 34 | 35 | disable_api_termination = var.disable_api_termination 36 | ebs_optimized = var.ebs_optimized 37 | update_default_version = var.update_default_version 38 | 39 | dynamic "elastic_gpu_specifications" { 40 | for_each = var.elastic_gpu_specifications != null ? [var.elastic_gpu_specifications] : [] 41 | content { 42 | type = lookup(elastic_gpu_specifications.value, "type", null) 43 | } 44 | } 45 | 46 | image_id = var.image_id 47 | instance_initiated_shutdown_behavior = var.instance_initiated_shutdown_behavior 48 | 49 | dynamic "instance_market_options" { 50 | for_each = var.instance_market_options != null ? [var.instance_market_options] : [] 51 | content { 52 | market_type = lookup(instance_market_options.value, "market_type", null) 53 | 54 | dynamic "spot_options" { 55 | for_each = (instance_market_options.value.spot_options != null ? 56 | [instance_market_options.value.spot_options] : []) 57 | content { 58 | block_duration_minutes = lookup(spot_options.value, "block_duration_minutes", null) 59 | instance_interruption_behavior = lookup(spot_options.value, "instance_interruption_behavior", null) 60 | max_price = lookup(spot_options.value, "max_price", null) 61 | spot_instance_type = lookup(spot_options.value, "spot_instance_type", null) 62 | valid_until = lookup(spot_options.value, "valid_until", null) 63 | } 64 | } 65 | } 66 | } 67 | 68 | instance_type = var.instance_type 69 | key_name = var.key_name 70 | 71 | dynamic "placement" { 72 | for_each = var.placement != null ? [var.placement] : [] 73 | content { 74 | affinity = lookup(placement.value, "affinity", null) 75 | availability_zone = lookup(placement.value, "availability_zone", null) 76 | group_name = lookup(placement.value, "group_name", null) 77 | host_id = lookup(placement.value, "host_id", null) 78 | tenancy = lookup(placement.value, "tenancy", null) 79 | } 80 | } 81 | 82 | user_data = var.user_data_base64 83 | 84 | dynamic "iam_instance_profile" { 85 | for_each = var.iam_instance_profile_name != "" ? [var.iam_instance_profile_name] : [] 86 | content { 87 | name = iam_instance_profile.value 88 | } 89 | } 90 | 91 | monitoring { 92 | enabled = var.enable_monitoring 93 | } 94 | 95 | # https://github.com/terraform-providers/terraform-provider-aws/issues/4570 96 | network_interfaces { 97 | description = module.this.id 98 | device_index = 0 99 | associate_public_ip_address = var.associate_public_ip_address 100 | delete_on_termination = true 101 | security_groups = var.security_group_ids 102 | } 103 | 104 | metadata_options { 105 | http_endpoint = (var.metadata_http_endpoint_enabled) ? "enabled" : "disabled" 106 | http_put_response_hop_limit = var.metadata_http_put_response_hop_limit 107 | http_tokens = (var.metadata_http_tokens_required) ? "required" : "optional" 108 | http_protocol_ipv6 = (var.metadata_http_protocol_ipv6_enabled) ? "enabled" : "disabled" 109 | instance_metadata_tags = (var.metadata_instance_metadata_tags_enabled) ? "enabled" : "disabled" 110 | } 111 | 112 | dynamic "tag_specifications" { 113 | for_each = var.tag_specifications_resource_types 114 | 115 | content { 116 | resource_type = tag_specifications.value 117 | tags = module.this.tags 118 | } 119 | } 120 | 121 | tags = module.this.tags 122 | 123 | lifecycle { 124 | create_before_destroy = true 125 | } 126 | } 127 | 128 | locals { 129 | launch_template_block = { 130 | id = join("", aws_launch_template.default.*.id) 131 | version = var.launch_template_version != "" ? var.launch_template_version : join("", aws_launch_template.default.*.latest_version) 132 | } 133 | launch_template = ( 134 | var.mixed_instances_policy == null ? local.launch_template_block 135 | : null) 136 | mixed_instances_policy = ( 137 | var.mixed_instances_policy == null ? null : { 138 | instances_distribution = var.mixed_instances_policy.instances_distribution 139 | launch_template = local.launch_template_block 140 | override = var.mixed_instances_policy.override 141 | }) 142 | } 143 | 144 | resource "aws_autoscaling_group" "default" { 145 | count = module.this.enabled ? 1 : 0 146 | 147 | name_prefix = format("%s%s", module.this.id, module.this.delimiter) 148 | vpc_zone_identifier = var.subnet_ids 149 | max_size = var.max_size 150 | min_size = var.min_size 151 | load_balancers = var.load_balancers 152 | health_check_grace_period = var.health_check_grace_period 153 | health_check_type = var.health_check_type 154 | min_elb_capacity = var.min_elb_capacity 155 | wait_for_elb_capacity = var.wait_for_elb_capacity 156 | target_group_arns = var.target_group_arns 157 | default_cooldown = var.default_cooldown 158 | force_delete = var.force_delete 159 | termination_policies = var.termination_policies 160 | suspended_processes = var.suspended_processes 161 | placement_group = var.placement_group 162 | enabled_metrics = var.enabled_metrics 163 | metrics_granularity = var.metrics_granularity 164 | wait_for_capacity_timeout = var.wait_for_capacity_timeout 165 | protect_from_scale_in = var.protect_from_scale_in 166 | service_linked_role_arn = var.service_linked_role_arn 167 | desired_capacity = var.desired_capacity 168 | max_instance_lifetime = var.max_instance_lifetime 169 | capacity_rebalance = var.capacity_rebalance 170 | 171 | dynamic "instance_refresh" { 172 | for_each = (var.instance_refresh != null ? [var.instance_refresh] : []) 173 | 174 | content { 175 | strategy = instance_refresh.value.strategy 176 | dynamic "preferences" { 177 | for_each = (length(instance_refresh.value.preferences) > 0 ? [instance_refresh.value.preferences] : []) 178 | content { 179 | instance_warmup = lookup(preferences.value, "instance_warmup", null) 180 | min_healthy_percentage = lookup(preferences.value, "min_healthy_percentage", null) 181 | } 182 | } 183 | triggers = instance_refresh.value.triggers 184 | } 185 | } 186 | 187 | dynamic "launch_template" { 188 | for_each = (local.launch_template != null ? 189 | [local.launch_template] : []) 190 | content { 191 | id = local.launch_template_block.id 192 | version = local.launch_template_block.version 193 | } 194 | } 195 | 196 | dynamic "mixed_instances_policy" { 197 | for_each = (local.mixed_instances_policy != null ? 198 | [local.mixed_instances_policy] : []) 199 | content { 200 | dynamic "instances_distribution" { 201 | for_each = ( 202 | mixed_instances_policy.value.instances_distribution != null ? 203 | [mixed_instances_policy.value.instances_distribution] : []) 204 | content { 205 | on_demand_allocation_strategy = lookup( 206 | instances_distribution.value, "on_demand_allocation_strategy", null) 207 | on_demand_base_capacity = lookup( 208 | instances_distribution.value, "on_demand_base_capacity", null) 209 | on_demand_percentage_above_base_capacity = lookup( 210 | instances_distribution.value, "on_demand_percentage_above_base_capacity", null) 211 | spot_allocation_strategy = lookup( 212 | instances_distribution.value, "spot_allocation_strategy", null) 213 | spot_instance_pools = lookup( 214 | instances_distribution.value, "spot_instance_pools", null) 215 | spot_max_price = lookup( 216 | instances_distribution.value, "spot_max_price", null) 217 | } 218 | } 219 | launch_template { 220 | launch_template_specification { 221 | launch_template_id = mixed_instances_policy.value.launch_template.id 222 | version = mixed_instances_policy.value.launch_template.version 223 | } 224 | dynamic "override" { 225 | for_each = (mixed_instances_policy.value.override != null ? 226 | mixed_instances_policy.value.override : []) 227 | content { 228 | instance_type = lookup(override.value, "instance_type", null) 229 | weighted_capacity = lookup(override.value, "weighted_capacity", null) 230 | } 231 | } 232 | } 233 | } 234 | } 235 | 236 | dynamic "warm_pool" { 237 | for_each = var.warm_pool != null ? [var.warm_pool] : [] 238 | content { 239 | pool_state = try(warm_pool.value.pool_state, null) 240 | min_size = try(warm_pool.value.min_size, null) 241 | max_group_prepared_capacity = try(warm_pool.value.max_group_prepared_capacity, null) 242 | } 243 | } 244 | 245 | tags = flatten([ 246 | for key in keys(module.this.tags) : 247 | { 248 | key = key 249 | value = module.this.tags[key] 250 | propagate_at_launch = true 251 | } 252 | ]) 253 | 254 | lifecycle { 255 | create_before_destroy = true 256 | ignore_changes = [desired_capacity] 257 | } 258 | } 259 | -------------------------------------------------------------------------------- /context.tf: -------------------------------------------------------------------------------- 1 | # 2 | # ONLY EDIT THIS FILE IN github.com/cloudposse/terraform-null-label 3 | # All other instances of this file should be a copy of that one 4 | # 5 | # 6 | # Copy this file from https://github.com/cloudposse/terraform-null-label/blob/master/exports/context.tf 7 | # and then place it in your Terraform module to automatically get 8 | # Cloud Posse's standard configuration inputs suitable for passing 9 | # to Cloud Posse modules. 10 | # 11 | # curl -sL https://raw.githubusercontent.com/cloudposse/terraform-null-label/master/exports/context.tf -o context.tf 12 | # 13 | # Modules should access the whole context as `module.this.context` 14 | # to get the input variables with nulls for defaults, 15 | # for example `context = module.this.context`, 16 | # and access individual variables as `module.this.`, 17 | # with final values filled in. 18 | # 19 | # For example, when using defaults, `module.this.context.delimiter` 20 | # will be null, and `module.this.delimiter` will be `-` (hyphen). 21 | # 22 | 23 | module "this" { 24 | source = "cloudposse/label/null" 25 | version = "0.25.0" # requires Terraform >= 0.13.0 26 | 27 | enabled = var.enabled 28 | namespace = var.namespace 29 | tenant = var.tenant 30 | environment = var.environment 31 | stage = var.stage 32 | name = var.name 33 | delimiter = var.delimiter 34 | attributes = var.attributes 35 | tags = var.tags 36 | additional_tag_map = var.additional_tag_map 37 | label_order = var.label_order 38 | regex_replace_chars = var.regex_replace_chars 39 | id_length_limit = var.id_length_limit 40 | label_key_case = var.label_key_case 41 | label_value_case = var.label_value_case 42 | descriptor_formats = var.descriptor_formats 43 | labels_as_tags = var.labels_as_tags 44 | 45 | context = var.context 46 | } 47 | 48 | # Copy contents of cloudposse/terraform-null-label/variables.tf here 49 | 50 | variable "context" { 51 | type = any 52 | default = { 53 | enabled = true 54 | namespace = null 55 | tenant = null 56 | environment = null 57 | stage = null 58 | name = null 59 | delimiter = null 60 | attributes = [] 61 | tags = {} 62 | additional_tag_map = {} 63 | regex_replace_chars = null 64 | label_order = [] 65 | id_length_limit = null 66 | label_key_case = null 67 | label_value_case = null 68 | descriptor_formats = {} 69 | # Note: we have to use [] instead of null for unset lists due to 70 | # https://github.com/hashicorp/terraform/issues/28137 71 | # which was not fixed until Terraform 1.0.0, 72 | # but we want the default to be all the labels in `label_order` 73 | # and we want users to be able to prevent all tag generation 74 | # by setting `labels_as_tags` to `[]`, so we need 75 | # a different sentinel to indicate "default" 76 | labels_as_tags = ["unset"] 77 | } 78 | description = <<-EOT 79 | Single object for setting entire context at once. 80 | See description of individual variables for details. 81 | Leave string and numeric variables as `null` to use default value. 82 | Individual variable settings (non-null) override settings in context object, 83 | except for attributes, tags, and additional_tag_map, which are merged. 84 | EOT 85 | 86 | validation { 87 | condition = lookup(var.context, "label_key_case", null) == null ? true : contains(["lower", "title", "upper"], var.context["label_key_case"]) 88 | error_message = "Allowed values: `lower`, `title`, `upper`." 89 | } 90 | 91 | validation { 92 | condition = lookup(var.context, "label_value_case", null) == null ? true : contains(["lower", "title", "upper", "none"], var.context["label_value_case"]) 93 | error_message = "Allowed values: `lower`, `title`, `upper`, `none`." 94 | } 95 | } 96 | 97 | variable "enabled" { 98 | type = bool 99 | default = null 100 | description = "Set to false to prevent the module from creating any resources" 101 | } 102 | 103 | variable "namespace" { 104 | type = string 105 | default = null 106 | description = "ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique" 107 | } 108 | 109 | variable "tenant" { 110 | type = string 111 | default = null 112 | description = "ID element _(Rarely used, not included by default)_. A customer identifier, indicating who this instance of a resource is for" 113 | } 114 | 115 | variable "environment" { 116 | type = string 117 | default = null 118 | description = "ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT'" 119 | } 120 | 121 | variable "stage" { 122 | type = string 123 | default = null 124 | description = "ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release'" 125 | } 126 | 127 | variable "name" { 128 | type = string 129 | default = null 130 | description = <<-EOT 131 | ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'. 132 | This is the only ID element not also included as a `tag`. 133 | The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input. 134 | EOT 135 | } 136 | 137 | variable "delimiter" { 138 | type = string 139 | default = null 140 | description = <<-EOT 141 | Delimiter to be used between ID elements. 142 | Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. 143 | EOT 144 | } 145 | 146 | variable "attributes" { 147 | type = list(string) 148 | default = [] 149 | description = <<-EOT 150 | ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`, 151 | in the order they appear in the list. New attributes are appended to the 152 | end of the list. The elements of the list are joined by the `delimiter` 153 | and treated as a single ID element. 154 | EOT 155 | } 156 | 157 | variable "labels_as_tags" { 158 | type = set(string) 159 | default = ["default"] 160 | description = <<-EOT 161 | Set of labels (ID elements) to include as tags in the `tags` output. 162 | Default is to include all labels. 163 | Tags with empty values will not be included in the `tags` output. 164 | Set to `[]` to suppress all generated tags. 165 | **Notes:** 166 | The value of the `name` tag, if included, will be the `id`, not the `name`. 167 | Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be 168 | changed in later chained modules. Attempts to change it will be silently ignored. 169 | EOT 170 | } 171 | 172 | variable "tags" { 173 | type = map(string) 174 | default = {} 175 | description = <<-EOT 176 | Additional tags (e.g. `{'BusinessUnit': 'XYZ'}`). 177 | Neither the tag keys nor the tag values will be modified by this module. 178 | EOT 179 | } 180 | 181 | variable "additional_tag_map" { 182 | type = map(string) 183 | default = {} 184 | description = <<-EOT 185 | Additional key-value pairs to add to each map in `tags_as_list_of_maps`. Not added to `tags` or `id`. 186 | This is for some rare cases where resources want additional configuration of tags 187 | and therefore take a list of maps with tag key, value, and additional configuration. 188 | EOT 189 | } 190 | 191 | variable "label_order" { 192 | type = list(string) 193 | default = null 194 | description = <<-EOT 195 | The order in which the labels (ID elements) appear in the `id`. 196 | Defaults to ["namespace", "environment", "stage", "name", "attributes"]. 197 | You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present. 198 | EOT 199 | } 200 | 201 | variable "regex_replace_chars" { 202 | type = string 203 | default = null 204 | description = <<-EOT 205 | Terraform regular expression (regex) string. 206 | Characters matching the regex will be removed from the ID elements. 207 | If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. 208 | EOT 209 | } 210 | 211 | variable "id_length_limit" { 212 | type = number 213 | default = null 214 | description = <<-EOT 215 | Limit `id` to this many characters (minimum 6). 216 | Set to `0` for unlimited length. 217 | Set to `null` for keep the existing setting, which defaults to `0`. 218 | Does not affect `id_full`. 219 | EOT 220 | validation { 221 | condition = var.id_length_limit == null ? true : var.id_length_limit >= 6 || var.id_length_limit == 0 222 | error_message = "The id_length_limit must be >= 6 if supplied (not null), or 0 for unlimited length." 223 | } 224 | } 225 | 226 | variable "label_key_case" { 227 | type = string 228 | default = null 229 | description = <<-EOT 230 | Controls the letter case of the `tags` keys (label names) for tags generated by this module. 231 | Does not affect keys of tags passed in via the `tags` input. 232 | Possible values: `lower`, `title`, `upper`. 233 | Default value: `title`. 234 | EOT 235 | 236 | validation { 237 | condition = var.label_key_case == null ? true : contains(["lower", "title", "upper"], var.label_key_case) 238 | error_message = "Allowed values: `lower`, `title`, `upper`." 239 | } 240 | } 241 | 242 | variable "label_value_case" { 243 | type = string 244 | default = null 245 | description = <<-EOT 246 | Controls the letter case of ID elements (labels) as included in `id`, 247 | set as tag values, and output by this module individually. 248 | Does not affect values of tags passed in via the `tags` input. 249 | Possible values: `lower`, `title`, `upper` and `none` (no transformation). 250 | Set this to `title` and set `delimiter` to `""` to yield Pascal Case IDs. 251 | Default value: `lower`. 252 | EOT 253 | 254 | validation { 255 | condition = var.label_value_case == null ? true : contains(["lower", "title", "upper", "none"], var.label_value_case) 256 | error_message = "Allowed values: `lower`, `title`, `upper`, `none`." 257 | } 258 | } 259 | 260 | variable "descriptor_formats" { 261 | type = any 262 | default = {} 263 | description = <<-EOT 264 | Describe additional descriptors to be output in the `descriptors` output map. 265 | Map of maps. Keys are names of descriptors. Values are maps of the form 266 | `{ 267 | format = string 268 | labels = list(string) 269 | }` 270 | (Type is `any` so the map values can later be enhanced to provide additional options.) 271 | `format` is a Terraform format string to be passed to the `format()` function. 272 | `labels` is a list of labels, in order, to pass to `format()` function. 273 | Label values will be normalized before being passed to `format()` so they will be 274 | identical to how they appear in `id`. 275 | Default is `{}` (`descriptors` output will be empty). 276 | EOT 277 | } 278 | 279 | #### End of copy of cloudposse/terraform-null-label/variables.tf 280 | -------------------------------------------------------------------------------- /examples/complete/context.tf: -------------------------------------------------------------------------------- 1 | # 2 | # ONLY EDIT THIS FILE IN github.com/cloudposse/terraform-null-label 3 | # All other instances of this file should be a copy of that one 4 | # 5 | # 6 | # Copy this file from https://github.com/cloudposse/terraform-null-label/blob/master/exports/context.tf 7 | # and then place it in your Terraform module to automatically get 8 | # Cloud Posse's standard configuration inputs suitable for passing 9 | # to Cloud Posse modules. 10 | # 11 | # curl -sL https://raw.githubusercontent.com/cloudposse/terraform-null-label/master/exports/context.tf -o context.tf 12 | # 13 | # Modules should access the whole context as `module.this.context` 14 | # to get the input variables with nulls for defaults, 15 | # for example `context = module.this.context`, 16 | # and access individual variables as `module.this.`, 17 | # with final values filled in. 18 | # 19 | # For example, when using defaults, `module.this.context.delimiter` 20 | # will be null, and `module.this.delimiter` will be `-` (hyphen). 21 | # 22 | 23 | module "this" { 24 | source = "cloudposse/label/null" 25 | version = "0.25.0" # requires Terraform >= 0.13.0 26 | 27 | enabled = var.enabled 28 | namespace = var.namespace 29 | tenant = var.tenant 30 | environment = var.environment 31 | stage = var.stage 32 | name = var.name 33 | delimiter = var.delimiter 34 | attributes = var.attributes 35 | tags = var.tags 36 | additional_tag_map = var.additional_tag_map 37 | label_order = var.label_order 38 | regex_replace_chars = var.regex_replace_chars 39 | id_length_limit = var.id_length_limit 40 | label_key_case = var.label_key_case 41 | label_value_case = var.label_value_case 42 | descriptor_formats = var.descriptor_formats 43 | labels_as_tags = var.labels_as_tags 44 | 45 | context = var.context 46 | } 47 | 48 | # Copy contents of cloudposse/terraform-null-label/variables.tf here 49 | 50 | variable "context" { 51 | type = any 52 | default = { 53 | enabled = true 54 | namespace = null 55 | tenant = null 56 | environment = null 57 | stage = null 58 | name = null 59 | delimiter = null 60 | attributes = [] 61 | tags = {} 62 | additional_tag_map = {} 63 | regex_replace_chars = null 64 | label_order = [] 65 | id_length_limit = null 66 | label_key_case = null 67 | label_value_case = null 68 | descriptor_formats = {} 69 | # Note: we have to use [] instead of null for unset lists due to 70 | # https://github.com/hashicorp/terraform/issues/28137 71 | # which was not fixed until Terraform 1.0.0, 72 | # but we want the default to be all the labels in `label_order` 73 | # and we want users to be able to prevent all tag generation 74 | # by setting `labels_as_tags` to `[]`, so we need 75 | # a different sentinel to indicate "default" 76 | labels_as_tags = ["unset"] 77 | } 78 | description = <<-EOT 79 | Single object for setting entire context at once. 80 | See description of individual variables for details. 81 | Leave string and numeric variables as `null` to use default value. 82 | Individual variable settings (non-null) override settings in context object, 83 | except for attributes, tags, and additional_tag_map, which are merged. 84 | EOT 85 | 86 | validation { 87 | condition = lookup(var.context, "label_key_case", null) == null ? true : contains(["lower", "title", "upper"], var.context["label_key_case"]) 88 | error_message = "Allowed values: `lower`, `title`, `upper`." 89 | } 90 | 91 | validation { 92 | condition = lookup(var.context, "label_value_case", null) == null ? true : contains(["lower", "title", "upper", "none"], var.context["label_value_case"]) 93 | error_message = "Allowed values: `lower`, `title`, `upper`, `none`." 94 | } 95 | } 96 | 97 | variable "enabled" { 98 | type = bool 99 | default = null 100 | description = "Set to false to prevent the module from creating any resources" 101 | } 102 | 103 | variable "namespace" { 104 | type = string 105 | default = null 106 | description = "ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique" 107 | } 108 | 109 | variable "tenant" { 110 | type = string 111 | default = null 112 | description = "ID element _(Rarely used, not included by default)_. A customer identifier, indicating who this instance of a resource is for" 113 | } 114 | 115 | variable "environment" { 116 | type = string 117 | default = null 118 | description = "ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT'" 119 | } 120 | 121 | variable "stage" { 122 | type = string 123 | default = null 124 | description = "ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release'" 125 | } 126 | 127 | variable "name" { 128 | type = string 129 | default = null 130 | description = <<-EOT 131 | ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'. 132 | This is the only ID element not also included as a `tag`. 133 | The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input. 134 | EOT 135 | } 136 | 137 | variable "delimiter" { 138 | type = string 139 | default = null 140 | description = <<-EOT 141 | Delimiter to be used between ID elements. 142 | Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. 143 | EOT 144 | } 145 | 146 | variable "attributes" { 147 | type = list(string) 148 | default = [] 149 | description = <<-EOT 150 | ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`, 151 | in the order they appear in the list. New attributes are appended to the 152 | end of the list. The elements of the list are joined by the `delimiter` 153 | and treated as a single ID element. 154 | EOT 155 | } 156 | 157 | variable "labels_as_tags" { 158 | type = set(string) 159 | default = ["default"] 160 | description = <<-EOT 161 | Set of labels (ID elements) to include as tags in the `tags` output. 162 | Default is to include all labels. 163 | Tags with empty values will not be included in the `tags` output. 164 | Set to `[]` to suppress all generated tags. 165 | **Notes:** 166 | The value of the `name` tag, if included, will be the `id`, not the `name`. 167 | Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be 168 | changed in later chained modules. Attempts to change it will be silently ignored. 169 | EOT 170 | } 171 | 172 | variable "tags" { 173 | type = map(string) 174 | default = {} 175 | description = <<-EOT 176 | Additional tags (e.g. `{'BusinessUnit': 'XYZ'}`). 177 | Neither the tag keys nor the tag values will be modified by this module. 178 | EOT 179 | } 180 | 181 | variable "additional_tag_map" { 182 | type = map(string) 183 | default = {} 184 | description = <<-EOT 185 | Additional key-value pairs to add to each map in `tags_as_list_of_maps`. Not added to `tags` or `id`. 186 | This is for some rare cases where resources want additional configuration of tags 187 | and therefore take a list of maps with tag key, value, and additional configuration. 188 | EOT 189 | } 190 | 191 | variable "label_order" { 192 | type = list(string) 193 | default = null 194 | description = <<-EOT 195 | The order in which the labels (ID elements) appear in the `id`. 196 | Defaults to ["namespace", "environment", "stage", "name", "attributes"]. 197 | You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present. 198 | EOT 199 | } 200 | 201 | variable "regex_replace_chars" { 202 | type = string 203 | default = null 204 | description = <<-EOT 205 | Terraform regular expression (regex) string. 206 | Characters matching the regex will be removed from the ID elements. 207 | If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. 208 | EOT 209 | } 210 | 211 | variable "id_length_limit" { 212 | type = number 213 | default = null 214 | description = <<-EOT 215 | Limit `id` to this many characters (minimum 6). 216 | Set to `0` for unlimited length. 217 | Set to `null` for keep the existing setting, which defaults to `0`. 218 | Does not affect `id_full`. 219 | EOT 220 | validation { 221 | condition = var.id_length_limit == null ? true : var.id_length_limit >= 6 || var.id_length_limit == 0 222 | error_message = "The id_length_limit must be >= 6 if supplied (not null), or 0 for unlimited length." 223 | } 224 | } 225 | 226 | variable "label_key_case" { 227 | type = string 228 | default = null 229 | description = <<-EOT 230 | Controls the letter case of the `tags` keys (label names) for tags generated by this module. 231 | Does not affect keys of tags passed in via the `tags` input. 232 | Possible values: `lower`, `title`, `upper`. 233 | Default value: `title`. 234 | EOT 235 | 236 | validation { 237 | condition = var.label_key_case == null ? true : contains(["lower", "title", "upper"], var.label_key_case) 238 | error_message = "Allowed values: `lower`, `title`, `upper`." 239 | } 240 | } 241 | 242 | variable "label_value_case" { 243 | type = string 244 | default = null 245 | description = <<-EOT 246 | Controls the letter case of ID elements (labels) as included in `id`, 247 | set as tag values, and output by this module individually. 248 | Does not affect values of tags passed in via the `tags` input. 249 | Possible values: `lower`, `title`, `upper` and `none` (no transformation). 250 | Set this to `title` and set `delimiter` to `""` to yield Pascal Case IDs. 251 | Default value: `lower`. 252 | EOT 253 | 254 | validation { 255 | condition = var.label_value_case == null ? true : contains(["lower", "title", "upper", "none"], var.label_value_case) 256 | error_message = "Allowed values: `lower`, `title`, `upper`, `none`." 257 | } 258 | } 259 | 260 | variable "descriptor_formats" { 261 | type = any 262 | default = {} 263 | description = <<-EOT 264 | Describe additional descriptors to be output in the `descriptors` output map. 265 | Map of maps. Keys are names of descriptors. Values are maps of the form 266 | `{ 267 | format = string 268 | labels = list(string) 269 | }` 270 | (Type is `any` so the map values can later be enhanced to provide additional options.) 271 | `format` is a Terraform format string to be passed to the `format()` function. 272 | `labels` is a list of labels, in order, to pass to `format()` function. 273 | Label values will be normalized before being passed to `format()` so they will be 274 | identical to how they appear in `id`. 275 | Default is `{}` (`descriptors` output will be empty). 276 | EOT 277 | } 278 | 279 | #### End of copy of cloudposse/terraform-null-label/variables.tf 280 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2018-2020 Cloud Posse, LLC 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /variables.tf: -------------------------------------------------------------------------------- 1 | variable "image_id" { 2 | type = string 3 | description = "The EC2 image ID to launch" 4 | default = "" 5 | } 6 | 7 | variable "instance_initiated_shutdown_behavior" { 8 | type = string 9 | description = "Shutdown behavior for the instances. Can be `stop` or `terminate`" 10 | default = "terminate" 11 | } 12 | 13 | variable "instance_type" { 14 | type = string 15 | description = "Instance type to launch" 16 | } 17 | 18 | variable "iam_instance_profile_name" { 19 | type = string 20 | description = "The IAM instance profile name to associate with launched instances" 21 | default = "" 22 | } 23 | 24 | variable "key_name" { 25 | type = string 26 | description = "The SSH key name that should be used for the instance" 27 | default = "" 28 | } 29 | 30 | variable "security_group_ids" { 31 | description = "A list of associated security group IDs" 32 | type = list(string) 33 | default = [] 34 | } 35 | 36 | variable "launch_template_version" { 37 | type = string 38 | description = "Launch template version. Can be version number, `$Latest` or `$Default`" 39 | default = "$Latest" 40 | } 41 | 42 | variable "associate_public_ip_address" { 43 | type = bool 44 | description = "Associate a public IP address with an instance in a VPC" 45 | default = false 46 | } 47 | 48 | variable "user_data_base64" { 49 | type = string 50 | description = "The Base64-encoded user data to provide when launching the instances" 51 | default = "" 52 | } 53 | 54 | variable "enable_monitoring" { 55 | type = bool 56 | description = "Enable/disable detailed monitoring" 57 | default = true 58 | } 59 | 60 | variable "update_default_version" { 61 | type = bool 62 | description = "Whether to update Default version of Launch template each update" 63 | default = false 64 | } 65 | 66 | variable "ebs_optimized" { 67 | type = bool 68 | description = "If true, the launched EC2 instance will be EBS-optimized" 69 | default = false 70 | } 71 | 72 | variable "block_device_mappings" { 73 | description = "Specify volumes to attach to the instance besides the volumes specified by the AMI" 74 | 75 | type = list(object({ 76 | device_name = string 77 | no_device = bool 78 | virtual_name = string 79 | ebs = object({ 80 | delete_on_termination = bool 81 | encrypted = bool 82 | iops = number 83 | kms_key_id = string 84 | snapshot_id = string 85 | volume_size = number 86 | volume_type = string 87 | }) 88 | })) 89 | 90 | default = [] 91 | } 92 | 93 | variable "instance_market_options" { 94 | description = "The market (purchasing) option for the instances" 95 | 96 | type = object({ 97 | market_type = string 98 | spot_options = object({ 99 | block_duration_minutes = number 100 | instance_interruption_behavior = string 101 | max_price = number 102 | spot_instance_type = string 103 | valid_until = string 104 | }) 105 | }) 106 | 107 | default = null 108 | } 109 | 110 | variable "instance_refresh" { 111 | description = "The instance refresh definition" 112 | type = object({ 113 | strategy = string 114 | preferences = object({ 115 | instance_warmup = number 116 | min_healthy_percentage = number 117 | }) 118 | triggers = list(string) 119 | }) 120 | 121 | default = null 122 | } 123 | 124 | variable "mixed_instances_policy" { 125 | description = "policy to used mixed group of on demand/spot of differing types. Launch template is automatically generated. https://www.terraform.io/docs/providers/aws/r/autoscaling_group.html#mixed_instances_policy-1" 126 | 127 | type = object({ 128 | instances_distribution = object({ 129 | on_demand_allocation_strategy = string 130 | on_demand_base_capacity = number 131 | on_demand_percentage_above_base_capacity = number 132 | spot_allocation_strategy = string 133 | spot_instance_pools = number 134 | spot_max_price = string 135 | }) 136 | override = list(object({ 137 | instance_type = string 138 | weighted_capacity = number 139 | })) 140 | }) 141 | default = null 142 | } 143 | 144 | variable "placement" { 145 | description = "The placement specifications of the instances" 146 | 147 | type = object({ 148 | affinity = string 149 | availability_zone = string 150 | group_name = string 151 | host_id = string 152 | tenancy = string 153 | }) 154 | 155 | default = null 156 | } 157 | 158 | variable "credit_specification" { 159 | description = "Customize the credit specification of the instances" 160 | 161 | type = object({ 162 | cpu_credits = string 163 | }) 164 | 165 | default = null 166 | } 167 | 168 | variable "elastic_gpu_specifications" { 169 | description = "Specifications of Elastic GPU to attach to the instances" 170 | 171 | type = object({ 172 | type = string 173 | }) 174 | 175 | default = null 176 | } 177 | 178 | variable "disable_api_termination" { 179 | type = bool 180 | description = "If `true`, enables EC2 Instance Termination Protection" 181 | default = false 182 | } 183 | 184 | variable "max_size" { 185 | type = number 186 | description = "The maximum size of the autoscale group" 187 | } 188 | 189 | variable "min_size" { 190 | type = number 191 | description = "The minimum size of the autoscale group" 192 | } 193 | 194 | variable "subnet_ids" { 195 | description = "A list of subnet IDs to launch resources in" 196 | type = list(string) 197 | } 198 | 199 | variable "default_cooldown" { 200 | type = number 201 | description = "The amount of time, in seconds, after a scaling activity completes before another scaling activity can start" 202 | default = 300 203 | } 204 | 205 | variable "health_check_grace_period" { 206 | type = number 207 | description = "Time (in seconds) after instance comes into service before checking health" 208 | default = 300 209 | } 210 | 211 | variable "health_check_type" { 212 | type = string 213 | description = "Controls how health checking is done. Valid values are `EC2` or `ELB`" 214 | default = "EC2" 215 | } 216 | 217 | variable "force_delete" { 218 | type = bool 219 | description = "Allows deleting the autoscaling group without waiting for all instances in the pool to terminate. You can force an autoscaling group to delete even if it's in the process of scaling a resource. Normally, Terraform drains all the instances before deleting the group. This bypasses that behavior and potentially leaves resources dangling" 220 | default = false 221 | } 222 | 223 | variable "load_balancers" { 224 | type = list(string) 225 | description = "A list of elastic load balancer names to add to the autoscaling group names. Only valid for classic load balancers. For ALBs, use `target_group_arns` instead" 226 | default = [] 227 | } 228 | 229 | variable "target_group_arns" { 230 | type = list(string) 231 | description = "A list of aws_alb_target_group ARNs, for use with Application Load Balancing" 232 | default = [] 233 | } 234 | 235 | variable "termination_policies" { 236 | description = "A list of policies to decide how the instances in the auto scale group should be terminated. The allowed values are `OldestInstance`, `NewestInstance`, `OldestLaunchConfiguration`, `ClosestToNextInstanceHour`, `Default`" 237 | type = list(string) 238 | default = ["Default"] 239 | } 240 | 241 | variable "suspended_processes" { 242 | type = list(string) 243 | description = "A list of processes to suspend for the AutoScaling Group. The allowed values are `Launch`, `Terminate`, `HealthCheck`, `ReplaceUnhealthy`, `AZRebalance`, `AlarmNotification`, `ScheduledActions`, `AddToLoadBalancer`. Note that if you suspend either the `Launch` or `Terminate` process types, it can prevent your autoscaling group from functioning properly." 244 | default = [] 245 | } 246 | 247 | variable "placement_group" { 248 | type = string 249 | description = "The name of the placement group into which you'll launch your instances, if any" 250 | default = "" 251 | } 252 | 253 | variable "metrics_granularity" { 254 | type = string 255 | description = "The granularity to associate with the metrics to collect. The only valid value is 1Minute" 256 | default = "1Minute" 257 | } 258 | 259 | variable "enabled_metrics" { 260 | description = "A list of metrics to collect. The allowed values are `GroupMinSize`, `GroupMaxSize`, `GroupDesiredCapacity`, `GroupInServiceInstances`, `GroupPendingInstances`, `GroupStandbyInstances`, `GroupTerminatingInstances`, `GroupTotalInstances`" 261 | type = list(string) 262 | 263 | default = [ 264 | "GroupMinSize", 265 | "GroupMaxSize", 266 | "GroupDesiredCapacity", 267 | "GroupInServiceInstances", 268 | "GroupPendingInstances", 269 | "GroupStandbyInstances", 270 | "GroupTerminatingInstances", 271 | "GroupTotalInstances", 272 | ] 273 | } 274 | 275 | variable "wait_for_capacity_timeout" { 276 | type = string 277 | description = "A maximum duration that Terraform should wait for ASG instances to be healthy before timing out. Setting this to '0' causes Terraform to skip all Capacity Waiting behavior" 278 | default = "10m" 279 | } 280 | 281 | variable "min_elb_capacity" { 282 | type = number 283 | description = "Setting this causes Terraform to wait for this number of instances to show up healthy in the ELB only on creation. Updates will not wait on ELB instance number changes" 284 | default = 0 285 | } 286 | 287 | variable "wait_for_elb_capacity" { 288 | type = number 289 | description = "Setting this will cause Terraform to wait for exactly this number of healthy instances in all attached load balancers on both create and update operations. Takes precedence over `min_elb_capacity` behavior" 290 | default = 0 291 | } 292 | 293 | variable "protect_from_scale_in" { 294 | type = bool 295 | description = "Allows setting instance protection. The autoscaling group will not select instances with this setting for terminination during scale in events" 296 | default = false 297 | } 298 | 299 | variable "service_linked_role_arn" { 300 | type = string 301 | description = "The ARN of the service-linked role that the ASG will use to call other AWS services" 302 | default = "" 303 | } 304 | 305 | variable "autoscaling_policies_enabled" { 306 | type = bool 307 | default = true 308 | description = "Whether to create `aws_autoscaling_policy` and `aws_cloudwatch_metric_alarm` resources to control Auto Scaling" 309 | } 310 | 311 | variable "scale_up_cooldown_seconds" { 312 | type = number 313 | default = 300 314 | description = "The amount of time, in seconds, after a scaling activity completes and before the next scaling activity can start" 315 | } 316 | 317 | variable "scale_up_scaling_adjustment" { 318 | type = number 319 | default = 1 320 | description = "The number of instances by which to scale. `scale_up_adjustment_type` determines the interpretation of this number (e.g. as an absolute number or as a percentage of the existing Auto Scaling group size). A positive increment adds to the current capacity and a negative value removes from the current capacity" 321 | } 322 | 323 | variable "scale_up_adjustment_type" { 324 | type = string 325 | default = "ChangeInCapacity" 326 | description = "Specifies whether the adjustment is an absolute number or a percentage of the current capacity. Valid values are `ChangeInCapacity`, `ExactCapacity` and `PercentChangeInCapacity`" 327 | } 328 | 329 | variable "scale_up_policy_type" { 330 | type = string 331 | default = "SimpleScaling" 332 | description = "The scaling policy type. Currently only `SimpleScaling` is supported" 333 | } 334 | 335 | variable "scale_down_cooldown_seconds" { 336 | type = number 337 | default = 300 338 | description = "The amount of time, in seconds, after a scaling activity completes and before the next scaling activity can start" 339 | } 340 | 341 | variable "scale_down_scaling_adjustment" { 342 | type = number 343 | default = -1 344 | description = "The number of instances by which to scale. `scale_down_scaling_adjustment` determines the interpretation of this number (e.g. as an absolute number or as a percentage of the existing Auto Scaling group size). A positive increment adds to the current capacity and a negative value removes from the current capacity" 345 | } 346 | 347 | variable "scale_down_adjustment_type" { 348 | type = string 349 | default = "ChangeInCapacity" 350 | description = "Specifies whether the adjustment is an absolute number or a percentage of the current capacity. Valid values are `ChangeInCapacity`, `ExactCapacity` and `PercentChangeInCapacity`" 351 | } 352 | 353 | variable "scale_down_policy_type" { 354 | type = string 355 | default = "SimpleScaling" 356 | description = "The scaling policy type. Currently only `SimpleScaling` is supported" 357 | } 358 | 359 | variable "cpu_utilization_high_evaluation_periods" { 360 | type = number 361 | default = 2 362 | description = "The number of periods over which data is compared to the specified threshold" 363 | } 364 | 365 | variable "cpu_utilization_high_period_seconds" { 366 | type = number 367 | default = 300 368 | description = "The period in seconds over which the specified statistic is applied" 369 | } 370 | 371 | variable "cpu_utilization_high_threshold_percent" { 372 | type = number 373 | default = 90 374 | description = "The value against which the specified statistic is compared" 375 | } 376 | 377 | variable "cpu_utilization_high_statistic" { 378 | type = string 379 | default = "Average" 380 | description = "The statistic to apply to the alarm's associated metric. Either of the following is supported: `SampleCount`, `Average`, `Sum`, `Minimum`, `Maximum`" 381 | } 382 | 383 | variable "cpu_utilization_low_evaluation_periods" { 384 | type = number 385 | default = 2 386 | description = "The number of periods over which data is compared to the specified threshold" 387 | } 388 | 389 | variable "cpu_utilization_low_period_seconds" { 390 | type = number 391 | default = 300 392 | description = "The period in seconds over which the specified statistic is applied" 393 | } 394 | 395 | variable "cpu_utilization_low_threshold_percent" { 396 | type = number 397 | default = 10 398 | description = "The value against which the specified statistic is compared" 399 | } 400 | 401 | variable "cpu_utilization_low_statistic" { 402 | type = string 403 | default = "Average" 404 | description = "The statistic to apply to the alarm's associated metric. Either of the following is supported: `SampleCount`, `Average`, `Sum`, `Minimum`, `Maximum`" 405 | } 406 | 407 | variable "desired_capacity" { 408 | type = number 409 | description = "The number of Amazon EC2 instances that should be running in the group, if not set will use `min_size` as value" 410 | default = null 411 | } 412 | 413 | variable "default_alarms_enabled" { 414 | type = bool 415 | default = true 416 | description = "Enable or disable cpu and memory Cloudwatch alarms" 417 | } 418 | 419 | variable "custom_alarms" { 420 | type = map(object({ 421 | alarm_name = string 422 | comparison_operator = string 423 | evaluation_periods = string 424 | metric_name = string 425 | namespace = string 426 | period = string 427 | statistic = string 428 | threshold = string 429 | treat_missing_data = string 430 | ok_actions = list(string) 431 | insufficient_data_actions = list(string) 432 | dimensions_name = string 433 | dimensions_target = string 434 | alarm_description = string 435 | alarm_actions = list(string) 436 | })) 437 | default = {} 438 | description = "Map of custom CloudWatch alarms configurations" 439 | } 440 | 441 | variable "metadata_http_endpoint_enabled" { 442 | type = bool 443 | default = true 444 | description = "Set false to disable the Instance Metadata Service." 445 | } 446 | 447 | variable "metadata_http_put_response_hop_limit" { 448 | type = number 449 | default = 2 450 | description = <<-EOT 451 | The desired HTTP PUT response hop limit (between 1 and 64) for Instance Metadata Service requests. 452 | The default is `2` to support containerized workloads. 453 | EOT 454 | } 455 | 456 | variable "metadata_http_tokens_required" { 457 | type = bool 458 | default = true 459 | description = "Set true to require IMDS session tokens, disabling Instance Metadata Service Version 1." 460 | } 461 | 462 | variable "metadata_http_protocol_ipv6_enabled" { 463 | type = bool 464 | default = false 465 | description = "Set true to enable IPv6 in the launch template." 466 | } 467 | 468 | 469 | variable "metadata_instance_metadata_tags_enabled" { 470 | type = bool 471 | default = false 472 | description = "Set true to enable metadata tags in the launch template." 473 | } 474 | variable "tag_specifications_resource_types" { 475 | type = set(string) 476 | default = ["instance", "volume"] 477 | description = "List of tag specification resource types to tag. Valid values are instance, volume, elastic-gpu and spot-instances-request." 478 | } 479 | 480 | variable "max_instance_lifetime" { 481 | type = number 482 | default = null 483 | description = "The maximum amount of time, in seconds, that an instance can be in service, values must be either equal to 0 or between 604800 and 31536000 seconds" 484 | } 485 | 486 | variable "capacity_rebalance" { 487 | type = bool 488 | default = false 489 | description = "Indicates whether capacity rebalance is enabled. Otherwise, capacity rebalance is disabled." 490 | } 491 | 492 | variable "warm_pool" { 493 | type = object({ 494 | pool_state = string 495 | min_size = number 496 | max_group_prepared_capacity = number 497 | }) 498 | description = "If this block is configured, add a Warm Pool to the specified Auto Scaling group. See [warm_pool](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/autoscaling_group#warm_pool)." 499 | default = null 500 | } 501 | -------------------------------------------------------------------------------- /docs/terraform.md: -------------------------------------------------------------------------------- 1 | 2 | ## Requirements 3 | 4 | | Name | Version | 5 | |------|---------| 6 | | [terraform](#requirement\_terraform) | >= 0.13 | 7 | | [aws](#requirement\_aws) | >= 2.0 | 8 | 9 | ## Providers 10 | 11 | | Name | Version | 12 | |------|---------| 13 | | [aws](#provider\_aws) | >= 2.0 | 14 | 15 | ## Modules 16 | 17 | | Name | Source | Version | 18 | |------|--------|---------| 19 | | [this](#module\_this) | cloudposse/label/null | 0.25.0 | 20 | 21 | ## Resources 22 | 23 | | Name | Type | 24 | |------|------| 25 | | [aws_autoscaling_group.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/autoscaling_group) | resource | 26 | | [aws_autoscaling_policy.scale_down](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/autoscaling_policy) | resource | 27 | | [aws_autoscaling_policy.scale_up](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/autoscaling_policy) | resource | 28 | | [aws_cloudwatch_metric_alarm.all_alarms](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_metric_alarm) | resource | 29 | | [aws_launch_template.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/launch_template) | resource | 30 | 31 | ## Inputs 32 | 33 | | Name | Description | Type | Default | Required | 34 | |------|-------------|------|---------|:--------:| 35 | | [additional\_tag\_map](#input\_additional\_tag\_map) | Additional key-value pairs to add to each map in `tags_as_list_of_maps`. Not added to `tags` or `id`.
This is for some rare cases where resources want additional configuration of tags
and therefore take a list of maps with tag key, value, and additional configuration. | `map(string)` | `{}` | no | 36 | | [associate\_public\_ip\_address](#input\_associate\_public\_ip\_address) | Associate a public IP address with an instance in a VPC | `bool` | `false` | no | 37 | | [attributes](#input\_attributes) | ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`,
in the order they appear in the list. New attributes are appended to the
end of the list. The elements of the list are joined by the `delimiter`
and treated as a single ID element. | `list(string)` | `[]` | no | 38 | | [autoscaling\_policies\_enabled](#input\_autoscaling\_policies\_enabled) | Whether to create `aws_autoscaling_policy` and `aws_cloudwatch_metric_alarm` resources to control Auto Scaling | `bool` | `true` | no | 39 | | [block\_device\_mappings](#input\_block\_device\_mappings) | Specify volumes to attach to the instance besides the volumes specified by the AMI |
list(object({
device_name = string
no_device = bool
virtual_name = string
ebs = object({
delete_on_termination = bool
encrypted = bool
iops = number
kms_key_id = string
snapshot_id = string
volume_size = number
volume_type = string
})
}))
| `[]` | no | 40 | | [capacity\_rebalance](#input\_capacity\_rebalance) | Indicates whether capacity rebalance is enabled. Otherwise, capacity rebalance is disabled. | `bool` | `false` | no | 41 | | [context](#input\_context) | Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as `null` to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional\_tag\_map, which are merged. | `any` |
{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"descriptor_formats": {},
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_key_case": null,
"label_order": [],
"label_value_case": null,
"labels_as_tags": [
"unset"
],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {},
"tenant": null
}
| no | 42 | | [cpu\_utilization\_high\_evaluation\_periods](#input\_cpu\_utilization\_high\_evaluation\_periods) | The number of periods over which data is compared to the specified threshold | `number` | `2` | no | 43 | | [cpu\_utilization\_high\_period\_seconds](#input\_cpu\_utilization\_high\_period\_seconds) | The period in seconds over which the specified statistic is applied | `number` | `300` | no | 44 | | [cpu\_utilization\_high\_statistic](#input\_cpu\_utilization\_high\_statistic) | The statistic to apply to the alarm's associated metric. Either of the following is supported: `SampleCount`, `Average`, `Sum`, `Minimum`, `Maximum` | `string` | `"Average"` | no | 45 | | [cpu\_utilization\_high\_threshold\_percent](#input\_cpu\_utilization\_high\_threshold\_percent) | The value against which the specified statistic is compared | `number` | `90` | no | 46 | | [cpu\_utilization\_low\_evaluation\_periods](#input\_cpu\_utilization\_low\_evaluation\_periods) | The number of periods over which data is compared to the specified threshold | `number` | `2` | no | 47 | | [cpu\_utilization\_low\_period\_seconds](#input\_cpu\_utilization\_low\_period\_seconds) | The period in seconds over which the specified statistic is applied | `number` | `300` | no | 48 | | [cpu\_utilization\_low\_statistic](#input\_cpu\_utilization\_low\_statistic) | The statistic to apply to the alarm's associated metric. Either of the following is supported: `SampleCount`, `Average`, `Sum`, `Minimum`, `Maximum` | `string` | `"Average"` | no | 49 | | [cpu\_utilization\_low\_threshold\_percent](#input\_cpu\_utilization\_low\_threshold\_percent) | The value against which the specified statistic is compared | `number` | `10` | no | 50 | | [credit\_specification](#input\_credit\_specification) | Customize the credit specification of the instances |
object({
cpu_credits = string
})
| `null` | no | 51 | | [custom\_alarms](#input\_custom\_alarms) | Map of custom CloudWatch alarms configurations |
map(object({
alarm_name = string
comparison_operator = string
evaluation_periods = string
metric_name = string
namespace = string
period = string
statistic = string
threshold = string
treat_missing_data = string
ok_actions = list(string)
insufficient_data_actions = list(string)
dimensions_name = string
dimensions_target = string
alarm_description = string
alarm_actions = list(string)
}))
| `{}` | no | 52 | | [default\_alarms\_enabled](#input\_default\_alarms\_enabled) | Enable or disable cpu and memory Cloudwatch alarms | `bool` | `true` | no | 53 | | [default\_cooldown](#input\_default\_cooldown) | The amount of time, in seconds, after a scaling activity completes before another scaling activity can start | `number` | `300` | no | 54 | | [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no | 55 | | [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map.
Map of maps. Keys are names of descriptors. Values are maps of the form
`{
format = string
labels = list(string)
}`
(Type is `any` so the map values can later be enhanced to provide additional options.)
`format` is a Terraform format string to be passed to the `format()` function.
`labels` is a list of labels, in order, to pass to `format()` function.
Label values will be normalized before being passed to `format()` so they will be
identical to how they appear in `id`.
Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no | 56 | | [desired\_capacity](#input\_desired\_capacity) | The number of Amazon EC2 instances that should be running in the group, if not set will use `min_size` as value | `number` | `null` | no | 57 | | [disable\_api\_termination](#input\_disable\_api\_termination) | If `true`, enables EC2 Instance Termination Protection | `bool` | `false` | no | 58 | | [ebs\_optimized](#input\_ebs\_optimized) | If true, the launched EC2 instance will be EBS-optimized | `bool` | `false` | no | 59 | | [elastic\_gpu\_specifications](#input\_elastic\_gpu\_specifications) | Specifications of Elastic GPU to attach to the instances |
object({
type = string
})
| `null` | no | 60 | | [enable\_monitoring](#input\_enable\_monitoring) | Enable/disable detailed monitoring | `bool` | `true` | no | 61 | | [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no | 62 | | [enabled\_metrics](#input\_enabled\_metrics) | A list of metrics to collect. The allowed values are `GroupMinSize`, `GroupMaxSize`, `GroupDesiredCapacity`, `GroupInServiceInstances`, `GroupPendingInstances`, `GroupStandbyInstances`, `GroupTerminatingInstances`, `GroupTotalInstances` | `list(string)` |
[
"GroupMinSize",
"GroupMaxSize",
"GroupDesiredCapacity",
"GroupInServiceInstances",
"GroupPendingInstances",
"GroupStandbyInstances",
"GroupTerminatingInstances",
"GroupTotalInstances"
]
| no | 63 | | [environment](#input\_environment) | ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no | 64 | | [force\_delete](#input\_force\_delete) | Allows deleting the autoscaling group without waiting for all instances in the pool to terminate. You can force an autoscaling group to delete even if it's in the process of scaling a resource. Normally, Terraform drains all the instances before deleting the group. This bypasses that behavior and potentially leaves resources dangling | `bool` | `false` | no | 65 | | [health\_check\_grace\_period](#input\_health\_check\_grace\_period) | Time (in seconds) after instance comes into service before checking health | `number` | `300` | no | 66 | | [health\_check\_type](#input\_health\_check\_type) | Controls how health checking is done. Valid values are `EC2` or `ELB` | `string` | `"EC2"` | no | 67 | | [iam\_instance\_profile\_name](#input\_iam\_instance\_profile\_name) | The IAM instance profile name to associate with launched instances | `string` | `""` | no | 68 | | [id\_length\_limit](#input\_id\_length\_limit) | Limit `id` to this many characters (minimum 6).
Set to `0` for unlimited length.
Set to `null` for keep the existing setting, which defaults to `0`.
Does not affect `id_full`. | `number` | `null` | no | 69 | | [image\_id](#input\_image\_id) | The EC2 image ID to launch | `string` | `""` | no | 70 | | [instance\_initiated\_shutdown\_behavior](#input\_instance\_initiated\_shutdown\_behavior) | Shutdown behavior for the instances. Can be `stop` or `terminate` | `string` | `"terminate"` | no | 71 | | [instance\_market\_options](#input\_instance\_market\_options) | The market (purchasing) option for the instances |
object({
market_type = string
spot_options = object({
block_duration_minutes = number
instance_interruption_behavior = string
max_price = number
spot_instance_type = string
valid_until = string
})
})
| `null` | no | 72 | | [instance\_refresh](#input\_instance\_refresh) | The instance refresh definition |
object({
strategy = string
preferences = object({
instance_warmup = number
min_healthy_percentage = number
})
triggers = list(string)
})
| `null` | no | 73 | | [instance\_type](#input\_instance\_type) | Instance type to launch | `string` | n/a | yes | 74 | | [key\_name](#input\_key\_name) | The SSH key name that should be used for the instance | `string` | `""` | no | 75 | | [label\_key\_case](#input\_label\_key\_case) | Controls the letter case of the `tags` keys (label names) for tags generated by this module.
Does not affect keys of tags passed in via the `tags` input.
Possible values: `lower`, `title`, `upper`.
Default value: `title`. | `string` | `null` | no | 76 | | [label\_order](#input\_label\_order) | The order in which the labels (ID elements) appear in the `id`.
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present. | `list(string)` | `null` | no | 77 | | [label\_value\_case](#input\_label\_value\_case) | Controls the letter case of ID elements (labels) as included in `id`,
set as tag values, and output by this module individually.
Does not affect values of tags passed in via the `tags` input.
Possible values: `lower`, `title`, `upper` and `none` (no transformation).
Set this to `title` and set `delimiter` to `""` to yield Pascal Case IDs.
Default value: `lower`. | `string` | `null` | no | 78 | | [labels\_as\_tags](#input\_labels\_as\_tags) | Set of labels (ID elements) to include as tags in the `tags` output.
Default is to include all labels.
Tags with empty values will not be included in the `tags` output.
Set to `[]` to suppress all generated tags.
**Notes:**
The value of the `name` tag, if included, will be the `id`, not the `name`.
Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be
changed in later chained modules. Attempts to change it will be silently ignored. | `set(string)` |
[
"default"
]
| no | 79 | | [launch\_template\_version](#input\_launch\_template\_version) | Launch template version. Can be version number, `$Latest` or `$Default` | `string` | `"$Latest"` | no | 80 | | [load\_balancers](#input\_load\_balancers) | A list of elastic load balancer names to add to the autoscaling group names. Only valid for classic load balancers. For ALBs, use `target_group_arns` instead | `list(string)` | `[]` | no | 81 | | [max\_instance\_lifetime](#input\_max\_instance\_lifetime) | The maximum amount of time, in seconds, that an instance can be in service, values must be either equal to 0 or between 604800 and 31536000 seconds | `number` | `null` | no | 82 | | [max\_size](#input\_max\_size) | The maximum size of the autoscale group | `number` | n/a | yes | 83 | | [metadata\_http\_endpoint\_enabled](#input\_metadata\_http\_endpoint\_enabled) | Set false to disable the Instance Metadata Service. | `bool` | `true` | no | 84 | | [metadata\_http\_protocol\_ipv6\_enabled](#input\_metadata\_http\_protocol\_ipv6\_enabled) | Set true to enable IPv6 in the launch template. | `bool` | `false` | no | 85 | | [metadata\_http\_put\_response\_hop\_limit](#input\_metadata\_http\_put\_response\_hop\_limit) | The desired HTTP PUT response hop limit (between 1 and 64) for Instance Metadata Service requests.
The default is `2` to support containerized workloads. | `number` | `2` | no | 86 | | [metadata\_http\_tokens\_required](#input\_metadata\_http\_tokens\_required) | Set true to require IMDS session tokens, disabling Instance Metadata Service Version 1. | `bool` | `true` | no | 87 | | [metadata\_instance\_metadata\_tags\_enabled](#input\_metadata\_instance\_metadata\_tags\_enabled) | Set true to enable metadata tags in the launch template. | `bool` | `false` | no | 88 | | [metrics\_granularity](#input\_metrics\_granularity) | The granularity to associate with the metrics to collect. The only valid value is 1Minute | `string` | `"1Minute"` | no | 89 | | [min\_elb\_capacity](#input\_min\_elb\_capacity) | Setting this causes Terraform to wait for this number of instances to show up healthy in the ELB only on creation. Updates will not wait on ELB instance number changes | `number` | `0` | no | 90 | | [min\_size](#input\_min\_size) | The minimum size of the autoscale group | `number` | n/a | yes | 91 | | [mixed\_instances\_policy](#input\_mixed\_instances\_policy) | policy to used mixed group of on demand/spot of differing types. Launch template is automatically generated. https://www.terraform.io/docs/providers/aws/r/autoscaling_group.html#mixed_instances_policy-1 |
object({
instances_distribution = object({
on_demand_allocation_strategy = string
on_demand_base_capacity = number
on_demand_percentage_above_base_capacity = number
spot_allocation_strategy = string
spot_instance_pools = number
spot_max_price = string
})
override = list(object({
instance_type = string
weighted_capacity = number
}))
})
| `null` | no | 92 | | [name](#input\_name) | ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.
This is the only ID element not also included as a `tag`.
The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input. | `string` | `null` | no | 93 | | [namespace](#input\_namespace) | ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique | `string` | `null` | no | 94 | | [placement](#input\_placement) | The placement specifications of the instances |
object({
affinity = string
availability_zone = string
group_name = string
host_id = string
tenancy = string
})
| `null` | no | 95 | | [placement\_group](#input\_placement\_group) | The name of the placement group into which you'll launch your instances, if any | `string` | `""` | no | 96 | | [protect\_from\_scale\_in](#input\_protect\_from\_scale\_in) | Allows setting instance protection. The autoscaling group will not select instances with this setting for terminination during scale in events | `bool` | `false` | no | 97 | | [regex\_replace\_chars](#input\_regex\_replace\_chars) | Terraform regular expression (regex) string.
Characters matching the regex will be removed from the ID elements.
If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no | 98 | | [scale\_down\_adjustment\_type](#input\_scale\_down\_adjustment\_type) | Specifies whether the adjustment is an absolute number or a percentage of the current capacity. Valid values are `ChangeInCapacity`, `ExactCapacity` and `PercentChangeInCapacity` | `string` | `"ChangeInCapacity"` | no | 99 | | [scale\_down\_cooldown\_seconds](#input\_scale\_down\_cooldown\_seconds) | The amount of time, in seconds, after a scaling activity completes and before the next scaling activity can start | `number` | `300` | no | 100 | | [scale\_down\_policy\_type](#input\_scale\_down\_policy\_type) | The scaling policy type. Currently only `SimpleScaling` is supported | `string` | `"SimpleScaling"` | no | 101 | | [scale\_down\_scaling\_adjustment](#input\_scale\_down\_scaling\_adjustment) | The number of instances by which to scale. `scale_down_scaling_adjustment` determines the interpretation of this number (e.g. as an absolute number or as a percentage of the existing Auto Scaling group size). A positive increment adds to the current capacity and a negative value removes from the current capacity | `number` | `-1` | no | 102 | | [scale\_up\_adjustment\_type](#input\_scale\_up\_adjustment\_type) | Specifies whether the adjustment is an absolute number or a percentage of the current capacity. Valid values are `ChangeInCapacity`, `ExactCapacity` and `PercentChangeInCapacity` | `string` | `"ChangeInCapacity"` | no | 103 | | [scale\_up\_cooldown\_seconds](#input\_scale\_up\_cooldown\_seconds) | The amount of time, in seconds, after a scaling activity completes and before the next scaling activity can start | `number` | `300` | no | 104 | | [scale\_up\_policy\_type](#input\_scale\_up\_policy\_type) | The scaling policy type. Currently only `SimpleScaling` is supported | `string` | `"SimpleScaling"` | no | 105 | | [scale\_up\_scaling\_adjustment](#input\_scale\_up\_scaling\_adjustment) | The number of instances by which to scale. `scale_up_adjustment_type` determines the interpretation of this number (e.g. as an absolute number or as a percentage of the existing Auto Scaling group size). A positive increment adds to the current capacity and a negative value removes from the current capacity | `number` | `1` | no | 106 | | [security\_group\_ids](#input\_security\_group\_ids) | A list of associated security group IDs | `list(string)` | `[]` | no | 107 | | [service\_linked\_role\_arn](#input\_service\_linked\_role\_arn) | The ARN of the service-linked role that the ASG will use to call other AWS services | `string` | `""` | no | 108 | | [stage](#input\_stage) | ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no | 109 | | [subnet\_ids](#input\_subnet\_ids) | A list of subnet IDs to launch resources in | `list(string)` | n/a | yes | 110 | | [suspended\_processes](#input\_suspended\_processes) | A list of processes to suspend for the AutoScaling Group. The allowed values are `Launch`, `Terminate`, `HealthCheck`, `ReplaceUnhealthy`, `AZRebalance`, `AlarmNotification`, `ScheduledActions`, `AddToLoadBalancer`. Note that if you suspend either the `Launch` or `Terminate` process types, it can prevent your autoscaling group from functioning properly. | `list(string)` | `[]` | no | 111 | | [tag\_specifications\_resource\_types](#input\_tag\_specifications\_resource\_types) | List of tag specification resource types to tag. Valid values are instance, volume, elastic-gpu and spot-instances-request. | `set(string)` |
[
"instance",
"volume"
]
| no | 112 | | [tags](#input\_tags) | Additional tags (e.g. `{'BusinessUnit': 'XYZ'}`).
Neither the tag keys nor the tag values will be modified by this module. | `map(string)` | `{}` | no | 113 | | [target\_group\_arns](#input\_target\_group\_arns) | A list of aws\_alb\_target\_group ARNs, for use with Application Load Balancing | `list(string)` | `[]` | no | 114 | | [tenant](#input\_tenant) | ID element \_(Rarely used, not included by default)\_. A customer identifier, indicating who this instance of a resource is for | `string` | `null` | no | 115 | | [termination\_policies](#input\_termination\_policies) | A list of policies to decide how the instances in the auto scale group should be terminated. The allowed values are `OldestInstance`, `NewestInstance`, `OldestLaunchConfiguration`, `ClosestToNextInstanceHour`, `Default` | `list(string)` |
[
"Default"
]
| no | 116 | | [update\_default\_version](#input\_update\_default\_version) | Whether to update Default version of Launch template each update | `bool` | `false` | no | 117 | | [user\_data\_base64](#input\_user\_data\_base64) | The Base64-encoded user data to provide when launching the instances | `string` | `""` | no | 118 | | [wait\_for\_capacity\_timeout](#input\_wait\_for\_capacity\_timeout) | A maximum duration that Terraform should wait for ASG instances to be healthy before timing out. Setting this to '0' causes Terraform to skip all Capacity Waiting behavior | `string` | `"10m"` | no | 119 | | [wait\_for\_elb\_capacity](#input\_wait\_for\_elb\_capacity) | Setting this will cause Terraform to wait for exactly this number of healthy instances in all attached load balancers on both create and update operations. Takes precedence over `min_elb_capacity` behavior | `number` | `0` | no | 120 | | [warm\_pool](#input\_warm\_pool) | If this block is configured, add a Warm Pool to the specified Auto Scaling group. See [warm\_pool](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/autoscaling_group#warm_pool). |
object({
pool_state = string
min_size = number
max_group_prepared_capacity = number
})
| `null` | no | 121 | 122 | ## Outputs 123 | 124 | | Name | Description | 125 | |------|-------------| 126 | | [autoscaling\_group\_arn](#output\_autoscaling\_group\_arn) | ARN of the AutoScaling Group | 127 | | [autoscaling\_group\_default\_cooldown](#output\_autoscaling\_group\_default\_cooldown) | Time between a scaling activity and the succeeding scaling activity | 128 | | [autoscaling\_group\_desired\_capacity](#output\_autoscaling\_group\_desired\_capacity) | The number of Amazon EC2 instances that should be running in the group | 129 | | [autoscaling\_group\_health\_check\_grace\_period](#output\_autoscaling\_group\_health\_check\_grace\_period) | Time after instance comes into service before checking health | 130 | | [autoscaling\_group\_health\_check\_type](#output\_autoscaling\_group\_health\_check\_type) | `EC2` or `ELB`. Controls how health checking is done | 131 | | [autoscaling\_group\_id](#output\_autoscaling\_group\_id) | The AutoScaling Group id | 132 | | [autoscaling\_group\_max\_size](#output\_autoscaling\_group\_max\_size) | The maximum size of the autoscale group | 133 | | [autoscaling\_group\_min\_size](#output\_autoscaling\_group\_min\_size) | The minimum size of the autoscale group | 134 | | [autoscaling\_group\_name](#output\_autoscaling\_group\_name) | The AutoScaling Group name | 135 | | [autoscaling\_group\_tags](#output\_autoscaling\_group\_tags) | A list of tag settings associated with the AutoScaling Group | 136 | | [autoscaling\_policy\_scale\_down\_arn](#output\_autoscaling\_policy\_scale\_down\_arn) | ARN of the AutoScaling policy scale down | 137 | | [autoscaling\_policy\_scale\_up\_arn](#output\_autoscaling\_policy\_scale\_up\_arn) | ARN of the AutoScaling policy scale up | 138 | | [launch\_template\_arn](#output\_launch\_template\_arn) | The ARN of the launch template | 139 | | [launch\_template\_id](#output\_launch\_template\_id) | The ID of the launch template | 140 | 141 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # terraform-aws-ec2-autoscale-group [![Latest Release](https://img.shields.io/github/release/cloudposse/terraform-aws-ec2-autoscale-group.svg)](https://github.com/cloudposse/terraform-aws-ec2-autoscale-group/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com) 4 | 5 | 6 | [![README Header][readme_header_img]][readme_header_link] 7 | 8 | [![Cloud Posse][logo]](https://cpco.io/homepage) 9 | 10 | 30 | 31 | Terraform module to provision [Auto Scaling Group](https://www.terraform.io/docs/providers/aws/r/autoscaling_group.html) and [Launch Template](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-launch-templates.html) on AWS. 32 | 33 | The module also creates AutoScaling Policies and CloudWatch Metric Alarms to monitor CPU utilization on the EC2 instances and scale the number of instance in the AutoScaling Group up or down. 34 | If you don't want to use the provided functionality, or want to provide your own policies, disable it by setting the variable `autoscaling_policies_enabled` to `false`. 35 | 36 | At present, although you can set the created AutoScaling Policy type to any legal value, in practice [only `SimpleScaling` is supported](https://github.com/cloudposse/terraform-aws-ec2-autoscale-group/issues/55). 37 | To use a `StepScaling` or `TargetTrackingScaling` policy, create it yourself and then pass it in the `alarm_actions` field of `custom_alarms`. 38 | 39 | --- 40 | 41 | This project is part of our comprehensive ["SweetOps"](https://cpco.io/sweetops) approach towards DevOps. 42 | [][share_email] 43 | [][share_googleplus] 44 | [][share_facebook] 45 | [][share_reddit] 46 | [][share_linkedin] 47 | [][share_twitter] 48 | 49 | 50 | [![Terraform Open Source Modules](https://docs.cloudposse.com/images/terraform-open-source-modules.svg)][terraform_modules] 51 | 52 | 53 | 54 | It's 100% Open Source and licensed under the [APACHE2](LICENSE). 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | We literally have [*hundreds of terraform modules*][terraform_modules] that are Open Source and well-maintained. Check them out! 63 | 64 | 65 | 66 | 67 | 68 | 69 | ## Security & Compliance [](https://bridgecrew.io/) 70 | 71 | Security scanning is graciously provided by Bridgecrew. Bridgecrew is the leading fully hosted, cloud-native solution providing continuous Terraform security and compliance. 72 | 73 | | Benchmark | Description | 74 | |--------|---------------| 75 | | [![Infrastructure Security](https://www.bridgecrew.cloud/badges/github/cloudposse/terraform-aws-ec2-autoscale-group/general)](https://www.bridgecrew.cloud/link/badge?vcs=github&fullRepo=cloudposse%2Fterraform-aws-ec2-autoscale-group&benchmark=INFRASTRUCTURE+SECURITY) | Infrastructure Security Compliance | 76 | | [![CIS KUBERNETES](https://www.bridgecrew.cloud/badges/github/cloudposse/terraform-aws-ec2-autoscale-group/cis_kubernetes)](https://www.bridgecrew.cloud/link/badge?vcs=github&fullRepo=cloudposse%2Fterraform-aws-ec2-autoscale-group&benchmark=CIS+KUBERNETES+V1.5) | Center for Internet Security, KUBERNETES Compliance | 77 | | [![CIS AWS](https://www.bridgecrew.cloud/badges/github/cloudposse/terraform-aws-ec2-autoscale-group/cis_aws)](https://www.bridgecrew.cloud/link/badge?vcs=github&fullRepo=cloudposse%2Fterraform-aws-ec2-autoscale-group&benchmark=CIS+AWS+V1.2) | Center for Internet Security, AWS Compliance | 78 | | [![CIS AZURE](https://www.bridgecrew.cloud/badges/github/cloudposse/terraform-aws-ec2-autoscale-group/cis_azure)](https://www.bridgecrew.cloud/link/badge?vcs=github&fullRepo=cloudposse%2Fterraform-aws-ec2-autoscale-group&benchmark=CIS+AZURE+V1.1) | Center for Internet Security, AZURE Compliance | 79 | | [![PCI-DSS](https://www.bridgecrew.cloud/badges/github/cloudposse/terraform-aws-ec2-autoscale-group/pci)](https://www.bridgecrew.cloud/link/badge?vcs=github&fullRepo=cloudposse%2Fterraform-aws-ec2-autoscale-group&benchmark=PCI-DSS+V3.2) | Payment Card Industry Data Security Standards Compliance | 80 | | [![NIST-800-53](https://www.bridgecrew.cloud/badges/github/cloudposse/terraform-aws-ec2-autoscale-group/nist)](https://www.bridgecrew.cloud/link/badge?vcs=github&fullRepo=cloudposse%2Fterraform-aws-ec2-autoscale-group&benchmark=NIST-800-53) | National Institute of Standards and Technology Compliance | 81 | | [![ISO27001](https://www.bridgecrew.cloud/badges/github/cloudposse/terraform-aws-ec2-autoscale-group/iso)](https://www.bridgecrew.cloud/link/badge?vcs=github&fullRepo=cloudposse%2Fterraform-aws-ec2-autoscale-group&benchmark=ISO27001) | Information Security Management System, ISO/IEC 27001 Compliance | 82 | | [![SOC2](https://www.bridgecrew.cloud/badges/github/cloudposse/terraform-aws-ec2-autoscale-group/soc2)](https://www.bridgecrew.cloud/link/badge?vcs=github&fullRepo=cloudposse%2Fterraform-aws-ec2-autoscale-group&benchmark=SOC2)| Service Organization Control 2 Compliance | 83 | | [![CIS GCP](https://www.bridgecrew.cloud/badges/github/cloudposse/terraform-aws-ec2-autoscale-group/cis_gcp)](https://www.bridgecrew.cloud/link/badge?vcs=github&fullRepo=cloudposse%2Fterraform-aws-ec2-autoscale-group&benchmark=CIS+GCP+V1.1) | Center for Internet Security, GCP Compliance | 84 | | [![HIPAA](https://www.bridgecrew.cloud/badges/github/cloudposse/terraform-aws-ec2-autoscale-group/hipaa)](https://www.bridgecrew.cloud/link/badge?vcs=github&fullRepo=cloudposse%2Fterraform-aws-ec2-autoscale-group&benchmark=HIPAA) | Health Insurance Portability and Accountability Compliance | 85 | 86 | 87 | 88 | ## Usage 89 | 90 | 91 | **IMPORTANT:** We do not pin modules to versions in our examples because of the 92 | difficulty of keeping the versions in the documentation in sync with the latest released versions. 93 | We highly recommend that in your code you pin the version to the exact version you are 94 | using so that your infrastructure remains stable, and update versions in a 95 | systematic way so that they do not catch you by surprise. 96 | 97 | Also, because of a bug in the Terraform registry ([hashicorp/terraform#21417](https://github.com/hashicorp/terraform/issues/21417)), 98 | the registry shows many of our inputs as required when in fact they are optional. 99 | The table below correctly indicates which inputs are required. 100 | 101 | 102 | 103 | ```hcl 104 | locals { 105 | userdata = <<-USERDATA 106 | #!/bin/bash 107 | cat <<"__EOF__" > /home/ec2-user/.ssh/config 108 | Host * 109 | StrictHostKeyChecking no 110 | __EOF__ 111 | chmod 600 /home/ec2-user/.ssh/config 112 | chown ec2-user:ec2-user /home/ec2-user/.ssh/config 113 | USERDATA 114 | } 115 | 116 | module "autoscale_group" { 117 | source = "cloudposse/ec2-autoscale-group/aws" 118 | # Cloud Posse recommends pinning every module to a specific version 119 | # version = "x.x.x" 120 | 121 | namespace = var.namespace 122 | stage = var.stage 123 | environment = var.environment 124 | name = var.name 125 | 126 | image_id = "ami-08cab282f9979fc7a" 127 | instance_type = "t2.small" 128 | security_group_ids = ["sg-xxxxxxxx"] 129 | subnet_ids = ["subnet-xxxxxxxx", "subnet-yyyyyyyy", "subnet-zzzzzzzz"] 130 | health_check_type = "EC2" 131 | min_size = 2 132 | max_size = 3 133 | wait_for_capacity_timeout = "5m" 134 | associate_public_ip_address = true 135 | user_data_base64 = base64encode(local.userdata) 136 | 137 | # All inputs to `block_device_mappings` have to be defined 138 | block_device_mappings = [ 139 | { 140 | device_name = "/dev/sda1" 141 | no_device = "false" 142 | virtual_name = "root" 143 | ebs = { 144 | encrypted = true 145 | volume_size = 200 146 | delete_on_termination = true 147 | iops = null 148 | kms_key_id = null 149 | snapshot_id = null 150 | volume_type = "standard" 151 | } 152 | } 153 | ] 154 | 155 | tags = { 156 | Tier = "1" 157 | KubernetesCluster = "us-west-2.testing.cloudposse.co" 158 | } 159 | 160 | # Auto-scaling policies and CloudWatch metric alarms 161 | autoscaling_policies_enabled = true 162 | cpu_utilization_high_threshold_percent = "70" 163 | cpu_utilization_low_threshold_percent = "20" 164 | } 165 | ``` 166 | 167 | To enable custom_alerts the map needs to be defined like so : 168 | ```hlc 169 | alarms = { 170 | alb_scale_up = { 171 | alarm_name = "${module.default_label.id}-alb-target-response-time-for-scale-up" 172 | comparison_operator = "GreaterThanThreshold" 173 | evaluation_periods = var.alb_target_group_alarms_evaluation_periods 174 | metric_name = "TargetResponseTime" 175 | namespace = "AWS/ApplicationELB" 176 | period = var.alb_target_group_alarms_period 177 | statistic = "Average" 178 | threshold = var.alb_target_group_alarms_response_time_max_threshold 179 | dimensions_name = "LoadBalancer" 180 | dimensions_target = data.alb.arn_suffix 181 | treat_missing_data = "missing" 182 | ok_actions = var.alb_target_group_alarms_ok_actions 183 | insufficient_data_actions = var.alb_target_group_alarms_insufficient_data_actions 184 | alarm_description = "ALB Target response time is over ${var.alb_target_group_alarms_response_time_max_threshold} for more than ${var.alb_target_group_alarms_period}" 185 | alarm_actions = [module.autoscaling.scale_up_policy_arn] 186 | } 187 | } 188 | ``` 189 | All those keys are required to be there so if the alarm you are setting does not requiere one or more keys you can just set to empty but do not remove the keys otherwise you could get a weird merge error due to the maps being of different sizes. 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | ## Makefile Targets 198 | ```text 199 | Available targets: 200 | 201 | help Help screen 202 | help/all Display help for all targets 203 | help/short This help short screen 204 | lint Lint terraform code 205 | 206 | ``` 207 | 208 | 209 | ## Requirements 210 | 211 | | Name | Version | 212 | |------|---------| 213 | | [terraform](#requirement\_terraform) | >= 0.13 | 214 | | [aws](#requirement\_aws) | >= 2.0 | 215 | 216 | ## Providers 217 | 218 | | Name | Version | 219 | |------|---------| 220 | | [aws](#provider\_aws) | >= 2.0 | 221 | 222 | ## Modules 223 | 224 | | Name | Source | Version | 225 | |------|--------|---------| 226 | | [this](#module\_this) | cloudposse/label/null | 0.25.0 | 227 | 228 | ## Resources 229 | 230 | | Name | Type | 231 | |------|------| 232 | | [aws_autoscaling_group.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/autoscaling_group) | resource | 233 | | [aws_autoscaling_policy.scale_down](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/autoscaling_policy) | resource | 234 | | [aws_autoscaling_policy.scale_up](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/autoscaling_policy) | resource | 235 | | [aws_cloudwatch_metric_alarm.all_alarms](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_metric_alarm) | resource | 236 | | [aws_launch_template.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/launch_template) | resource | 237 | 238 | ## Inputs 239 | 240 | | Name | Description | Type | Default | Required | 241 | |------|-------------|------|---------|:--------:| 242 | | [additional\_tag\_map](#input\_additional\_tag\_map) | Additional key-value pairs to add to each map in `tags_as_list_of_maps`. Not added to `tags` or `id`.
This is for some rare cases where resources want additional configuration of tags
and therefore take a list of maps with tag key, value, and additional configuration. | `map(string)` | `{}` | no | 243 | | [associate\_public\_ip\_address](#input\_associate\_public\_ip\_address) | Associate a public IP address with an instance in a VPC | `bool` | `false` | no | 244 | | [attributes](#input\_attributes) | ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`,
in the order they appear in the list. New attributes are appended to the
end of the list. The elements of the list are joined by the `delimiter`
and treated as a single ID element. | `list(string)` | `[]` | no | 245 | | [autoscaling\_policies\_enabled](#input\_autoscaling\_policies\_enabled) | Whether to create `aws_autoscaling_policy` and `aws_cloudwatch_metric_alarm` resources to control Auto Scaling | `bool` | `true` | no | 246 | | [block\_device\_mappings](#input\_block\_device\_mappings) | Specify volumes to attach to the instance besides the volumes specified by the AMI |
list(object({
device_name = string
no_device = bool
virtual_name = string
ebs = object({
delete_on_termination = bool
encrypted = bool
iops = number
kms_key_id = string
snapshot_id = string
volume_size = number
volume_type = string
})
}))
| `[]` | no | 247 | | [capacity\_rebalance](#input\_capacity\_rebalance) | Indicates whether capacity rebalance is enabled. Otherwise, capacity rebalance is disabled. | `bool` | `false` | no | 248 | | [context](#input\_context) | Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as `null` to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional\_tag\_map, which are merged. | `any` |
{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"descriptor_formats": {},
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_key_case": null,
"label_order": [],
"label_value_case": null,
"labels_as_tags": [
"unset"
],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {},
"tenant": null
}
| no | 249 | | [cpu\_utilization\_high\_evaluation\_periods](#input\_cpu\_utilization\_high\_evaluation\_periods) | The number of periods over which data is compared to the specified threshold | `number` | `2` | no | 250 | | [cpu\_utilization\_high\_period\_seconds](#input\_cpu\_utilization\_high\_period\_seconds) | The period in seconds over which the specified statistic is applied | `number` | `300` | no | 251 | | [cpu\_utilization\_high\_statistic](#input\_cpu\_utilization\_high\_statistic) | The statistic to apply to the alarm's associated metric. Either of the following is supported: `SampleCount`, `Average`, `Sum`, `Minimum`, `Maximum` | `string` | `"Average"` | no | 252 | | [cpu\_utilization\_high\_threshold\_percent](#input\_cpu\_utilization\_high\_threshold\_percent) | The value against which the specified statistic is compared | `number` | `90` | no | 253 | | [cpu\_utilization\_low\_evaluation\_periods](#input\_cpu\_utilization\_low\_evaluation\_periods) | The number of periods over which data is compared to the specified threshold | `number` | `2` | no | 254 | | [cpu\_utilization\_low\_period\_seconds](#input\_cpu\_utilization\_low\_period\_seconds) | The period in seconds over which the specified statistic is applied | `number` | `300` | no | 255 | | [cpu\_utilization\_low\_statistic](#input\_cpu\_utilization\_low\_statistic) | The statistic to apply to the alarm's associated metric. Either of the following is supported: `SampleCount`, `Average`, `Sum`, `Minimum`, `Maximum` | `string` | `"Average"` | no | 256 | | [cpu\_utilization\_low\_threshold\_percent](#input\_cpu\_utilization\_low\_threshold\_percent) | The value against which the specified statistic is compared | `number` | `10` | no | 257 | | [credit\_specification](#input\_credit\_specification) | Customize the credit specification of the instances |
object({
cpu_credits = string
})
| `null` | no | 258 | | [custom\_alarms](#input\_custom\_alarms) | Map of custom CloudWatch alarms configurations |
map(object({
alarm_name = string
comparison_operator = string
evaluation_periods = string
metric_name = string
namespace = string
period = string
statistic = string
threshold = string
treat_missing_data = string
ok_actions = list(string)
insufficient_data_actions = list(string)
dimensions_name = string
dimensions_target = string
alarm_description = string
alarm_actions = list(string)
}))
| `{}` | no | 259 | | [default\_alarms\_enabled](#input\_default\_alarms\_enabled) | Enable or disable cpu and memory Cloudwatch alarms | `bool` | `true` | no | 260 | | [default\_cooldown](#input\_default\_cooldown) | The amount of time, in seconds, after a scaling activity completes before another scaling activity can start | `number` | `300` | no | 261 | | [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no | 262 | | [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map.
Map of maps. Keys are names of descriptors. Values are maps of the form
`{
format = string
labels = list(string)
}`
(Type is `any` so the map values can later be enhanced to provide additional options.)
`format` is a Terraform format string to be passed to the `format()` function.
`labels` is a list of labels, in order, to pass to `format()` function.
Label values will be normalized before being passed to `format()` so they will be
identical to how they appear in `id`.
Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no | 263 | | [desired\_capacity](#input\_desired\_capacity) | The number of Amazon EC2 instances that should be running in the group, if not set will use `min_size` as value | `number` | `null` | no | 264 | | [disable\_api\_termination](#input\_disable\_api\_termination) | If `true`, enables EC2 Instance Termination Protection | `bool` | `false` | no | 265 | | [ebs\_optimized](#input\_ebs\_optimized) | If true, the launched EC2 instance will be EBS-optimized | `bool` | `false` | no | 266 | | [elastic\_gpu\_specifications](#input\_elastic\_gpu\_specifications) | Specifications of Elastic GPU to attach to the instances |
object({
type = string
})
| `null` | no | 267 | | [enable\_monitoring](#input\_enable\_monitoring) | Enable/disable detailed monitoring | `bool` | `true` | no | 268 | | [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no | 269 | | [enabled\_metrics](#input\_enabled\_metrics) | A list of metrics to collect. The allowed values are `GroupMinSize`, `GroupMaxSize`, `GroupDesiredCapacity`, `GroupInServiceInstances`, `GroupPendingInstances`, `GroupStandbyInstances`, `GroupTerminatingInstances`, `GroupTotalInstances` | `list(string)` |
[
"GroupMinSize",
"GroupMaxSize",
"GroupDesiredCapacity",
"GroupInServiceInstances",
"GroupPendingInstances",
"GroupStandbyInstances",
"GroupTerminatingInstances",
"GroupTotalInstances"
]
| no | 270 | | [environment](#input\_environment) | ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no | 271 | | [force\_delete](#input\_force\_delete) | Allows deleting the autoscaling group without waiting for all instances in the pool to terminate. You can force an autoscaling group to delete even if it's in the process of scaling a resource. Normally, Terraform drains all the instances before deleting the group. This bypasses that behavior and potentially leaves resources dangling | `bool` | `false` | no | 272 | | [health\_check\_grace\_period](#input\_health\_check\_grace\_period) | Time (in seconds) after instance comes into service before checking health | `number` | `300` | no | 273 | | [health\_check\_type](#input\_health\_check\_type) | Controls how health checking is done. Valid values are `EC2` or `ELB` | `string` | `"EC2"` | no | 274 | | [iam\_instance\_profile\_name](#input\_iam\_instance\_profile\_name) | The IAM instance profile name to associate with launched instances | `string` | `""` | no | 275 | | [id\_length\_limit](#input\_id\_length\_limit) | Limit `id` to this many characters (minimum 6).
Set to `0` for unlimited length.
Set to `null` for keep the existing setting, which defaults to `0`.
Does not affect `id_full`. | `number` | `null` | no | 276 | | [image\_id](#input\_image\_id) | The EC2 image ID to launch | `string` | `""` | no | 277 | | [instance\_initiated\_shutdown\_behavior](#input\_instance\_initiated\_shutdown\_behavior) | Shutdown behavior for the instances. Can be `stop` or `terminate` | `string` | `"terminate"` | no | 278 | | [instance\_market\_options](#input\_instance\_market\_options) | The market (purchasing) option for the instances |
object({
market_type = string
spot_options = object({
block_duration_minutes = number
instance_interruption_behavior = string
max_price = number
spot_instance_type = string
valid_until = string
})
})
| `null` | no | 279 | | [instance\_refresh](#input\_instance\_refresh) | The instance refresh definition |
object({
strategy = string
preferences = object({
instance_warmup = number
min_healthy_percentage = number
})
triggers = list(string)
})
| `null` | no | 280 | | [instance\_type](#input\_instance\_type) | Instance type to launch | `string` | n/a | yes | 281 | | [key\_name](#input\_key\_name) | The SSH key name that should be used for the instance | `string` | `""` | no | 282 | | [label\_key\_case](#input\_label\_key\_case) | Controls the letter case of the `tags` keys (label names) for tags generated by this module.
Does not affect keys of tags passed in via the `tags` input.
Possible values: `lower`, `title`, `upper`.
Default value: `title`. | `string` | `null` | no | 283 | | [label\_order](#input\_label\_order) | The order in which the labels (ID elements) appear in the `id`.
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present. | `list(string)` | `null` | no | 284 | | [label\_value\_case](#input\_label\_value\_case) | Controls the letter case of ID elements (labels) as included in `id`,
set as tag values, and output by this module individually.
Does not affect values of tags passed in via the `tags` input.
Possible values: `lower`, `title`, `upper` and `none` (no transformation).
Set this to `title` and set `delimiter` to `""` to yield Pascal Case IDs.
Default value: `lower`. | `string` | `null` | no | 285 | | [labels\_as\_tags](#input\_labels\_as\_tags) | Set of labels (ID elements) to include as tags in the `tags` output.
Default is to include all labels.
Tags with empty values will not be included in the `tags` output.
Set to `[]` to suppress all generated tags.
**Notes:**
The value of the `name` tag, if included, will be the `id`, not the `name`.
Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be
changed in later chained modules. Attempts to change it will be silently ignored. | `set(string)` |
[
"default"
]
| no | 286 | | [launch\_template\_version](#input\_launch\_template\_version) | Launch template version. Can be version number, `$Latest` or `$Default` | `string` | `"$Latest"` | no | 287 | | [load\_balancers](#input\_load\_balancers) | A list of elastic load balancer names to add to the autoscaling group names. Only valid for classic load balancers. For ALBs, use `target_group_arns` instead | `list(string)` | `[]` | no | 288 | | [max\_instance\_lifetime](#input\_max\_instance\_lifetime) | The maximum amount of time, in seconds, that an instance can be in service, values must be either equal to 0 or between 604800 and 31536000 seconds | `number` | `null` | no | 289 | | [max\_size](#input\_max\_size) | The maximum size of the autoscale group | `number` | n/a | yes | 290 | | [metadata\_http\_endpoint\_enabled](#input\_metadata\_http\_endpoint\_enabled) | Set false to disable the Instance Metadata Service. | `bool` | `true` | no | 291 | | [metadata\_http\_protocol\_ipv6\_enabled](#input\_metadata\_http\_protocol\_ipv6\_enabled) | Set true to enable IPv6 in the launch template. | `bool` | `false` | no | 292 | | [metadata\_http\_put\_response\_hop\_limit](#input\_metadata\_http\_put\_response\_hop\_limit) | The desired HTTP PUT response hop limit (between 1 and 64) for Instance Metadata Service requests.
The default is `2` to support containerized workloads. | `number` | `2` | no | 293 | | [metadata\_http\_tokens\_required](#input\_metadata\_http\_tokens\_required) | Set true to require IMDS session tokens, disabling Instance Metadata Service Version 1. | `bool` | `true` | no | 294 | | [metadata\_instance\_metadata\_tags\_enabled](#input\_metadata\_instance\_metadata\_tags\_enabled) | Set true to enable metadata tags in the launch template. | `bool` | `false` | no | 295 | | [metrics\_granularity](#input\_metrics\_granularity) | The granularity to associate with the metrics to collect. The only valid value is 1Minute | `string` | `"1Minute"` | no | 296 | | [min\_elb\_capacity](#input\_min\_elb\_capacity) | Setting this causes Terraform to wait for this number of instances to show up healthy in the ELB only on creation. Updates will not wait on ELB instance number changes | `number` | `0` | no | 297 | | [min\_size](#input\_min\_size) | The minimum size of the autoscale group | `number` | n/a | yes | 298 | | [mixed\_instances\_policy](#input\_mixed\_instances\_policy) | policy to used mixed group of on demand/spot of differing types. Launch template is automatically generated. https://www.terraform.io/docs/providers/aws/r/autoscaling_group.html#mixed_instances_policy-1 |
object({
instances_distribution = object({
on_demand_allocation_strategy = string
on_demand_base_capacity = number
on_demand_percentage_above_base_capacity = number
spot_allocation_strategy = string
spot_instance_pools = number
spot_max_price = string
})
override = list(object({
instance_type = string
weighted_capacity = number
}))
})
| `null` | no | 299 | | [name](#input\_name) | ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.
This is the only ID element not also included as a `tag`.
The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input. | `string` | `null` | no | 300 | | [namespace](#input\_namespace) | ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique | `string` | `null` | no | 301 | | [placement](#input\_placement) | The placement specifications of the instances |
object({
affinity = string
availability_zone = string
group_name = string
host_id = string
tenancy = string
})
| `null` | no | 302 | | [placement\_group](#input\_placement\_group) | The name of the placement group into which you'll launch your instances, if any | `string` | `""` | no | 303 | | [protect\_from\_scale\_in](#input\_protect\_from\_scale\_in) | Allows setting instance protection. The autoscaling group will not select instances with this setting for terminination during scale in events | `bool` | `false` | no | 304 | | [regex\_replace\_chars](#input\_regex\_replace\_chars) | Terraform regular expression (regex) string.
Characters matching the regex will be removed from the ID elements.
If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no | 305 | | [scale\_down\_adjustment\_type](#input\_scale\_down\_adjustment\_type) | Specifies whether the adjustment is an absolute number or a percentage of the current capacity. Valid values are `ChangeInCapacity`, `ExactCapacity` and `PercentChangeInCapacity` | `string` | `"ChangeInCapacity"` | no | 306 | | [scale\_down\_cooldown\_seconds](#input\_scale\_down\_cooldown\_seconds) | The amount of time, in seconds, after a scaling activity completes and before the next scaling activity can start | `number` | `300` | no | 307 | | [scale\_down\_policy\_type](#input\_scale\_down\_policy\_type) | The scaling policy type. Currently only `SimpleScaling` is supported | `string` | `"SimpleScaling"` | no | 308 | | [scale\_down\_scaling\_adjustment](#input\_scale\_down\_scaling\_adjustment) | The number of instances by which to scale. `scale_down_scaling_adjustment` determines the interpretation of this number (e.g. as an absolute number or as a percentage of the existing Auto Scaling group size). A positive increment adds to the current capacity and a negative value removes from the current capacity | `number` | `-1` | no | 309 | | [scale\_up\_adjustment\_type](#input\_scale\_up\_adjustment\_type) | Specifies whether the adjustment is an absolute number or a percentage of the current capacity. Valid values are `ChangeInCapacity`, `ExactCapacity` and `PercentChangeInCapacity` | `string` | `"ChangeInCapacity"` | no | 310 | | [scale\_up\_cooldown\_seconds](#input\_scale\_up\_cooldown\_seconds) | The amount of time, in seconds, after a scaling activity completes and before the next scaling activity can start | `number` | `300` | no | 311 | | [scale\_up\_policy\_type](#input\_scale\_up\_policy\_type) | The scaling policy type. Currently only `SimpleScaling` is supported | `string` | `"SimpleScaling"` | no | 312 | | [scale\_up\_scaling\_adjustment](#input\_scale\_up\_scaling\_adjustment) | The number of instances by which to scale. `scale_up_adjustment_type` determines the interpretation of this number (e.g. as an absolute number or as a percentage of the existing Auto Scaling group size). A positive increment adds to the current capacity and a negative value removes from the current capacity | `number` | `1` | no | 313 | | [security\_group\_ids](#input\_security\_group\_ids) | A list of associated security group IDs | `list(string)` | `[]` | no | 314 | | [service\_linked\_role\_arn](#input\_service\_linked\_role\_arn) | The ARN of the service-linked role that the ASG will use to call other AWS services | `string` | `""` | no | 315 | | [stage](#input\_stage) | ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no | 316 | | [subnet\_ids](#input\_subnet\_ids) | A list of subnet IDs to launch resources in | `list(string)` | n/a | yes | 317 | | [suspended\_processes](#input\_suspended\_processes) | A list of processes to suspend for the AutoScaling Group. The allowed values are `Launch`, `Terminate`, `HealthCheck`, `ReplaceUnhealthy`, `AZRebalance`, `AlarmNotification`, `ScheduledActions`, `AddToLoadBalancer`. Note that if you suspend either the `Launch` or `Terminate` process types, it can prevent your autoscaling group from functioning properly. | `list(string)` | `[]` | no | 318 | | [tag\_specifications\_resource\_types](#input\_tag\_specifications\_resource\_types) | List of tag specification resource types to tag. Valid values are instance, volume, elastic-gpu and spot-instances-request. | `set(string)` |
[
"instance",
"volume"
]
| no | 319 | | [tags](#input\_tags) | Additional tags (e.g. `{'BusinessUnit': 'XYZ'}`).
Neither the tag keys nor the tag values will be modified by this module. | `map(string)` | `{}` | no | 320 | | [target\_group\_arns](#input\_target\_group\_arns) | A list of aws\_alb\_target\_group ARNs, for use with Application Load Balancing | `list(string)` | `[]` | no | 321 | | [tenant](#input\_tenant) | ID element \_(Rarely used, not included by default)\_. A customer identifier, indicating who this instance of a resource is for | `string` | `null` | no | 322 | | [termination\_policies](#input\_termination\_policies) | A list of policies to decide how the instances in the auto scale group should be terminated. The allowed values are `OldestInstance`, `NewestInstance`, `OldestLaunchConfiguration`, `ClosestToNextInstanceHour`, `Default` | `list(string)` |
[
"Default"
]
| no | 323 | | [update\_default\_version](#input\_update\_default\_version) | Whether to update Default version of Launch template each update | `bool` | `false` | no | 324 | | [user\_data\_base64](#input\_user\_data\_base64) | The Base64-encoded user data to provide when launching the instances | `string` | `""` | no | 325 | | [wait\_for\_capacity\_timeout](#input\_wait\_for\_capacity\_timeout) | A maximum duration that Terraform should wait for ASG instances to be healthy before timing out. Setting this to '0' causes Terraform to skip all Capacity Waiting behavior | `string` | `"10m"` | no | 326 | | [wait\_for\_elb\_capacity](#input\_wait\_for\_elb\_capacity) | Setting this will cause Terraform to wait for exactly this number of healthy instances in all attached load balancers on both create and update operations. Takes precedence over `min_elb_capacity` behavior | `number` | `0` | no | 327 | | [warm\_pool](#input\_warm\_pool) | If this block is configured, add a Warm Pool to the specified Auto Scaling group. See [warm\_pool](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/autoscaling_group#warm_pool). |
object({
pool_state = string
min_size = number
max_group_prepared_capacity = number
})
| `null` | no | 328 | 329 | ## Outputs 330 | 331 | | Name | Description | 332 | |------|-------------| 333 | | [autoscaling\_group\_arn](#output\_autoscaling\_group\_arn) | ARN of the AutoScaling Group | 334 | | [autoscaling\_group\_default\_cooldown](#output\_autoscaling\_group\_default\_cooldown) | Time between a scaling activity and the succeeding scaling activity | 335 | | [autoscaling\_group\_desired\_capacity](#output\_autoscaling\_group\_desired\_capacity) | The number of Amazon EC2 instances that should be running in the group | 336 | | [autoscaling\_group\_health\_check\_grace\_period](#output\_autoscaling\_group\_health\_check\_grace\_period) | Time after instance comes into service before checking health | 337 | | [autoscaling\_group\_health\_check\_type](#output\_autoscaling\_group\_health\_check\_type) | `EC2` or `ELB`. Controls how health checking is done | 338 | | [autoscaling\_group\_id](#output\_autoscaling\_group\_id) | The AutoScaling Group id | 339 | | [autoscaling\_group\_max\_size](#output\_autoscaling\_group\_max\_size) | The maximum size of the autoscale group | 340 | | [autoscaling\_group\_min\_size](#output\_autoscaling\_group\_min\_size) | The minimum size of the autoscale group | 341 | | [autoscaling\_group\_name](#output\_autoscaling\_group\_name) | The AutoScaling Group name | 342 | | [autoscaling\_group\_tags](#output\_autoscaling\_group\_tags) | A list of tag settings associated with the AutoScaling Group | 343 | | [autoscaling\_policy\_scale\_down\_arn](#output\_autoscaling\_policy\_scale\_down\_arn) | ARN of the AutoScaling policy scale down | 344 | | [autoscaling\_policy\_scale\_up\_arn](#output\_autoscaling\_policy\_scale\_up\_arn) | ARN of the AutoScaling policy scale up | 345 | | [launch\_template\_arn](#output\_launch\_template\_arn) | The ARN of the launch template | 346 | | [launch\_template\_id](#output\_launch\_template\_id) | The ID of the launch template | 347 | 348 | 349 | 350 | 351 | ## Share the Love 352 | 353 | Like this project? Please give it a ★ on [our GitHub](https://github.com/cloudposse/terraform-aws-ec2-autoscale-group)! (it helps us **a lot**) 354 | 355 | Are you using this project or any of our other projects? Consider [leaving a testimonial][testimonial]. =) 356 | 357 | 358 | 359 | ## Related Projects 360 | 361 | Check out these related projects. 362 | 363 | - [terraform-aws-ec2-instance](https://github.com/cloudposse/terraform-aws-ec2-instance) - Terraform module for providing a general purpose EC2 instance 364 | - [terraform-aws-ec2-bastion-server](https://github.com/cloudposse/terraform-aws-ec2-bastion-server) - Terraform module to define a generic bastion host with parameterized user data 365 | - [terraform-aws-ec2-admin-server](https://github.com/cloudposse/terraform-aws-ec2-admin-server) - Terraform module for providing an EC2 instance capable of running admin tasks 366 | - [terraform-aws-ec2-instance-group](https://github.com/cloudposse/terraform-aws-ec2-instance-group) - Terraform module for provisioning multiple general purpose EC2 hosts for stateful applications 367 | - [terraform-aws-ec2-ami-snapshot](https://github.com/cloudposse/terraform-aws-ec2-ami-snapshot) - Terraform module to easily generate AMI snapshots to create replica instances 368 | 369 | ## Help 370 | 371 | **Got a question?** We got answers. 372 | 373 | File a GitHub [issue](https://github.com/cloudposse/terraform-aws-ec2-autoscale-group/issues), send us an [email][email] or join our [Slack Community][slack]. 374 | 375 | [![README Commercial Support][readme_commercial_support_img]][readme_commercial_support_link] 376 | 377 | ## DevOps Accelerator for Startups 378 | 379 | 380 | We are a [**DevOps Accelerator**][commercial_support]. We'll help you build your cloud infrastructure from the ground up so you can own it. Then we'll show you how to operate it and stick around for as long as you need us. 381 | 382 | [![Learn More](https://img.shields.io/badge/learn%20more-success.svg?style=for-the-badge)][commercial_support] 383 | 384 | Work directly with our team of DevOps experts via email, slack, and video conferencing. 385 | 386 | We deliver 10x the value for a fraction of the cost of a full-time engineer. Our track record is not even funny. If you want things done right and you need it done FAST, then we're your best bet. 387 | 388 | - **Reference Architecture.** You'll get everything you need from the ground up built using 100% infrastructure as code. 389 | - **Release Engineering.** You'll have end-to-end CI/CD with unlimited staging environments. 390 | - **Site Reliability Engineering.** You'll have total visibility into your apps and microservices. 391 | - **Security Baseline.** You'll have built-in governance with accountability and audit logs for all changes. 392 | - **GitOps.** You'll be able to operate your infrastructure via Pull Requests. 393 | - **Training.** You'll receive hands-on training so your team can operate what we build. 394 | - **Questions.** You'll have a direct line of communication between our teams via a Shared Slack channel. 395 | - **Troubleshooting.** You'll get help to triage when things aren't working. 396 | - **Code Reviews.** You'll receive constructive feedback on Pull Requests. 397 | - **Bug Fixes.** We'll rapidly work with you to fix any bugs in our projects. 398 | 399 | ## Slack Community 400 | 401 | Join our [Open Source Community][slack] on Slack. It's **FREE** for everyone! Our "SweetOps" community is where you get to talk with others who share a similar vision for how to rollout and manage infrastructure. This is the best place to talk shop, ask questions, solicit feedback, and work together as a community to build totally *sweet* infrastructure. 402 | 403 | ## Discourse Forums 404 | 405 | Participate in our [Discourse Forums][discourse]. Here you'll find answers to commonly asked questions. Most questions will be related to the enormous number of projects we support on our GitHub. Come here to collaborate on answers, find solutions, and get ideas about the products and services we value. It only takes a minute to get started! Just sign in with SSO using your GitHub account. 406 | 407 | ## Newsletter 408 | 409 | Sign up for [our newsletter][newsletter] that covers everything on our technology radar. Receive updates on what we're up to on GitHub as well as awesome new projects we discover. 410 | 411 | ## Office Hours 412 | 413 | [Join us every Wednesday via Zoom][office_hours] for our weekly "Lunch & Learn" sessions. It's **FREE** for everyone! 414 | 415 | [![zoom](https://img.cloudposse.com/fit-in/200x200/https://cloudposse.com/wp-content/uploads/2019/08/Powered-by-Zoom.png")][office_hours] 416 | 417 | ## Contributing 418 | 419 | ### Bug Reports & Feature Requests 420 | 421 | Please use the [issue tracker](https://github.com/cloudposse/terraform-aws-ec2-autoscale-group/issues) to report any bugs or file feature requests. 422 | 423 | ### Developing 424 | 425 | If you are interested in being a contributor and want to get involved in developing this project or [help out](https://cpco.io/help-out) with our other projects, we would love to hear from you! Shoot us an [email][email]. 426 | 427 | In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow. 428 | 429 | 1. **Fork** the repo on GitHub 430 | 2. **Clone** the project to your own machine 431 | 3. **Commit** changes to your own branch 432 | 4. **Push** your work back up to your fork 433 | 5. Submit a **Pull Request** so that we can review your changes 434 | 435 | **NOTE:** Be sure to merge the latest changes from "upstream" before making a pull request! 436 | 437 | 438 | ## Copyright 439 | 440 | Copyright © 2017-2022 [Cloud Posse, LLC](https://cpco.io/copyright) 441 | 442 | 443 | 444 | ## License 445 | 446 | [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) 447 | 448 | See [LICENSE](LICENSE) for full details. 449 | 450 | ```text 451 | Licensed to the Apache Software Foundation (ASF) under one 452 | or more contributor license agreements. See the NOTICE file 453 | distributed with this work for additional information 454 | regarding copyright ownership. The ASF licenses this file 455 | to you under the Apache License, Version 2.0 (the 456 | "License"); you may not use this file except in compliance 457 | with the License. You may obtain a copy of the License at 458 | 459 | https://www.apache.org/licenses/LICENSE-2.0 460 | 461 | Unless required by applicable law or agreed to in writing, 462 | software distributed under the License is distributed on an 463 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 464 | KIND, either express or implied. See the License for the 465 | specific language governing permissions and limitations 466 | under the License. 467 | ``` 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | ## Trademarks 478 | 479 | All other trademarks referenced herein are the property of their respective owners. 480 | 481 | ## About 482 | 483 | This project is maintained and funded by [Cloud Posse, LLC][website]. Like it? Please let us know by [leaving a testimonial][testimonial]! 484 | 485 | [![Cloud Posse][logo]][website] 486 | 487 | We're a [DevOps Professional Services][hire] company based in Los Angeles, CA. We ❤️ [Open Source Software][we_love_open_source]. 488 | 489 | We offer [paid support][commercial_support] on all of our projects. 490 | 491 | Check out [our other projects][github], [follow us on twitter][twitter], [apply for a job][jobs], or [hire us][hire] to help with your cloud strategy and implementation. 492 | 493 | 494 | 495 | ### Contributors 496 | 497 | 498 | | [![Erik Osterman][osterman_avatar]][osterman_homepage]
[Erik Osterman][osterman_homepage] | [![Andriy Knysh][aknysh_avatar]][aknysh_homepage]
[Andriy Knysh][aknysh_homepage] | [![Igor Rodionov][goruha_avatar]][goruha_homepage]
[Igor Rodionov][goruha_homepage] | [![RB][nitrocode_avatar]][nitrocode_homepage]
[RB][nitrocode_homepage] | 499 | |---|---|---|---| 500 | 501 | 502 | [osterman_homepage]: https://github.com/osterman 503 | [osterman_avatar]: https://img.cloudposse.com/150x150/https://github.com/osterman.png 504 | [aknysh_homepage]: https://github.com/aknysh 505 | [aknysh_avatar]: https://img.cloudposse.com/150x150/https://github.com/aknysh.png 506 | [goruha_homepage]: https://github.com/goruha 507 | [goruha_avatar]: https://img.cloudposse.com/150x150/https://github.com/goruha.png 508 | [nitrocode_homepage]: https://github.com/nitrocode 509 | [nitrocode_avatar]: https://img.cloudposse.com/150x150/https://github.com/nitrocode.png 510 | 511 | [![README Footer][readme_footer_img]][readme_footer_link] 512 | [![Beacon][beacon]][website] 513 | 514 | [logo]: https://cloudposse.com/logo-300x69.svg 515 | [docs]: https://cpco.io/docs?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-ec2-autoscale-group&utm_content=docs 516 | [website]: https://cpco.io/homepage?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-ec2-autoscale-group&utm_content=website 517 | [github]: https://cpco.io/github?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-ec2-autoscale-group&utm_content=github 518 | [jobs]: https://cpco.io/jobs?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-ec2-autoscale-group&utm_content=jobs 519 | [hire]: https://cpco.io/hire?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-ec2-autoscale-group&utm_content=hire 520 | [slack]: https://cpco.io/slack?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-ec2-autoscale-group&utm_content=slack 521 | [linkedin]: https://cpco.io/linkedin?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-ec2-autoscale-group&utm_content=linkedin 522 | [twitter]: https://cpco.io/twitter?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-ec2-autoscale-group&utm_content=twitter 523 | [testimonial]: https://cpco.io/leave-testimonial?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-ec2-autoscale-group&utm_content=testimonial 524 | [office_hours]: https://cloudposse.com/office-hours?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-ec2-autoscale-group&utm_content=office_hours 525 | [newsletter]: https://cpco.io/newsletter?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-ec2-autoscale-group&utm_content=newsletter 526 | [discourse]: https://ask.sweetops.com/?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-ec2-autoscale-group&utm_content=discourse 527 | [email]: https://cpco.io/email?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-ec2-autoscale-group&utm_content=email 528 | [commercial_support]: https://cpco.io/commercial-support?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-ec2-autoscale-group&utm_content=commercial_support 529 | [we_love_open_source]: https://cpco.io/we-love-open-source?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-ec2-autoscale-group&utm_content=we_love_open_source 530 | [terraform_modules]: https://cpco.io/terraform-modules?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-ec2-autoscale-group&utm_content=terraform_modules 531 | [readme_header_img]: https://cloudposse.com/readme/header/img 532 | [readme_header_link]: https://cloudposse.com/readme/header/link?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-ec2-autoscale-group&utm_content=readme_header_link 533 | [readme_footer_img]: https://cloudposse.com/readme/footer/img 534 | [readme_footer_link]: https://cloudposse.com/readme/footer/link?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-ec2-autoscale-group&utm_content=readme_footer_link 535 | [readme_commercial_support_img]: https://cloudposse.com/readme/commercial-support/img 536 | [readme_commercial_support_link]: https://cloudposse.com/readme/commercial-support/link?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-ec2-autoscale-group&utm_content=readme_commercial_support_link 537 | [share_twitter]: https://twitter.com/intent/tweet/?text=terraform-aws-ec2-autoscale-group&url=https://github.com/cloudposse/terraform-aws-ec2-autoscale-group 538 | [share_linkedin]: https://www.linkedin.com/shareArticle?mini=true&title=terraform-aws-ec2-autoscale-group&url=https://github.com/cloudposse/terraform-aws-ec2-autoscale-group 539 | [share_reddit]: https://reddit.com/submit/?url=https://github.com/cloudposse/terraform-aws-ec2-autoscale-group 540 | [share_facebook]: https://facebook.com/sharer/sharer.php?u=https://github.com/cloudposse/terraform-aws-ec2-autoscale-group 541 | [share_googleplus]: https://plus.google.com/share?url=https://github.com/cloudposse/terraform-aws-ec2-autoscale-group 542 | [share_email]: mailto:?subject=terraform-aws-ec2-autoscale-group&body=https://github.com/cloudposse/terraform-aws-ec2-autoscale-group 543 | [beacon]: https://ga-beacon.cloudposse.com/UA-76589703-4/cloudposse/terraform-aws-ec2-autoscale-group?pixel&cs=github&cm=readme&an=terraform-aws-ec2-autoscale-group 544 | --------------------------------------------------------------------------------