├── test ├── .gitignore ├── src │ ├── .gitignore │ ├── utils.go │ ├── Makefile │ ├── examples_complete_test.go │ └── go.mod ├── Makefile.alpine └── Makefile ├── .github ├── ISSUE_TEMPLATE │ ├── question.md │ ├── config.yml │ ├── bug_report.md │ ├── feature_request.md │ ├── bug_report.yml │ └── feature_request.yml ├── mergify.yml ├── banner.png ├── workflows │ ├── release.yml │ ├── scheduled.yml │ ├── chatops.yml │ └── branch.yml ├── renovate.json ├── settings.yml ├── PULL_REQUEST_TEMPLATE.md └── CODEOWNERS ├── examples └── complete │ ├── providers.tf │ ├── versions.tf │ ├── outputs.tf │ ├── main.tf │ ├── fixtures.us-east-2.tfvars │ ├── variables.tf │ └── context.tf ├── versions.tf ├── .gitignore ├── atmos.yaml ├── .editorconfig ├── variables-deprecated.tf ├── outputs.tf ├── iam.tf ├── main.tf ├── variables.tf ├── README.yaml ├── context.tf ├── LICENSE └── README.md /test/.gitignore: -------------------------------------------------------------------------------- 1 | .test-harness 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.github/mergify.yml: -------------------------------------------------------------------------------- 1 | extends: .github 2 | -------------------------------------------------------------------------------- /test/src/.gitignore: -------------------------------------------------------------------------------- 1 | .gopath 2 | vendor/ 3 | -------------------------------------------------------------------------------- /examples/complete/providers.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = var.region 3 | } 4 | -------------------------------------------------------------------------------- /.github/banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudposse/terraform-aws-amplify-app/HEAD/.github/banner.png -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /versions.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = ">= 1.3.0" 3 | 4 | required_providers { 5 | aws = { 6 | source = "hashicorp/aws" 7 | version = ">= 4.0" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/complete/versions.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = ">= 1.3.0" 3 | 4 | required_providers { 5 | aws = { 6 | source = "hashicorp/aws" 7 | version = ">= 4.0" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: release 3 | on: 4 | release: 5 | types: 6 | - published 7 | 8 | permissions: 9 | id-token: write 10 | contents: write 11 | pull-requests: write 12 | 13 | jobs: 14 | terraform-module: 15 | uses: cloudposse/.github/.github/workflows/shared-release-branches.yml@main 16 | secrets: inherit 17 | -------------------------------------------------------------------------------- /.github/renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "config:base", 4 | ":preserveSemverRanges", 5 | ":rebaseStalePrs" 6 | ], 7 | "baseBranches": ["main"], 8 | "labels": ["auto-update"], 9 | "dependencyDashboardAutoclose": true, 10 | "enabledManagers": ["terraform"], 11 | "terraform": { 12 | "ignorePaths": ["**/context.tf"] 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /test/src/utils.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "github.com/gruntwork-io/terratest/modules/terraform" 5 | "github.com/stretchr/testify/assert" 6 | "os" 7 | "testing" 8 | ) 9 | 10 | func cleanup(t *testing.T, terraformOptions *terraform.Options, tempTestFolder string) { 11 | terraform.Destroy(t, terraformOptions) 12 | err := os.RemoveAll(tempTestFolder) 13 | assert.NoError(t, err) 14 | } 15 | -------------------------------------------------------------------------------- /.github/workflows/scheduled.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: scheduled 3 | on: 4 | workflow_dispatch: { } # Allows manually trigger this workflow 5 | schedule: 6 | - cron: "0 3 * * *" 7 | 8 | permissions: 9 | pull-requests: write 10 | id-token: write 11 | contents: write 12 | 13 | jobs: 14 | scheduled: 15 | uses: cloudposse/.github/.github/workflows/shared-terraform-scheduled.yml@main 16 | secrets: inherit 17 | -------------------------------------------------------------------------------- /.github/settings.yml: -------------------------------------------------------------------------------- 1 | # Upstream changes from _extends are only recognized when modifications are made to this file in the default branch. 2 | _extends: .github 3 | repository: 4 | name: terraform-aws-amplify-app 5 | description: Terraform module to provision AWS Amplify apps, backend environments, branches, domain associations, and webhooks 6 | homepage: https://cloudposse.com/accelerate 7 | topics: amplify, branch, domain, webhook 8 | 9 | 10 | -------------------------------------------------------------------------------- /.github/workflows/chatops.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: chatops 3 | on: 4 | issue_comment: 5 | types: [created] 6 | 7 | permissions: 8 | pull-requests: write 9 | id-token: write 10 | contents: write 11 | statuses: write 12 | 13 | jobs: 14 | test: 15 | uses: cloudposse/.github/.github/workflows/shared-terraform-chatops.yml@main 16 | if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, '/terratest') }} 17 | secrets: inherit 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Local .terraform directories 2 | **/.terraform 3 | **/.terraform.d 4 | 5 | # .tfstate files 6 | *.tfstate 7 | *.tfstate.* 8 | .terraform 9 | .terraform.tfstate.lock.info 10 | .terraform.lock.hcl 11 | 12 | **/.idea 13 | **/*.iml 14 | 15 | # Cloud Posse Build Harness https://github.com/cloudposse/build-harness 16 | **/.build-harness 17 | **/build-harness 18 | 19 | # Crash log files 20 | crash.log 21 | test.log 22 | 23 | # Editor backups 24 | *.orig 25 | *.draft 26 | *~ 27 | 28 | -------------------------------------------------------------------------------- /atmos.yaml: -------------------------------------------------------------------------------- 1 | # Atmos Configuration — powered by https://atmos.tools 2 | # 3 | # This configuration enables centralized, DRY, and consistent project scaffolding using Atmos. 4 | # 5 | # Included features: 6 | # - Organizational custom commands: https://atmos.tools/core-concepts/custom-commands 7 | # - Automated README generation: https://atmos.tools/cli/commands/docs/generate 8 | # 9 | 10 | # Import shared configuration used by all modules 11 | import: 12 | - https://raw.githubusercontent.com/cloudposse/.github/refs/heads/main/.github/atmos/terraform-module.yaml 13 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # Unix-style newlines with a newline ending every file 2 | [*] 3 | charset = utf-8 4 | end_of_line = lf 5 | indent_size = 2 6 | indent_style = space 7 | insert_final_newline = true 8 | trim_trailing_whitespace = true 9 | 10 | [*.{tf,tfvars}] 11 | indent_size = 2 12 | indent_style = space 13 | 14 | [*.md] 15 | max_line_length = 0 16 | trim_trailing_whitespace = false 17 | 18 | # Override for Makefile 19 | [{Makefile, makefile, GNUmakefile, Makefile.*}] 20 | tab_width = 2 21 | indent_style = tab 22 | indent_size = 4 23 | 24 | [COMMIT_EDITMSG] 25 | max_line_length = 0 26 | -------------------------------------------------------------------------------- /.github/workflows/branch.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Branch 3 | on: 4 | pull_request: 5 | branches: 6 | - main 7 | - release/** 8 | types: [opened, synchronize, reopened, labeled, unlabeled] 9 | push: 10 | branches: 11 | - main 12 | - release/v* 13 | paths-ignore: 14 | - '.github/**' 15 | - 'docs/**' 16 | - 'examples/**' 17 | - 'test/**' 18 | - 'README.md' 19 | 20 | permissions: {} 21 | 22 | jobs: 23 | terraform-module: 24 | uses: cloudposse/.github/.github/workflows/shared-terraform-module.yml@main 25 | secrets: inherit 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 | 3 | 7 | 8 | ## why 9 | 10 | 15 | 16 | ## references 17 | 18 | 22 | -------------------------------------------------------------------------------- /variables-deprecated.tf: -------------------------------------------------------------------------------- 1 | variable "domain_config" { 2 | type = object({ 3 | domain_name = string 4 | enable_auto_sub_domain = optional(bool, false) 5 | wait_for_verification = optional(bool, false) 6 | sub_domain = list(object({ 7 | branch_name = string 8 | prefix = string 9 | })) 10 | }) 11 | description = <<-EOT 12 | DEPRECATED: Use the `domains` variable instead. 13 | Amplify custom domain configuration. 14 | EOT 15 | default = null 16 | } 17 | 18 | locals { 19 | domain_config = local.enabled && var.domain_config != null ? { 20 | (var.domain_config.domain_name) = { 21 | enable_auto_sub_domain = lookup(var.domain_config, "enable_auto_sub_domain", false) 22 | wait_for_verification = lookup(var.domain_config, "wait_for_verification", false) 23 | sub_domain = var.domain_config.sub_domain 24 | } 25 | } : null 26 | } 27 | -------------------------------------------------------------------------------- /test/src/Makefile: -------------------------------------------------------------------------------- 1 | export TERRAFORM_VERSION ?= $(shell curl -s https://checkpoint-api.hashicorp.com/v1/check/terraform | jq -r -M '.current_version' | cut -d. -f1) 2 | 3 | .DEFAULT_GOAL : all 4 | .PHONY: all 5 | 6 | ## Default target 7 | all: test 8 | 9 | .PHONY : init 10 | ## Initialize tests 11 | init: 12 | @exit 0 13 | 14 | .PHONY : test 15 | ## Run tests 16 | test: init 17 | go mod download 18 | go test -v -timeout 20m 19 | 20 | ## Run tests in docker container 21 | docker/test: 22 | docker run --name terratest --rm -it -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_SESSION_TOKEN -e GITHUB_TOKEN \ 23 | -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" \ 24 | -v $(CURDIR)/../../:/module/ cloudposse/test-harness:latest -C /module/test/src test 25 | 26 | .PHONY : clean 27 | ## Clean up files 28 | clean: 29 | rm -rf ../../examples/complete/*.tfstate* 30 | -------------------------------------------------------------------------------- /examples/complete/outputs.tf: -------------------------------------------------------------------------------- 1 | output "name" { 2 | description = "Amplify App name" 3 | value = module.amplify_app.name 4 | } 5 | 6 | output "arn" { 7 | description = "Amplify App ARN" 8 | value = module.amplify_app.arn 9 | } 10 | 11 | output "default_domain" { 12 | description = "Amplify App domain (non-custom)" 13 | value = module.amplify_app.default_domain 14 | } 15 | 16 | output "backend_environments" { 17 | description = "Created backend environments" 18 | value = module.amplify_app.backend_environments 19 | } 20 | 21 | output "branch_names" { 22 | description = "The names of the created Amplify branches" 23 | value = module.amplify_app.branch_names 24 | } 25 | 26 | output "webhooks" { 27 | description = "Created webhooks" 28 | value = module.amplify_app.webhooks 29 | } 30 | 31 | output "domain_associations" { 32 | description = "Created domain associations" 33 | value = module.amplify_app.domain_associations 34 | } 35 | -------------------------------------------------------------------------------- /.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. -------------------------------------------------------------------------------- /outputs.tf: -------------------------------------------------------------------------------- 1 | output "name" { 2 | description = "Amplify App name" 3 | value = one(aws_amplify_app.default[*].name) 4 | } 5 | 6 | output "arn" { 7 | description = "Amplify App ARN" 8 | value = one(aws_amplify_app.default[*].arn) 9 | } 10 | 11 | output "id" { 12 | description = "Amplify App Id" 13 | value = one(aws_amplify_app.default[*].id) 14 | } 15 | 16 | output "default_domain" { 17 | description = "Amplify App domain (non-custom)" 18 | value = one(aws_amplify_app.default[*].default_domain) 19 | } 20 | 21 | output "backend_environments" { 22 | description = "Created backend environments" 23 | value = aws_amplify_backend_environment.default 24 | } 25 | 26 | output "branch_names" { 27 | description = "The names of the created Amplify branches" 28 | value = values(aws_amplify_branch.default)[*].branch_name 29 | } 30 | 31 | output "webhooks" { 32 | description = "Created webhooks" 33 | value = aws_amplify_webhook.default 34 | } 35 | 36 | output "domain_associations" { 37 | description = "Created domain associations" 38 | value = aws_amplify_domain_association.default 39 | } 40 | -------------------------------------------------------------------------------- /.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/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 module-pinning 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 validate 42 | examples/complete: deps 43 | $(call RUN_TESTS, ../$@) 44 | -------------------------------------------------------------------------------- /examples/complete/main.tf: -------------------------------------------------------------------------------- 1 | data "aws_ssm_parameter" "github_pat" { 2 | name = var.github_personal_access_token_secret_path 3 | with_decryption = true 4 | } 5 | 6 | locals { 7 | prefix = one(var.attributes) 8 | domains = { for k, v in var.domains : join("-", [local.prefix, k]) => v } 9 | } 10 | 11 | module "amplify_app" { 12 | source = "../../" 13 | 14 | access_token = data.aws_ssm_parameter.github_pat.value 15 | description = var.description 16 | repository = var.repository 17 | platform = var.platform 18 | oauth_token = var.oauth_token 19 | auto_branch_creation_config = var.auto_branch_creation_config 20 | auto_branch_creation_patterns = var.auto_branch_creation_patterns 21 | basic_auth_credentials = var.basic_auth_credentials 22 | build_spec = var.build_spec 23 | enable_auto_branch_creation = var.enable_auto_branch_creation 24 | enable_basic_auth = var.enable_basic_auth 25 | enable_branch_auto_build = var.enable_branch_auto_build 26 | enable_branch_auto_deletion = var.enable_branch_auto_deletion 27 | environment_variables = var.environment_variables 28 | custom_rules = var.custom_rules 29 | custom_headers = var.custom_headers 30 | iam_service_role_enabled = var.iam_service_role_enabled 31 | iam_service_role_arn = var.iam_service_role_arn 32 | iam_service_role_actions = var.iam_service_role_actions 33 | environments = var.environments 34 | domains = local.domains 35 | 36 | context = module.this.context 37 | } 38 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | description: Create a report to help us improve 4 | labels: ["bug"] 5 | assignees: [""] 6 | body: 7 | - type: markdown 8 | attributes: 9 | value: | 10 | Found a bug? 11 | 12 | Please checkout our [Slack Community](https://slack.cloudposse.com) 13 | or visit our [Slack Archive](https://archive.sweetops.com/). 14 | 15 | [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com) 16 | 17 | - type: textarea 18 | id: concise-description 19 | attributes: 20 | label: Describe the Bug 21 | description: A clear and concise description of what the bug is. 22 | placeholder: What is the bug about? 23 | validations: 24 | required: true 25 | 26 | - type: textarea 27 | id: expected 28 | attributes: 29 | label: Expected Behavior 30 | description: A clear and concise description of what you expected. 31 | placeholder: What happened? 32 | validations: 33 | required: true 34 | 35 | - type: textarea 36 | id: reproduction-steps 37 | attributes: 38 | label: Steps to Reproduce 39 | description: Steps to reproduce the behavior. 40 | placeholder: How do we reproduce it? 41 | validations: 42 | required: true 43 | 44 | - type: textarea 45 | id: screenshots 46 | attributes: 47 | label: Screenshots 48 | description: If applicable, add screenshots or logs to help explain. 49 | validations: 50 | required: false 51 | 52 | - type: textarea 53 | id: environment 54 | attributes: 55 | label: Environment 56 | description: Anything that will help us triage the bug. 57 | placeholder: | 58 | - OS: [e.g. Linux, OSX, WSL, etc] 59 | - Version [e.g. 10.15] 60 | - Module version 61 | - Terraform version 62 | validations: 63 | required: false 64 | 65 | - type: textarea 66 | id: additional 67 | attributes: 68 | label: Additional Context 69 | description: | 70 | Add any other context about the problem here. 71 | validations: 72 | required: false 73 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature Request 3 | description: Suggest an idea for this project 4 | labels: ["feature request"] 5 | assignees: [""] 6 | body: 7 | - type: markdown 8 | attributes: 9 | value: | 10 | Have a question? 11 | 12 | Please checkout our [Slack Community](https://slack.cloudposse.com) 13 | or visit our [Slack Archive](https://archive.sweetops.com/). 14 | 15 | [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com) 16 | 17 | - type: textarea 18 | id: concise-description 19 | attributes: 20 | label: Describe the Feature 21 | description: A clear and concise description of what the feature is. 22 | placeholder: What is the feature about? 23 | validations: 24 | required: true 25 | 26 | - type: textarea 27 | id: expected 28 | attributes: 29 | label: Expected Behavior 30 | description: A clear and concise description of what you expected. 31 | placeholder: What happened? 32 | validations: 33 | required: true 34 | 35 | - type: textarea 36 | id: use-case 37 | attributes: 38 | label: Use Case 39 | description: | 40 | Is your feature request related to a problem/challenge you are trying 41 | to solve? 42 | 43 | Please provide some additional context of why this feature or 44 | capability will be valuable. 45 | validations: 46 | required: true 47 | 48 | - type: textarea 49 | id: ideal-solution 50 | attributes: 51 | label: Describe Ideal Solution 52 | description: A clear and concise description of what you want to happen. 53 | validations: 54 | required: true 55 | 56 | - type: textarea 57 | id: alternatives-considered 58 | attributes: 59 | label: Alternatives Considered 60 | description: Explain alternative solutions or features considered. 61 | validations: 62 | required: false 63 | 64 | - type: textarea 65 | id: additional 66 | attributes: 67 | label: Additional Context 68 | description: | 69 | Add any other context about the problem here. 70 | validations: 71 | required: false 72 | -------------------------------------------------------------------------------- /test/src/examples_complete_test.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "regexp" 5 | "strings" 6 | "testing" 7 | 8 | "github.com/gruntwork-io/terratest/modules/random" 9 | "github.com/gruntwork-io/terratest/modules/terraform" 10 | testStructure "github.com/gruntwork-io/terratest/modules/test-structure" 11 | "github.com/stretchr/testify/assert" 12 | "k8s.io/apimachinery/pkg/util/runtime" 13 | ) 14 | 15 | // Test the Terraform module in examples/complete using Terratest. 16 | func TestExamplesComplete(t *testing.T) { 17 | t.Parallel() 18 | randID := strings.ToLower(random.UniqueId()) 19 | attributes := []string{randID} 20 | 21 | rootFolder := "../../" 22 | terraformFolderRelativeToRoot := "examples/complete" 23 | varFiles := []string{"fixtures.us-east-2.tfvars"} 24 | 25 | tempTestFolder := testStructure.CopyTerraformFolderToTemp(t, rootFolder, terraformFolderRelativeToRoot) 26 | 27 | terraformOptions := &terraform.Options{ 28 | // The path to where our Terraform code is located 29 | TerraformDir: tempTestFolder, 30 | Upgrade: true, 31 | // Variables to pass to our Terraform code using -var-file options 32 | VarFiles: varFiles, 33 | Vars: map[string]interface{}{ 34 | "attributes": attributes, 35 | }, 36 | } 37 | 38 | // At the end of the test, run `terraform destroy` to clean up any resources that were created 39 | defer cleanup(t, terraformOptions, tempTestFolder) 40 | 41 | // If Go runtime crushes, run `terraform destroy` to clean up any resources that were created 42 | defer runtime.HandleCrash(func(i interface{}) { 43 | cleanup(t, terraformOptions, tempTestFolder) 44 | }) 45 | 46 | // This will run `terraform init` and `terraform apply` and fail the test if there are any errors 47 | terraform.InitAndApply(t, terraformOptions) 48 | 49 | // Run `terraform output` to get the value of an output variable 50 | name := terraform.Output(t, terraformOptions, "name") 51 | // Verify we're getting back the outputs we expect 52 | assert.Equal(t, "eg-ue2-test-amplify-"+randID, name) 53 | } 54 | 55 | func TestExamplesCompleteDisabled(t *testing.T) { 56 | t.Parallel() 57 | randID := strings.ToLower(random.UniqueId()) 58 | attributes := []string{randID} 59 | 60 | rootFolder := "../../" 61 | terraformFolderRelativeToRoot := "examples/complete" 62 | varFiles := []string{"fixtures.us-east-2.tfvars"} 63 | 64 | tempTestFolder := testStructure.CopyTerraformFolderToTemp(t, rootFolder, terraformFolderRelativeToRoot) 65 | 66 | terraformOptions := &terraform.Options{ 67 | // The path to where our Terraform code is located 68 | TerraformDir: tempTestFolder, 69 | Upgrade: true, 70 | // Variables to pass to our Terraform code using -var-file options 71 | VarFiles: varFiles, 72 | Vars: map[string]interface{}{ 73 | "attributes": attributes, 74 | "enabled": false, 75 | }, 76 | } 77 | 78 | // At the end of the test, run `terraform destroy` to clean up any resources that were created 79 | defer cleanup(t, terraformOptions, tempTestFolder) 80 | 81 | // This will run `terraform init` and `terraform apply` and fail the test if there are any errors 82 | results := terraform.InitAndApply(t, terraformOptions) 83 | 84 | // Should complete successfully without creating or changing any resources. 85 | // Extract the "Resources:" section of the output to make the error message more readable. 86 | re := regexp.MustCompile(`Resources: [^.]+\.`) 87 | match := re.FindString(results) 88 | assert.Equal(t, "Resources: 0 added, 0 changed, 0 destroyed.", match, "Re-applying the same configuration should not change any resources") 89 | } 90 | -------------------------------------------------------------------------------- /examples/complete/fixtures.us-east-2.tfvars: -------------------------------------------------------------------------------- 1 | region = "us-east-2" 2 | 3 | namespace = "eg" 4 | 5 | environment = "ue2" 6 | 7 | stage = "test" 8 | 9 | name = "amplify" 10 | 11 | # https://docs.aws.amazon.com/amplify/latest/userguide/getting-started.html 12 | # The GitHub PAT needs to have the scope `admin:repo_hook` 13 | # Refer to "Setting up the Amplify GitHub App for AWS CloudFormation, CLI, and SDK deployments" 14 | # in https://docs.aws.amazon.com/amplify/latest/userguide/setting-up-GitHub-access.html 15 | github_personal_access_token_secret_path = "/cpco-amplify-app-test-github-token" 16 | 17 | platform = "WEB" 18 | 19 | repository = "https://github.com/cloudposse-tests/amplify" 20 | 21 | iam_service_role_enabled = true 22 | 23 | # https://docs.aws.amazon.com/amplify/latest/userguide/ssr-CloudWatch-logs.html 24 | iam_service_role_actions = [ 25 | "logs:CreateLogStream", 26 | "logs:CreateLogGroup", 27 | "logs:DescribeLogGroups", 28 | "logs:PutLogEvents" 29 | ] 30 | 31 | enable_auto_branch_creation = false 32 | 33 | enable_branch_auto_build = true 34 | 35 | enable_branch_auto_deletion = true 36 | 37 | enable_basic_auth = false 38 | 39 | auto_branch_creation_patterns = [ 40 | "*", 41 | "*/**" 42 | ] 43 | 44 | auto_branch_creation_config = { 45 | # Enable auto build for the created branches 46 | enable_auto_build = true 47 | } 48 | 49 | # The build spec for React 50 | build_spec = <<-EOT 51 | version: 1 52 | frontend: 53 | phases: 54 | preBuild: 55 | commands: 56 | - yarn install 57 | build: 58 | commands: 59 | - yarn run build 60 | artifacts: 61 | baseDirectory: build 62 | files: 63 | - '**/*' 64 | cache: 65 | paths: 66 | - node_modules/**/* 67 | EOT 68 | 69 | custom_rules = [ 70 | { 71 | source = "/<*>" 72 | status = "404" 73 | target = "/index.html" 74 | } 75 | ] 76 | 77 | # Custom header, HTST to always block HTTP and always redirect to HTTPS 78 | custom_headers = <<-EOT 79 | customHeaders: 80 | - pattern: '**' 81 | headers: 82 | - key: 'Strict-Transport-Security' 83 | value: 'max-age=31536000; includeSubDomains' 84 | EOT 85 | 86 | environment_variables = { 87 | ENV = "test" 88 | } 89 | 90 | environments = { 91 | main = { 92 | branch_name = "main" 93 | enable_auto_build = true 94 | backend_enabled = false 95 | enable_performance_mode = true 96 | enable_pull_request_preview = false 97 | framework = "React" 98 | stage = "PRODUCTION" 99 | } 100 | dev = { 101 | branch_name = "dev" 102 | enable_auto_build = true 103 | backend_enabled = false 104 | enable_performance_mode = false 105 | enable_pull_request_preview = true 106 | framework = "React" 107 | stage = "DEVELOPMENT" 108 | } 109 | } 110 | 111 | domains = { 112 | "test.net" = { 113 | enable_auto_sub_domain = true 114 | wait_for_verification = false 115 | sub_domain = [ 116 | { 117 | branch_name = "main" 118 | prefix = "" 119 | }, 120 | { 121 | branch_name = "dev" 122 | prefix = "dev" 123 | } 124 | ] 125 | } 126 | "test.io" = { 127 | enable_auto_sub_domain = true 128 | wait_for_verification = false 129 | sub_domain = [ 130 | { 131 | branch_name = "main" 132 | prefix = "" 133 | }, 134 | { 135 | branch_name = "dev" 136 | prefix = "dev" 137 | } 138 | ] 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /iam.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | create_iam_role = local.enabled && var.iam_service_role_enabled && length(var.iam_service_role_arn) == 0 3 | 4 | iam_service_role_arn = try(local.create_iam_role ? module.role.arn : var.iam_service_role_arn[0], null) 5 | 6 | # source: https://github.com/aws-amplify/amplify-cli/issues/4322#issuecomment-455022473 7 | default_actions = [ 8 | "appsync:*", 9 | "amplify:*", 10 | "apigateway:POST", 11 | "apigateway:DELETE", 12 | "apigateway:PATCH", 13 | "apigateway:PUT", 14 | "cloudformation:CreateStack", 15 | "cloudformation:CreateStackSet", 16 | "cloudformation:DeleteStack", 17 | "cloudformation:DeleteStackSet", 18 | "cloudformation:DescribeStackEvents", 19 | "cloudformation:DescribeStackResource", 20 | "cloudformation:DescribeStackResources", 21 | "cloudformation:DescribeStackSet", 22 | "cloudformation:DescribeStackSetOperation", 23 | "cloudformation:DescribeStacks", 24 | "cloudformation:UpdateStack", 25 | "cloudformation:UpdateStackSet", 26 | "cloudfront:CreateCloudFrontOriginAccessIdentity", 27 | "cloudfront:CreateDistribution", 28 | "cloudfront:DeleteCloudFrontOriginAccessIdentity", 29 | "cloudfront:DeleteDistribution", 30 | "cloudfront:GetCloudFrontOriginAccessIdentity", 31 | "cloudfront:GetCloudFrontOriginAccessIdentityConfig", 32 | "cloudfront:GetDistribution", 33 | "cloudfront:GetDistributionConfig", 34 | "cloudfront:TagResource", 35 | "cloudfront:UntagResource", 36 | "cloudfront:UpdateCloudFrontOriginAccessIdentity", 37 | "cloudfront:UpdateDistribution", 38 | "cognito-identity:CreateIdentityPool", 39 | "cognito-identity:DeleteIdentityPool", 40 | "cognito-identity:DescribeIdentity", 41 | "cognito-identity:DescribeIdentityPool", 42 | "cognito-identity:SetIdentityPoolRoles", 43 | "cognito-identity:UpdateIdentityPool", 44 | "cognito-idp:CreateUserPool", 45 | "cognito-idp:CreateUserPoolClient", 46 | "cognito-idp:DeleteUserPool", 47 | "cognito-idp:DeleteUserPoolClient", 48 | "cognito-idp:DescribeUserPool", 49 | "cognito-idp:UpdateUserPool", 50 | "cognito-idp:UpdateUserPoolClient", 51 | "dynamodb:CreateTable", 52 | "dynamodb:DeleteItem", 53 | "dynamodb:DeleteTable", 54 | "dynamodb:DescribeTable", 55 | "dynamodb:PutItem", 56 | "dynamodb:UpdateItem", 57 | "dynamodb:UpdateTable", 58 | "iam:CreateRole", 59 | "iam:DeleteRole", 60 | "iam:DeleteRolePolicy", 61 | "iam:GetRole", 62 | "iam:GetUser", 63 | "iam:PassRole", 64 | "iam:PutRolePolicy", 65 | "iam:UpdateRole", 66 | "lambda:AddPermission", 67 | "lambda:CreateFunction", 68 | "lambda:DeleteFunction", 69 | "lambda:GetFunction", 70 | "lambda:GetFunctionConfiguration", 71 | "lambda:InvokeAsync", 72 | "lambda:InvokeFunction", 73 | "lambda:RemovePermission", 74 | "lambda:UpdateFunctionCode", 75 | "lambda:UpdateFunctionConfiguration", 76 | "s3:*", 77 | "logs:CreateLogStream", 78 | "logs:CreateLogGroup", 79 | "logs:DescribeLogGroups", 80 | "logs:PutLogEvents" 81 | ] 82 | 83 | actions = length(var.iam_service_role_actions) > 0 ? var.iam_service_role_actions : local.default_actions 84 | } 85 | 86 | data "aws_iam_policy_document" "default" { 87 | count = local.create_iam_role ? 1 : 0 88 | 89 | statement { 90 | sid = "AmplifyAccess" 91 | effect = "Allow" 92 | resources = ["*"] 93 | actions = local.actions 94 | } 95 | } 96 | 97 | module "role" { 98 | source = "cloudposse/iam-role/aws" 99 | version = "0.18.0" 100 | 101 | enabled = local.create_iam_role 102 | 103 | policy_description = "IAM policy for Amplify to perform actions on AWS resources" 104 | role_description = "IAM role with permissions for Amplify to perform actions on AWS resources" 105 | 106 | principals = { 107 | # AWS = ["arn:aws:iam::123456789012:role/workers"] 108 | Service = ["amplify.amazonaws.com"] 109 | } 110 | 111 | policy_documents = [ 112 | one(data.aws_iam_policy_document.default[*].json) 113 | ] 114 | 115 | context = module.this.context 116 | } 117 | -------------------------------------------------------------------------------- /test/src/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/cloudposse/terraform-aws-amplify-app 2 | 3 | go 1.24 4 | 5 | toolchain go1.24.0 6 | 7 | require ( 8 | github.com/gruntwork-io/terratest v0.43.10 9 | github.com/stretchr/testify v1.8.4 10 | k8s.io/apimachinery v0.27.4 11 | ) 12 | 13 | require ( 14 | cloud.google.com/go v0.110.0 // indirect 15 | cloud.google.com/go/compute v1.19.1 // indirect 16 | cloud.google.com/go/compute/metadata v0.2.3 // indirect 17 | cloud.google.com/go/iam v0.13.0 // indirect 18 | cloud.google.com/go/storage v1.28.1 // indirect 19 | github.com/agext/levenshtein v1.2.3 // indirect 20 | github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect 21 | github.com/aws/aws-sdk-go v1.44.122 // indirect 22 | github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect 23 | github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc // indirect 24 | github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect 25 | github.com/davecgh/go-spew v1.1.1 // indirect 26 | github.com/emicklei/go-restful/v3 v3.9.0 // indirect 27 | github.com/go-errors/errors v1.0.2-0.20180813162953-d98b870cc4e0 // indirect 28 | github.com/go-logr/logr v1.2.3 // indirect 29 | github.com/go-openapi/jsonpointer v0.19.6 // indirect 30 | github.com/go-openapi/jsonreference v0.20.1 // indirect 31 | github.com/go-openapi/swag v0.22.3 // indirect 32 | github.com/go-sql-driver/mysql v1.4.1 // indirect 33 | github.com/gogo/protobuf v1.3.2 // indirect 34 | github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect 35 | github.com/golang/protobuf v1.5.3 // indirect 36 | github.com/google/gnostic v0.5.7-v3refs // indirect 37 | github.com/google/go-cmp v0.5.9 // indirect 38 | github.com/google/gofuzz v1.1.0 // indirect 39 | github.com/google/uuid v1.3.0 // indirect 40 | github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect 41 | github.com/googleapis/gax-go/v2 v2.7.1 // indirect 42 | github.com/gruntwork-io/go-commons v0.8.0 // indirect 43 | github.com/hashicorp/errwrap v1.0.0 // indirect 44 | github.com/hashicorp/go-cleanhttp v0.5.2 // indirect 45 | github.com/hashicorp/go-getter v1.7.5 // indirect 46 | github.com/hashicorp/go-multierror v1.1.0 // indirect 47 | github.com/hashicorp/go-safetemp v1.0.0 // indirect 48 | github.com/hashicorp/go-version v1.6.0 // indirect 49 | github.com/hashicorp/hcl/v2 v2.9.1 // indirect 50 | github.com/hashicorp/terraform-json v0.13.0 // indirect 51 | github.com/imdario/mergo v0.3.11 // indirect 52 | github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a // indirect 53 | github.com/jmespath/go-jmespath v0.4.0 // indirect 54 | github.com/josharian/intern v1.0.0 // indirect 55 | github.com/json-iterator/go v1.1.12 // indirect 56 | github.com/klauspost/compress v1.15.11 // indirect 57 | github.com/mailru/easyjson v0.7.7 // indirect 58 | github.com/mattn/go-zglob v0.0.2-0.20190814121620-e3c945676326 // indirect 59 | github.com/mitchellh/go-homedir v1.1.0 // indirect 60 | github.com/mitchellh/go-testing-interface v1.14.1 // indirect 61 | github.com/mitchellh/go-wordwrap v1.0.1 // indirect 62 | github.com/moby/spdystream v0.2.0 // indirect 63 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 64 | github.com/modern-go/reflect2 v1.0.2 // indirect 65 | github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect 66 | github.com/pmezard/go-difflib v1.0.0 // indirect 67 | github.com/pquerna/otp v1.2.0 // indirect 68 | github.com/russross/blackfriday/v2 v2.1.0 // indirect 69 | github.com/spf13/pflag v1.0.5 // indirect 70 | github.com/tmccombs/hcl2json v0.3.3 // indirect 71 | github.com/ulikunitz/xz v0.5.10 // indirect 72 | github.com/urfave/cli v1.22.2 // indirect 73 | github.com/zclconf/go-cty v1.9.1 // indirect 74 | go.opencensus.io v0.24.0 // indirect 75 | golang.org/x/crypto v0.17.0 // indirect 76 | golang.org/x/net v0.10.0 // indirect 77 | golang.org/x/oauth2 v0.7.0 // indirect 78 | golang.org/x/sys v0.15.0 // indirect 79 | golang.org/x/term v0.15.0 // indirect 80 | golang.org/x/text v0.14.0 // indirect 81 | golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect 82 | golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect 83 | google.golang.org/api v0.114.0 // indirect 84 | google.golang.org/appengine v1.6.7 // indirect 85 | google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect 86 | google.golang.org/grpc v1.56.3 // indirect 87 | google.golang.org/protobuf v1.33.0 // indirect 88 | gopkg.in/inf.v0 v0.9.1 // indirect 89 | gopkg.in/yaml.v2 v2.4.0 // indirect 90 | gopkg.in/yaml.v3 v3.0.1 // indirect 91 | k8s.io/api v0.27.2 // indirect 92 | k8s.io/client-go v0.27.2 // indirect 93 | k8s.io/klog/v2 v2.90.1 // indirect 94 | k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f // indirect 95 | k8s.io/utils v0.0.0-20230209194617-a36077c30491 // indirect 96 | sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect 97 | sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect 98 | sigs.k8s.io/yaml v1.3.0 // indirect 99 | ) 100 | -------------------------------------------------------------------------------- /main.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | enabled = module.this.enabled 3 | 4 | environments = { for k, v in var.environments : k => v if local.enabled } 5 | 6 | domains = merge(local.domain_config, { for k, v in var.domains : k => v if local.enabled }) 7 | } 8 | 9 | # https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/amplify_app 10 | resource "aws_amplify_app" "default" { 11 | count = local.enabled ? 1 : 0 12 | 13 | name = module.this.id 14 | description = var.description 15 | repository = var.repository 16 | platform = var.platform 17 | 18 | access_token = var.access_token 19 | oauth_token = var.oauth_token 20 | auto_branch_creation_patterns = var.auto_branch_creation_patterns 21 | basic_auth_credentials = var.basic_auth_credentials 22 | build_spec = var.build_spec 23 | enable_auto_branch_creation = var.enable_auto_branch_creation 24 | enable_branch_auto_deletion = var.enable_branch_auto_deletion 25 | enable_basic_auth = var.enable_basic_auth 26 | enable_branch_auto_build = var.enable_branch_auto_build 27 | environment_variables = var.environment_variables 28 | custom_headers = var.custom_headers 29 | 30 | iam_service_role_arn = local.iam_service_role_arn 31 | 32 | dynamic "custom_rule" { 33 | for_each = var.custom_rules 34 | 35 | content { 36 | condition = lookup(custom_rule.value, "condition", null) 37 | source = custom_rule.value.source 38 | status = lookup(custom_rule.value, "status", null) 39 | target = custom_rule.value.target 40 | } 41 | } 42 | 43 | dynamic "auto_branch_creation_config" { 44 | for_each = var.auto_branch_creation_config != null ? [true] : [] 45 | 46 | content { 47 | basic_auth_credentials = lookup(var.auto_branch_creation_config, "basic_auth_credentials", null) 48 | build_spec = lookup(var.auto_branch_creation_config, "build_spec", null) 49 | enable_auto_build = lookup(var.auto_branch_creation_config, "enable_auto_build", null) 50 | enable_basic_auth = lookup(var.auto_branch_creation_config, "enable_basic_auth", null) 51 | enable_performance_mode = lookup(var.auto_branch_creation_config, "enable_performance_mode", null) 52 | enable_pull_request_preview = lookup(var.auto_branch_creation_config, "enable_pull_request_preview", null) 53 | environment_variables = lookup(var.auto_branch_creation_config, "environment_variables", null) 54 | framework = lookup(var.auto_branch_creation_config, "framework", null) 55 | pull_request_environment_name = lookup(var.auto_branch_creation_config, "pull_request_environment_name", null) 56 | stage = lookup(var.auto_branch_creation_config, "stage", null) 57 | } 58 | } 59 | 60 | tags = module.this.tags 61 | } 62 | 63 | # https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/amplify_backend_environment 64 | resource "aws_amplify_backend_environment" "default" { 65 | for_each = { for k, v in local.environments : k => v if lookup(v, "backend_enabled", null) != null && lookup(v, "backend_enabled", false) } 66 | 67 | app_id = one(aws_amplify_app.default[*].id) 68 | environment_name = lookup(each.value, "environment_name", each.key) 69 | deployment_artifacts = lookup(each.value, "deployment_artifacts", null) 70 | stack_name = lookup(each.value, "stack_name", null) 71 | } 72 | 73 | # https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/amplify_branch 74 | resource "aws_amplify_branch" "default" { 75 | for_each = local.environments 76 | 77 | app_id = one(aws_amplify_app.default[*].id) 78 | 79 | backend_environment_arn = lookup(each.value, "backend_enabled", false) ? aws_amplify_backend_environment.default[each.key].arn : null 80 | 81 | basic_auth_credentials = lookup(each.value, "basic_auth_credentials", null) 82 | branch_name = lookup(each.value, "branch_name", each.key) 83 | display_name = lookup(each.value, "display_name", each.key) 84 | description = lookup(each.value, "description", null) 85 | enable_auto_build = lookup(each.value, "enable_auto_build", null) 86 | enable_basic_auth = lookup(each.value, "enable_basic_auth", null) 87 | enable_notification = lookup(each.value, "enable_notification ", null) 88 | enable_performance_mode = lookup(each.value, "enable_performance_mode", null) 89 | enable_pull_request_preview = lookup(each.value, "enable_pull_request_preview", null) 90 | environment_variables = lookup(each.value, "environment_variables", {}) 91 | framework = lookup(each.value, "framework", null) 92 | pull_request_environment_name = lookup(each.value, "pull_request_environment_name", null) 93 | stage = lookup(each.value, "stage", null) 94 | ttl = lookup(each.value, "ttl", null) 95 | 96 | tags = module.this.tags 97 | } 98 | 99 | # https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/amplify_domain_association 100 | resource "aws_amplify_domain_association" "default" { 101 | for_each = local.domains 102 | 103 | app_id = one(aws_amplify_app.default[*].id) 104 | domain_name = each.key 105 | enable_auto_sub_domain = lookup(each.value, "enable_auto_sub_domain", null) 106 | wait_for_verification = lookup(each.value, "wait_for_verification", null) 107 | 108 | dynamic "sub_domain" { 109 | for_each = lookup(each.value, "sub_domain") 110 | 111 | content { 112 | branch_name = aws_amplify_branch.default[sub_domain.value.branch_name].branch_name 113 | prefix = sub_domain.value.prefix 114 | } 115 | } 116 | } 117 | 118 | # https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/amplify_webhook 119 | resource "aws_amplify_webhook" "default" { 120 | for_each = { for k, v in local.environments : k => v if lookup(v, "webhook_enabled", false) } 121 | 122 | app_id = one(aws_amplify_app.default[*].id) 123 | branch_name = aws_amplify_branch.default[lookup(each.value, "branch_name", each.key)].branch_name 124 | description = format("trigger-%s", aws_amplify_branch.default[lookup(each.value, "branch_name", each.key)].branch_name) 125 | 126 | # NOTE: We trigger the webhook via local-exec so as to kick off the first build on creation of Amplify App 127 | provisioner "local-exec" { 128 | command = "curl -X POST -d {} '${aws_amplify_webhook.default[each.key].url}&operation=startbuild' -H 'Content-Type:application/json'" 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /examples/complete/variables.tf: -------------------------------------------------------------------------------- 1 | variable "region" { 2 | type = string 3 | description = "AWS region" 4 | nullable = false 5 | } 6 | 7 | variable "github_personal_access_token_secret_path" { 8 | description = "Path to the GitHub personal access token in AWS Parameter Store" 9 | type = string 10 | nullable = false 11 | } 12 | 13 | variable "description" { 14 | type = string 15 | description = "The description for the Amplify app" 16 | default = null 17 | } 18 | 19 | variable "repository" { 20 | type = string 21 | description = "The repository for the Amplify app" 22 | default = null 23 | } 24 | 25 | variable "platform" { 26 | type = string 27 | description = "The platform or framework for the Amplify app" 28 | default = "WEB" 29 | } 30 | 31 | variable "oauth_token" { 32 | type = string 33 | description = <<-EOT 34 | The OAuth token for a third-party source control system for the Amplify app. 35 | The OAuth token is used to create a webhook and a read-only deploy key. 36 | The OAuth token is not stored. 37 | EOT 38 | default = null 39 | sensitive = true 40 | } 41 | 42 | variable "auto_branch_creation_config" { 43 | type = object({ 44 | basic_auth_credentials = optional(string) 45 | build_spec = optional(string) 46 | enable_auto_build = optional(bool) 47 | enable_basic_auth = optional(bool) 48 | enable_performance_mode = optional(bool) 49 | enable_pull_request_preview = optional(bool) 50 | environment_variables = optional(map(string)) 51 | framework = optional(string) 52 | pull_request_environment_name = optional(string) 53 | stage = optional(string) 54 | }) 55 | description = "The automated branch creation configuration for the Amplify app" 56 | default = null 57 | } 58 | 59 | variable "auto_branch_creation_patterns" { 60 | type = list(string) 61 | description = "The automated branch creation glob patterns for the Amplify app" 62 | default = [] 63 | } 64 | 65 | variable "basic_auth_credentials" { 66 | type = string 67 | description = "The credentials for basic authorization for the Amplify app" 68 | default = null 69 | } 70 | 71 | variable "build_spec" { 72 | type = string 73 | description = <<-EOT 74 | The [build specification](https://docs.aws.amazon.com/amplify/latest/userguide/build-settings.html) (build spec) for the Amplify app. 75 | If not provided then it will use the `amplify.yml` at the root of your project / branch. 76 | EOT 77 | default = null 78 | } 79 | 80 | variable "enable_auto_branch_creation" { 81 | type = bool 82 | description = "Enables automated branch creation for the Amplify app" 83 | default = false 84 | } 85 | 86 | variable "enable_basic_auth" { 87 | type = bool 88 | description = <<-EOT 89 | Enables basic authorization for the Amplify app. 90 | This will apply to all branches that are part of this app. 91 | EOT 92 | default = false 93 | } 94 | 95 | variable "enable_branch_auto_build" { 96 | type = bool 97 | description = "Enables auto-building of branches for the Amplify App" 98 | default = true 99 | } 100 | 101 | variable "enable_branch_auto_deletion" { 102 | type = bool 103 | description = "Automatically disconnects a branch in the Amplify Console when you delete a branch from your Git repository" 104 | default = false 105 | } 106 | 107 | variable "environment_variables" { 108 | type = map(string) 109 | description = "The environment variables for the Amplify app" 110 | default = {} 111 | } 112 | 113 | variable "custom_headers" { 114 | type = string 115 | description = "The custom headers for the Amplify app, allows specifying headers for every HTTP response. Must adhere to AWS's format: https://docs.aws.amazon.com/amplify/latest/userguide/custom-headers.html" 116 | default = "" 117 | } 118 | 119 | variable "iam_service_role_arn" { 120 | type = list(string) 121 | description = <<-EOT 122 | The AWS Identity and Access Management (IAM) service role for the Amplify app. 123 | If not provided, a new role will be created if the variable `iam_service_role_enabled` is set to `true`. 124 | EOT 125 | default = [] 126 | nullable = false 127 | } 128 | 129 | variable "iam_service_role_enabled" { 130 | type = bool 131 | description = "Flag to create the IAM service role for the Amplify app" 132 | default = false 133 | nullable = false 134 | } 135 | 136 | variable "iam_service_role_actions" { 137 | type = list(string) 138 | description = <<-EOT 139 | List of IAM policy actions for the AWS Identity and Access Management (IAM) service role for the Amplify app. 140 | If not provided, the default set of actions will be used for the role if the variable `iam_service_role_enabled` is set to `true`. 141 | EOT 142 | default = [] 143 | nullable = false 144 | } 145 | 146 | variable "custom_rules" { 147 | type = list(object({ 148 | condition = optional(string) 149 | source = string 150 | status = optional(string) 151 | target = string 152 | })) 153 | description = "The custom rules to apply to the Amplify App" 154 | default = [] 155 | nullable = false 156 | } 157 | 158 | variable "environments" { 159 | type = map(object({ 160 | branch_name = optional(string) 161 | backend_enabled = optional(bool, false) 162 | environment_name = optional(string) 163 | deployment_artifacts = optional(string) 164 | stack_name = optional(string) 165 | display_name = optional(string) 166 | description = optional(string) 167 | enable_auto_build = optional(bool) 168 | enable_basic_auth = optional(bool) 169 | enable_notification = optional(bool) 170 | enable_performance_mode = optional(bool) 171 | enable_pull_request_preview = optional(bool) 172 | environment_variables = optional(map(string)) 173 | framework = optional(string) 174 | pull_request_environment_name = optional(string) 175 | stage = optional(string) 176 | ttl = optional(number) 177 | webhook_enabled = optional(bool, false) 178 | })) 179 | description = "The configuration of the environments for the Amplify App" 180 | default = {} 181 | nullable = false 182 | } 183 | 184 | variable "domains" { 185 | type = map(object({ 186 | enable_auto_sub_domain = optional(bool, false) 187 | wait_for_verification = optional(bool, false) 188 | sub_domain = list(object({ 189 | branch_name = string 190 | prefix = string 191 | })) 192 | })) 193 | description = "Amplify custom domain configurations" 194 | default = null 195 | } 196 | -------------------------------------------------------------------------------- /variables.tf: -------------------------------------------------------------------------------- 1 | variable "description" { 2 | type = string 3 | description = "The description for the Amplify app" 4 | default = null 5 | } 6 | 7 | variable "repository" { 8 | type = string 9 | description = "The repository for the Amplify app" 10 | default = null 11 | } 12 | 13 | variable "platform" { 14 | type = string 15 | description = "The platform or framework for the Amplify app" 16 | default = "WEB" 17 | } 18 | 19 | variable "access_token" { 20 | type = string 21 | description = <<-EOT 22 | The personal access token for a third-party source control system for the Amplify app. 23 | The personal access token is used to create a webhook and a read-only deploy key. The token is not stored. 24 | Make sure that the account where the token is created has access to the repository. 25 | EOT 26 | default = null 27 | sensitive = true 28 | } 29 | 30 | variable "oauth_token" { 31 | type = string 32 | description = <<-EOT 33 | The OAuth token for a third-party source control system for the Amplify app. 34 | The OAuth token is used to create a webhook and a read-only deploy key. 35 | The OAuth token is not stored. 36 | EOT 37 | default = null 38 | sensitive = true 39 | } 40 | 41 | variable "auto_branch_creation_config" { 42 | type = object({ 43 | basic_auth_credentials = optional(string) 44 | build_spec = optional(string) 45 | enable_auto_build = optional(bool) 46 | enable_basic_auth = optional(bool) 47 | enable_performance_mode = optional(bool) 48 | enable_pull_request_preview = optional(bool) 49 | environment_variables = optional(map(string)) 50 | framework = optional(string) 51 | pull_request_environment_name = optional(string) 52 | stage = optional(string) 53 | }) 54 | description = "The automated branch creation configuration for the Amplify app" 55 | default = null 56 | } 57 | 58 | variable "auto_branch_creation_patterns" { 59 | type = list(string) 60 | description = "The automated branch creation glob patterns for the Amplify app" 61 | default = [] 62 | } 63 | 64 | variable "basic_auth_credentials" { 65 | type = string 66 | description = "The credentials for basic authorization for the Amplify app" 67 | default = null 68 | } 69 | 70 | variable "build_spec" { 71 | type = string 72 | description = <<-EOT 73 | The [build specification](https://docs.aws.amazon.com/amplify/latest/userguide/build-settings.html) (build spec) for the Amplify app. 74 | If not provided then it will use the `amplify.yml` at the root of your project / branch. 75 | EOT 76 | default = null 77 | } 78 | 79 | variable "enable_auto_branch_creation" { 80 | type = bool 81 | description = "Enables automated branch creation for the Amplify app" 82 | default = false 83 | } 84 | 85 | variable "enable_basic_auth" { 86 | type = bool 87 | description = <<-EOT 88 | Enables basic authorization for the Amplify app. 89 | This will apply to all branches that are part of this app. 90 | EOT 91 | default = false 92 | } 93 | 94 | variable "enable_branch_auto_build" { 95 | type = bool 96 | description = "Enables auto-building of branches for the Amplify App" 97 | default = true 98 | } 99 | 100 | variable "enable_branch_auto_deletion" { 101 | type = bool 102 | description = "Automatically disconnects a branch in the Amplify Console when you delete a branch from your Git repository" 103 | default = false 104 | } 105 | 106 | variable "environment_variables" { 107 | type = map(string) 108 | description = "The environment variables for the Amplify app" 109 | default = {} 110 | } 111 | 112 | variable "iam_service_role_arn" { 113 | type = list(string) 114 | description = <<-EOT 115 | The AWS Identity and Access Management (IAM) service role for the Amplify app. 116 | If not provided, a new role will be created if the variable `iam_service_role_enabled` is set to `true`. 117 | EOT 118 | default = [] 119 | nullable = false 120 | } 121 | 122 | variable "iam_service_role_enabled" { 123 | type = bool 124 | description = "Flag to create the IAM service role for the Amplify app" 125 | default = false 126 | nullable = false 127 | } 128 | 129 | variable "iam_service_role_actions" { 130 | type = list(string) 131 | description = <<-EOT 132 | List of IAM policy actions for the AWS Identity and Access Management (IAM) service role for the Amplify app. 133 | If not provided, the default set of actions will be used for the role if the variable `iam_service_role_enabled` is set to `true`. 134 | EOT 135 | default = [] 136 | nullable = false 137 | } 138 | 139 | variable "custom_headers" { 140 | type = string 141 | description = "The custom headers for the Amplify app, allows specifying headers for every HTTP response. Must adhere to AWS's format: https://docs.aws.amazon.com/amplify/latest/userguide/custom-headers.html" 142 | default = null 143 | } 144 | 145 | variable "custom_rules" { 146 | type = list(object({ 147 | condition = optional(string) 148 | source = string 149 | status = optional(string) 150 | target = string 151 | })) 152 | description = "The custom rules to apply to the Amplify App" 153 | default = [] 154 | nullable = false 155 | } 156 | 157 | variable "environments" { 158 | type = map(object({ 159 | branch_name = optional(string) 160 | basic_auth_credentials = optional(string) 161 | backend_enabled = optional(bool, false) 162 | environment_name = optional(string) 163 | deployment_artifacts = optional(string) 164 | stack_name = optional(string) 165 | display_name = optional(string) 166 | description = optional(string) 167 | enable_auto_build = optional(bool) 168 | enable_basic_auth = optional(bool) 169 | enable_notification = optional(bool) 170 | enable_performance_mode = optional(bool) 171 | enable_pull_request_preview = optional(bool) 172 | environment_variables = optional(map(string)) 173 | framework = optional(string) 174 | pull_request_environment_name = optional(string) 175 | stage = optional(string) 176 | ttl = optional(number) 177 | webhook_enabled = optional(bool, false) 178 | })) 179 | description = "The configuration of the environments for the Amplify App" 180 | default = {} 181 | nullable = false 182 | } 183 | 184 | variable "domains" { 185 | type = map(object({ 186 | enable_auto_sub_domain = optional(bool, false) 187 | wait_for_verification = optional(bool, false) 188 | sub_domain = list(object({ 189 | branch_name = string 190 | prefix = string 191 | })) 192 | })) 193 | description = "Amplify custom domain configurations" 194 | default = {} 195 | } 196 | -------------------------------------------------------------------------------- /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-amplify-app 8 | 9 | # Logo for this project 10 | #logo: docs/logo.png 11 | 12 | # License of this project 13 | license: "APACHE2" 14 | 15 | # Copyrights 16 | copyrights: 17 | - name: "Cloud Posse, LLC" 18 | url: "https://cloudposse.com" 19 | year: "2023" 20 | 21 | # Canonical GitHub repo 22 | github_repo: cloudposse/terraform-aws-amplify-app 23 | 24 | # Badges to display 25 | badges: 26 | - name: Latest Release 27 | image: https://img.shields.io/github/release/cloudposse/terraform-aws-amplify-app.svg?style=for-the-badge 28 | url: https://github.com/cloudposse/terraform-aws-amplify-app/releases/latest 29 | - name: Last Updated 30 | image: https://img.shields.io/github/last-commit/cloudposse/terraform-aws-amplify-app.svg?style=for-the-badge 31 | url: https://github.com/cloudposse/terraform-aws-amplify-app/commits 32 | - name: Slack Community 33 | image: https://slack.cloudposse.com/for-the-badge.svg 34 | url: https://cloudposse.com/slack 35 | 36 | # List any related terraform modules that this module may be used with or that this module depends on. 37 | related: 38 | - name: "terraform-null-label" 39 | description: "Terraform module designed to generate consistent names and tags for resources. Use terraform-null-label to implement a strict naming convention." 40 | url: "https://github.com/cloudposse/terraform-null-label" 41 | 42 | # List any resources helpful for someone to get started. For example, link to the hashicorp documentation or AWS documentation. 43 | references: 44 | - name: "AWS Amplify Documentation" 45 | url: "https://docs.aws.amazon.com/amplify/index.html" 46 | description: "Use AWS Amplify to develop and deploy cloud-powered mobile and web apps" 47 | - name: "Setting up Amplify access to GitHub repositories" 48 | url: "https://docs.aws.amazon.com/amplify/latest/userguide/setting-up-GitHub-access.html" 49 | description: "Amplify uses the GitHub Apps feature to authorize Amplify read-only access to GitHub repositories. With the Amplify GitHub App, permissions are more fine-tuned, enabling you to grant Amplify access to only the repositories that you specify" 50 | - name: "Getting started with existing code" 51 | url: "https://docs.aws.amazon.com/amplify/latest/userguide/getting-started.html" 52 | description: "Documentation on how to continuously build, deploy, and host a modern web app using existing code" 53 | - name: "Deploy a Web App on AWS Amplify" 54 | url: "https://aws.amazon.com/getting-started/guides/deploy-webapp-amplify/" 55 | description: "A guide on deploying a web application with AWS Amplify" 56 | - name: "Getting started with fullstack continuous deployments" 57 | url: "https://docs.aws.amazon.com/amplify/latest/userguide/deploy-backend.html" 58 | description: "Tutorial on how to set up a fullstack CI/CD workflow with Amplify" 59 | - name: "Cloud Posse Documentation" 60 | url: "https://docs.cloudposse.com" 61 | description: "The Cloud Posse Developer Hub (documentation)" 62 | - name: "Terraform Standard Module Structure" 63 | description: "HashiCorp's standard module structure is a file and directory layout we recommend for reusable modules distributed in separate repositories." 64 | url: "https://www.terraform.io/docs/language/modules/develop/structure.html" 65 | - name: "Terraform Module Requirements" 66 | description: "HashiCorp's guidance on all the requirements for publishing a module. Meeting the requirements for publishing a module is extremely easy." 67 | url: "https://www.terraform.io/docs/registry/modules/publish.html#requirements" 68 | - name: "Terraform Version Pinning" 69 | description: "The required_version setting can be used to constrain which versions of the Terraform CLI can be used with your configuration" 70 | url: "https://www.terraform.io/docs/language/settings/index.html#specifying-a-required-terraform-version" 71 | - name: "Masterpoint.io" 72 | description: "This repo was inspired by masterpoint's original amplify-app terraform module" 73 | url: https://github.com/masterpointio/terraform-aws-amplify-app/ 74 | 75 | # Short description of this project 76 | description: |- 77 | Terraform module to provision AWS Amplify apps, backend environments, branches, domain associations, and webhooks. 78 | 79 | # How to use this module. Should be an easy example to copy and paste. 80 | usage: |- 81 | For a complete example, see [examples/complete](examples/complete). 82 | 83 | For automated tests of the complete example using [bats](https://github.com/bats-core/bats-core) and [Terratest](https://github.com/gruntwork-io/terratest) 84 | (which tests and deploys the example on AWS), see [test](test). 85 | 86 | ```hcl 87 | data "aws_ssm_parameter" "github_pat" { 88 | name = var.github_personal_access_token_secret_path 89 | with_decryption = true 90 | } 91 | 92 | module "amplify_app" { 93 | source = "cloudposse/amplify-app/aws" 94 | # Cloud Posse recommends pinning every module to a specific version 95 | # version = "x.x.x" 96 | 97 | access_token = data.aws_ssm_parameter.github_pat.value 98 | 99 | description = "Test Amplify App" 100 | repository = "https://github.com/cloudposse/amplify-test2" 101 | platform = "WEB" 102 | 103 | enable_auto_branch_creation = false 104 | enable_branch_auto_build = true 105 | enable_branch_auto_deletion = true 106 | enable_basic_auth = false 107 | 108 | iam_service_role_enabled = true 109 | 110 | iam_service_role_actions = [ 111 | "logs:CreateLogStream", 112 | "logs:CreateLogGroup", 113 | "logs:DescribeLogGroups", 114 | "logs:PutLogEvents" 115 | ] 116 | 117 | auto_branch_creation_patterns = [ 118 | "*", 119 | "*/**" 120 | ] 121 | 122 | auto_branch_creation_config = { 123 | # Enable auto build for the created branches 124 | enable_auto_build = true 125 | } 126 | 127 | # The build spec for React 128 | build_spec = <<-EOT 129 | version: 0.1 130 | frontend: 131 | phases: 132 | preBuild: 133 | commands: 134 | - yarn install 135 | build: 136 | commands: 137 | - yarn run build 138 | artifacts: 139 | baseDirectory: build 140 | files: 141 | - '**/*' 142 | cache: 143 | paths: 144 | - node_modules/**/* 145 | EOT 146 | 147 | custom_rules = [ 148 | { 149 | source = "/<*>" 150 | status = "404" 151 | target = "/index.html" 152 | } 153 | ] 154 | 155 | environment_variables = { 156 | ENV = "test" 157 | } 158 | 159 | environments = { 160 | main = { 161 | branch_name = "main" 162 | enable_auto_build = true 163 | backend_enabled = false 164 | enable_performance_mode = true 165 | enable_pull_request_preview = false 166 | framework = "React" 167 | stage = "PRODUCTION" 168 | } 169 | dev = { 170 | branch_name = "dev" 171 | enable_auto_build = true 172 | backend_enabled = false 173 | enable_performance_mode = false 174 | enable_pull_request_preview = true 175 | framework = "React" 176 | stage = "DEVELOPMENT" 177 | } 178 | } 179 | 180 | domains = { 181 | "test.net" = { 182 | enable_auto_sub_domain = true 183 | wait_for_verification = false 184 | sub_domain = [ 185 | { 186 | branch_name = "main" 187 | prefix = "" 188 | }, 189 | { 190 | branch_name = "dev" 191 | prefix = "dev" 192 | } 193 | ] 194 | } 195 | } 196 | 197 | context = module.label.context 198 | } 199 | ``` 200 | 201 | # Example usage 202 | examples: |- 203 | Here is an example of using this module: 204 | - [`examples/complete`](https://github.com/cloudposse/terraform-aws-amplify-app/) - complete example of using this module 205 | 206 | # Other files to include in this README from the project folder 207 | include: [] 208 | contributors: [] 209 | -------------------------------------------------------------------------------- /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 2023 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Project Banner
5 | 6 | 7 |

Latest ReleaseLast UpdatedSlack CommunityGet Support 8 | 9 |

10 | 11 | 12 | 32 | 33 | Terraform module to provision AWS Amplify apps, backend environments, branches, domain associations, and webhooks. 34 | 35 | 36 | > [!TIP] 37 | > #### 👽 Use Atmos with Terraform 38 | > Cloud Posse uses [`atmos`](https://atmos.tools) to easily orchestrate multiple environments using Terraform.
39 | > Works with [Github Actions](https://atmos.tools/integrations/github-actions/), [Atlantis](https://atmos.tools/integrations/atlantis), or [Spacelift](https://atmos.tools/integrations/spacelift). 40 | > 41 | >
42 | > Watch demo of using Atmos with Terraform 43 | >
44 | > Example of running atmos to manage infrastructure from our Quick Start tutorial. 45 | > 46 | 47 | 48 | 49 | 50 | 51 | ## Usage 52 | 53 | For a complete example, see [examples/complete](examples/complete). 54 | 55 | For automated tests of the complete example using [bats](https://github.com/bats-core/bats-core) and [Terratest](https://github.com/gruntwork-io/terratest) 56 | (which tests and deploys the example on AWS), see [test](test). 57 | 58 | ```hcl 59 | data "aws_ssm_parameter" "github_pat" { 60 | name = var.github_personal_access_token_secret_path 61 | with_decryption = true 62 | } 63 | 64 | module "amplify_app" { 65 | source = "cloudposse/amplify-app/aws" 66 | # Cloud Posse recommends pinning every module to a specific version 67 | # version = "x.x.x" 68 | 69 | access_token = data.aws_ssm_parameter.github_pat.value 70 | 71 | description = "Test Amplify App" 72 | repository = "https://github.com/cloudposse/amplify-test2" 73 | platform = "WEB" 74 | 75 | enable_auto_branch_creation = false 76 | enable_branch_auto_build = true 77 | enable_branch_auto_deletion = true 78 | enable_basic_auth = false 79 | 80 | iam_service_role_enabled = true 81 | 82 | iam_service_role_actions = [ 83 | "logs:CreateLogStream", 84 | "logs:CreateLogGroup", 85 | "logs:DescribeLogGroups", 86 | "logs:PutLogEvents" 87 | ] 88 | 89 | auto_branch_creation_patterns = [ 90 | "*", 91 | "*/**" 92 | ] 93 | 94 | auto_branch_creation_config = { 95 | # Enable auto build for the created branches 96 | enable_auto_build = true 97 | } 98 | 99 | # The build spec for React 100 | build_spec = <<-EOT 101 | version: 0.1 102 | frontend: 103 | phases: 104 | preBuild: 105 | commands: 106 | - yarn install 107 | build: 108 | commands: 109 | - yarn run build 110 | artifacts: 111 | baseDirectory: build 112 | files: 113 | - '**/*' 114 | cache: 115 | paths: 116 | - node_modules/**/* 117 | EOT 118 | 119 | custom_rules = [ 120 | { 121 | source = "/<*>" 122 | status = "404" 123 | target = "/index.html" 124 | } 125 | ] 126 | 127 | environment_variables = { 128 | ENV = "test" 129 | } 130 | 131 | environments = { 132 | main = { 133 | branch_name = "main" 134 | enable_auto_build = true 135 | backend_enabled = false 136 | enable_performance_mode = true 137 | enable_pull_request_preview = false 138 | framework = "React" 139 | stage = "PRODUCTION" 140 | } 141 | dev = { 142 | branch_name = "dev" 143 | enable_auto_build = true 144 | backend_enabled = false 145 | enable_performance_mode = false 146 | enable_pull_request_preview = true 147 | framework = "React" 148 | stage = "DEVELOPMENT" 149 | } 150 | } 151 | 152 | domains = { 153 | "test.net" = { 154 | enable_auto_sub_domain = true 155 | wait_for_verification = false 156 | sub_domain = [ 157 | { 158 | branch_name = "main" 159 | prefix = "" 160 | }, 161 | { 162 | branch_name = "dev" 163 | prefix = "dev" 164 | } 165 | ] 166 | } 167 | } 168 | 169 | context = module.label.context 170 | } 171 | ``` 172 | 173 | > [!IMPORTANT] 174 | > In Cloud Posse's examples, we avoid pinning modules to specific versions to prevent discrepancies between the documentation 175 | > and the latest released versions. However, for your own projects, we strongly advise pinning each module to the exact version 176 | > you're using. This practice ensures the stability of your infrastructure. Additionally, we recommend implementing a systematic 177 | > approach for updating versions to avoid unexpected changes. 178 | 179 | 180 | 181 | 182 | 183 | ## Examples 184 | 185 | Here is an example of using this module: 186 | - [`examples/complete`](https://github.com/cloudposse/terraform-aws-amplify-app/) - complete example of using this module 187 | 188 | 189 | 190 | 191 | 192 | ## Requirements 193 | 194 | | Name | Version | 195 | |------|---------| 196 | | [terraform](#requirement\_terraform) | >= 1.3.0 | 197 | | [aws](#requirement\_aws) | >= 4.0 | 198 | 199 | ## Providers 200 | 201 | | Name | Version | 202 | |------|---------| 203 | | [aws](#provider\_aws) | >= 4.0 | 204 | 205 | ## Modules 206 | 207 | | Name | Source | Version | 208 | |------|--------|---------| 209 | | [role](#module\_role) | cloudposse/iam-role/aws | 0.18.0 | 210 | | [this](#module\_this) | cloudposse/label/null | 0.25.0 | 211 | 212 | ## Resources 213 | 214 | | Name | Type | 215 | |------|------| 216 | | [aws_amplify_app.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/amplify_app) | resource | 217 | | [aws_amplify_backend_environment.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/amplify_backend_environment) | resource | 218 | | [aws_amplify_branch.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/amplify_branch) | resource | 219 | | [aws_amplify_domain_association.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/amplify_domain_association) | resource | 220 | | [aws_amplify_webhook.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/amplify_webhook) | resource | 221 | | [aws_iam_policy_document.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source | 222 | 223 | ## Inputs 224 | 225 | | Name | Description | Type | Default | Required | 226 | |------|-------------|------|---------|:--------:| 227 | | [access\_token](#input\_access\_token) | The personal access token for a third-party source control system for the Amplify app.
The personal access token is used to create a webhook and a read-only deploy key. The token is not stored.
Make sure that the account where the token is created has access to the repository. | `string` | `null` | no | 228 | | [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 | 229 | | [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 | 230 | | [auto\_branch\_creation\_config](#input\_auto\_branch\_creation\_config) | The automated branch creation configuration for the Amplify app |
object({
basic_auth_credentials = optional(string)
build_spec = optional(string)
enable_auto_build = optional(bool)
enable_basic_auth = optional(bool)
enable_performance_mode = optional(bool)
enable_pull_request_preview = optional(bool)
environment_variables = optional(map(string))
framework = optional(string)
pull_request_environment_name = optional(string)
stage = optional(string)
})
| `null` | no | 231 | | [auto\_branch\_creation\_patterns](#input\_auto\_branch\_creation\_patterns) | The automated branch creation glob patterns for the Amplify app | `list(string)` | `[]` | no | 232 | | [basic\_auth\_credentials](#input\_basic\_auth\_credentials) | The credentials for basic authorization for the Amplify app | `string` | `null` | no | 233 | | [build\_spec](#input\_build\_spec) | The [build specification](https://docs.aws.amazon.com/amplify/latest/userguide/build-settings.html) (build spec) for the Amplify app.
If not provided then it will use the `amplify.yml` at the root of your project / branch. | `string` | `null` | no | 234 | | [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 | 235 | | [custom\_headers](#input\_custom\_headers) | The custom headers for the Amplify app, allows specifying headers for every HTTP response. Must adhere to AWS's format: https://docs.aws.amazon.com/amplify/latest/userguide/custom-headers.html | `string` | `null` | no | 236 | | [custom\_rules](#input\_custom\_rules) | The custom rules to apply to the Amplify App |
list(object({
condition = optional(string)
source = string
status = optional(string)
target = string
}))
| `[]` | no | 237 | | [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no | 238 | | [description](#input\_description) | The description for the Amplify app | `string` | `null` | no | 239 | | [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 | 240 | | [domain\_config](#input\_domain\_config) | DEPRECATED: Use the `domains` variable instead.
Amplify custom domain configuration. |
object({
domain_name = string
enable_auto_sub_domain = optional(bool, false)
wait_for_verification = optional(bool, false)
sub_domain = list(object({
branch_name = string
prefix = string
}))
})
| `null` | no | 241 | | [domains](#input\_domains) | Amplify custom domain configurations |
map(object({
enable_auto_sub_domain = optional(bool, false)
wait_for_verification = optional(bool, false)
sub_domain = list(object({
branch_name = string
prefix = string
}))
}))
| `{}` | no | 242 | | [enable\_auto\_branch\_creation](#input\_enable\_auto\_branch\_creation) | Enables automated branch creation for the Amplify app | `bool` | `false` | no | 243 | | [enable\_basic\_auth](#input\_enable\_basic\_auth) | Enables basic authorization for the Amplify app.
This will apply to all branches that are part of this app. | `bool` | `false` | no | 244 | | [enable\_branch\_auto\_build](#input\_enable\_branch\_auto\_build) | Enables auto-building of branches for the Amplify App | `bool` | `true` | no | 245 | | [enable\_branch\_auto\_deletion](#input\_enable\_branch\_auto\_deletion) | Automatically disconnects a branch in the Amplify Console when you delete a branch from your Git repository | `bool` | `false` | no | 246 | | [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no | 247 | | [environment](#input\_environment) | ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no | 248 | | [environment\_variables](#input\_environment\_variables) | The environment variables for the Amplify app | `map(string)` | `{}` | no | 249 | | [environments](#input\_environments) | The configuration of the environments for the Amplify App |
map(object({
branch_name = optional(string)
basic_auth_credentials = optional(string)
backend_enabled = optional(bool, false)
environment_name = optional(string)
deployment_artifacts = optional(string)
stack_name = optional(string)
display_name = optional(string)
description = optional(string)
enable_auto_build = optional(bool)
enable_basic_auth = optional(bool)
enable_notification = optional(bool)
enable_performance_mode = optional(bool)
enable_pull_request_preview = optional(bool)
environment_variables = optional(map(string))
framework = optional(string)
pull_request_environment_name = optional(string)
stage = optional(string)
ttl = optional(number)
webhook_enabled = optional(bool, false)
}))
| `{}` | no | 250 | | [iam\_service\_role\_actions](#input\_iam\_service\_role\_actions) | List of IAM policy actions for the AWS Identity and Access Management (IAM) service role for the Amplify app.
If not provided, the default set of actions will be used for the role if the variable `iam_service_role_enabled` is set to `true`. | `list(string)` | `[]` | no | 251 | | [iam\_service\_role\_arn](#input\_iam\_service\_role\_arn) | The AWS Identity and Access Management (IAM) service role for the Amplify app.
If not provided, a new role will be created if the variable `iam_service_role_enabled` is set to `true`. | `list(string)` | `[]` | no | 252 | | [iam\_service\_role\_enabled](#input\_iam\_service\_role\_enabled) | Flag to create the IAM service role for the Amplify app | `bool` | `false` | no | 253 | | [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 | 254 | | [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 | 255 | | [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 | 256 | | [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 | 257 | | [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 | 258 | | [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 | 259 | | [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 | 260 | | [oauth\_token](#input\_oauth\_token) | The OAuth token for a third-party source control system for the Amplify app.
The OAuth token is used to create a webhook and a read-only deploy key.
The OAuth token is not stored. | `string` | `null` | no | 261 | | [platform](#input\_platform) | The platform or framework for the Amplify app | `string` | `"WEB"` | no | 262 | | [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 | 263 | | [repository](#input\_repository) | The repository for the Amplify app | `string` | `null` | no | 264 | | [stage](#input\_stage) | ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no | 265 | | [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 | 266 | | [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 | 267 | 268 | ## Outputs 269 | 270 | | Name | Description | 271 | |------|-------------| 272 | | [arn](#output\_arn) | Amplify App ARN | 273 | | [backend\_environments](#output\_backend\_environments) | Created backend environments | 274 | | [branch\_names](#output\_branch\_names) | The names of the created Amplify branches | 275 | | [default\_domain](#output\_default\_domain) | Amplify App domain (non-custom) | 276 | | [domain\_associations](#output\_domain\_associations) | Created domain associations | 277 | | [id](#output\_id) | Amplify App Id | 278 | | [name](#output\_name) | Amplify App name | 279 | | [webhooks](#output\_webhooks) | Created webhooks | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | ## Related Projects 289 | 290 | Check out these related projects. 291 | 292 | - [terraform-null-label](https://github.com/cloudposse/terraform-null-label) - Terraform module designed to generate consistent names and tags for resources. Use terraform-null-label to implement a strict naming convention. 293 | 294 | 295 | ## References 296 | 297 | For additional context, refer to some of these links. 298 | 299 | - [AWS Amplify Documentation](https://docs.aws.amazon.com/amplify/index.html) - Use AWS Amplify to develop and deploy cloud-powered mobile and web apps 300 | - [Setting up Amplify access to GitHub repositories](https://docs.aws.amazon.com/amplify/latest/userguide/setting-up-GitHub-access.html) - Amplify uses the GitHub Apps feature to authorize Amplify read-only access to GitHub repositories. With the Amplify GitHub App, permissions are more fine-tuned, enabling you to grant Amplify access to only the repositories that you specify 301 | - [Getting started with existing code](https://docs.aws.amazon.com/amplify/latest/userguide/getting-started.html) - Documentation on how to continuously build, deploy, and host a modern web app using existing code 302 | - [Deploy a Web App on AWS Amplify](https://aws.amazon.com/getting-started/guides/deploy-webapp-amplify/) - A guide on deploying a web application with AWS Amplify 303 | - [Getting started with fullstack continuous deployments](https://docs.aws.amazon.com/amplify/latest/userguide/deploy-backend.html) - Tutorial on how to set up a fullstack CI/CD workflow with Amplify 304 | - [Cloud Posse Documentation](https://docs.cloudposse.com) - The Cloud Posse Developer Hub (documentation) 305 | - [Terraform Standard Module Structure](https://www.terraform.io/docs/language/modules/develop/structure.html) - HashiCorp's standard module structure is a file and directory layout we recommend for reusable modules distributed in separate repositories. 306 | - [Terraform Module Requirements](https://www.terraform.io/docs/registry/modules/publish.html#requirements) - HashiCorp's guidance on all the requirements for publishing a module. Meeting the requirements for publishing a module is extremely easy. 307 | - [Terraform Version Pinning](https://www.terraform.io/docs/language/settings/index.html#specifying-a-required-terraform-version) - The required_version setting can be used to constrain which versions of the Terraform CLI can be used with your configuration 308 | - [Masterpoint.io](https://github.com/masterpointio/terraform-aws-amplify-app/) - This repo was inspired by masterpoint's original amplify-app terraform module 309 | 310 | 311 | 312 | > [!TIP] 313 | > #### Use Terraform Reference Architectures for AWS 314 | > 315 | > Use Cloud Posse's ready-to-go [terraform architecture blueprints](https://cloudposse.com/reference-architecture/) for AWS to get up and running quickly. 316 | > 317 | > ✅ We build it together with your team.
318 | > ✅ Your team owns everything.
319 | > ✅ 100% Open Source and backed by fanatical support.
320 | > 321 | > Request Quote 322 | >
📚 Learn More 323 | > 324 | >
325 | > 326 | > Cloud Posse is the leading [**DevOps Accelerator**](https://cpco.io/commercial-support?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-amplify-app&utm_content=commercial_support) for funded startups and enterprises. 327 | > 328 | > *Your team can operate like a pro today.* 329 | > 330 | > Ensure that your team succeeds by using Cloud Posse's proven process and turnkey blueprints. Plus, we stick around until you succeed. 331 | > #### Day-0: Your Foundation for Success 332 | > - **Reference Architecture.** You'll get everything you need from the ground up built using 100% infrastructure as code. 333 | > - **Deployment Strategy.** Adopt a proven deployment strategy with GitHub Actions, enabling automated, repeatable, and reliable software releases. 334 | > - **Site Reliability Engineering.** Gain total visibility into your applications and services with Datadog, ensuring high availability and performance. 335 | > - **Security Baseline.** Establish a secure environment from the start, with built-in governance, accountability, and comprehensive audit logs, safeguarding your operations. 336 | > - **GitOps.** Empower your team to manage infrastructure changes confidently and efficiently through Pull Requests, leveraging the full power of GitHub Actions. 337 | > 338 | > Request Quote 339 | > 340 | > #### Day-2: Your Operational Mastery 341 | > - **Training.** Equip your team with the knowledge and skills to confidently manage the infrastructure, ensuring long-term success and self-sufficiency. 342 | > - **Support.** Benefit from a seamless communication over Slack with our experts, ensuring you have the support you need, whenever you need it. 343 | > - **Troubleshooting.** Access expert assistance to quickly resolve any operational challenges, minimizing downtime and maintaining business continuity. 344 | > - **Code Reviews.** Enhance your team’s code quality with our expert feedback, fostering continuous improvement and collaboration. 345 | > - **Bug Fixes.** Rely on our team to troubleshoot and resolve any issues, ensuring your systems run smoothly. 346 | > - **Migration Assistance.** Accelerate your migration process with our dedicated support, minimizing disruption and speeding up time-to-value. 347 | > - **Customer Workshops.** Engage with our team in weekly workshops, gaining insights and strategies to continuously improve and innovate. 348 | > 349 | > Request Quote 350 | > 351 |
352 | 353 | ## ✨ Contributing 354 | 355 | This project is under active development, and we encourage contributions from our community. 356 | 357 | 358 | 359 | Many thanks to our outstanding contributors: 360 | 361 | 362 | 363 | 364 | 365 | For 🐛 bug reports & feature requests, please use the [issue tracker](https://github.com/cloudposse/terraform-aws-amplify-app/issues). 366 | 367 | In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow. 368 | 1. Review our [Code of Conduct](https://github.com/cloudposse/terraform-aws-amplify-app/?tab=coc-ov-file#code-of-conduct) and [Contributor Guidelines](https://github.com/cloudposse/.github/blob/main/CONTRIBUTING.md). 369 | 2. **Fork** the repo on GitHub 370 | 3. **Clone** the project to your own machine 371 | 4. **Commit** changes to your own branch 372 | 5. **Push** your work back up to your fork 373 | 6. Submit a **Pull Request** so that we can review your changes 374 | 375 | **NOTE:** Be sure to merge the latest changes from "upstream" before making a pull request! 376 | 377 | 378 | ## Running Terraform Tests 379 | 380 | We use [Atmos](https://atmos.tools) to streamline how Terraform tests are run. It centralizes configuration and wraps common test workflows with easy-to-use commands. 381 | 382 | All tests are located in the [`test/`](test) folder. 383 | 384 | Under the hood, tests are powered by Terratest together with our internal [Test Helpers](https://github.com/cloudposse/test-helpers) library, providing robust infrastructure validation. 385 | 386 | Setup dependencies: 387 | - Install Atmos ([installation guide](https://atmos.tools/install/)) 388 | - Install Go [1.24+ or newer](https://go.dev/doc/install) 389 | - Install Terraform or OpenTofu 390 | 391 | To run tests: 392 | 393 | - Run all tests: 394 | ```sh 395 | atmos test run 396 | ``` 397 | - Clean up test artifacts: 398 | ```sh 399 | atmos test clean 400 | ``` 401 | - Explore additional test options: 402 | ```sh 403 | atmos test --help 404 | ``` 405 | The configuration for test commands is centrally managed. To review what's being imported, see the [`atmos.yaml`](https://raw.githubusercontent.com/cloudposse/.github/refs/heads/main/.github/atmos/terraform-module.yaml) file. 406 | 407 | Learn more about our [automated testing in our documentation](https://docs.cloudposse.com/community/contribute/automated-testing/) or implementing [custom commands](https://atmos.tools/core-concepts/custom-commands/) with atmos. 408 | 409 | ### 🌎 Slack Community 410 | 411 | Join our [Open Source Community](https://cpco.io/slack?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-amplify-app&utm_content=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. 412 | 413 | ### 📰 Newsletter 414 | 415 | Sign up for [our newsletter](https://cpco.io/newsletter?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-amplify-app&utm_content=newsletter) and join 3,000+ DevOps engineers, CTOs, and founders who get insider access to the latest DevOps trends, so you can always stay in the know. 416 | Dropped straight into your Inbox every week — and usually a 5-minute read. 417 | 418 | ### 📆 Office Hours 419 | 420 | [Join us every Wednesday via Zoom](https://cloudposse.com/office-hours?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-amplify-app&utm_content=office_hours) for your weekly dose of insider DevOps trends, AWS news and Terraform insights, all sourced from our SweetOps community, plus a _live Q&A_ that you can’t find anywhere else. 421 | It's **FREE** for everyone! 422 | ## License 423 | 424 | License 425 | 426 |
427 | Preamble to the Apache License, Version 2.0 428 |
429 |
430 | 431 | Complete license is available in the [`LICENSE`](LICENSE) file. 432 | 433 | ```text 434 | Licensed to the Apache Software Foundation (ASF) under one 435 | or more contributor license agreements. See the NOTICE file 436 | distributed with this work for additional information 437 | regarding copyright ownership. The ASF licenses this file 438 | to you under the Apache License, Version 2.0 (the 439 | "License"); you may not use this file except in compliance 440 | with the License. You may obtain a copy of the License at 441 | 442 | https://www.apache.org/licenses/LICENSE-2.0 443 | 444 | Unless required by applicable law or agreed to in writing, 445 | software distributed under the License is distributed on an 446 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 447 | KIND, either express or implied. See the License for the 448 | specific language governing permissions and limitations 449 | under the License. 450 | ``` 451 |
452 | 453 | ## Trademarks 454 | 455 | All other trademarks referenced herein are the property of their respective owners. 456 | 457 | 458 | ## Copyrights 459 | 460 | Copyright © 2023-2025 [Cloud Posse, LLC](https://cloudposse.com) 461 | 462 | 463 | 464 | README footer 465 | 466 | Beacon 467 | --------------------------------------------------------------------------------