Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ability to write secrets for amplify app #33

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ Available targets:
|------|--------|---------|
| <a name="module_role"></a> [role](#module\_role) | cloudposse/iam-role/aws | 0.18.0 |
| <a name="module_this"></a> [this](#module\_this) | cloudposse/label/null | 0.25.0 |
| <a name="module_write_ssm_secrets"></a> [write\_ssm\_secrets](#module\_write\_ssm\_secrets) | cloudposse/ssm-parameter-store/aws | 0.13.0 |

## Resources

Expand Down Expand Up @@ -254,7 +255,7 @@ Available targets:
| <a name="input_enabled"></a> [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
| <a name="input_environment"></a> [environment](#input\_environment) | ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |
| <a name="input_environment_variables"></a> [environment\_variables](#input\_environment\_variables) | The environment variables for the Amplify app | `map(string)` | `{}` | no |
| <a name="input_environments"></a> [environments](#input\_environments) | The configuration of the environments for the Amplify App | <pre>map(object({<br> branch_name = optional(string)<br> basic_auth_credentials = optional(string)<br> backend_enabled = optional(bool, false)<br> environment_name = optional(string)<br> deployment_artifacts = optional(string)<br> stack_name = optional(string)<br> display_name = optional(string)<br> description = optional(string)<br> enable_auto_build = optional(bool)<br> enable_basic_auth = optional(bool)<br> enable_notification = optional(bool)<br> enable_performance_mode = optional(bool)<br> enable_pull_request_preview = optional(bool)<br> environment_variables = optional(map(string))<br> framework = optional(string)<br> pull_request_environment_name = optional(string)<br> stage = optional(string)<br> ttl = optional(number)<br> webhook_enabled = optional(bool, false)<br> }))</pre> | `{}` | no |
| <a name="input_environments"></a> [environments](#input\_environments) | The configuration of the environments for the Amplify App | <pre>map(object({<br> branch_name = optional(string)<br> basic_auth_credentials = optional(string)<br> backend_enabled = optional(bool, false)<br> environment_name = optional(string)<br> deployment_artifacts = optional(string)<br> stack_name = optional(string)<br> display_name = optional(string)<br> description = optional(string)<br> enable_auto_build = optional(bool)<br> enable_basic_auth = optional(bool)<br> enable_notification = optional(bool)<br> enable_performance_mode = optional(bool)<br> enable_pull_request_preview = optional(bool)<br> environment_variables = optional(map(string))<br> secrets = optional(map(string), {})<br> framework = optional(string)<br> pull_request_environment_name = optional(string)<br> stage = optional(string)<br> ttl = optional(number)<br> webhook_enabled = optional(bool, false)<br> }))</pre> | `{}` | no |
| <a name="input_iam_service_role_actions"></a> [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.<br>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 |
| <a name="input_iam_service_role_arn"></a> [iam\_service\_role\_arn](#input\_iam\_service\_role\_arn) | The AWS Identity and Access Management (IAM) service role for the Amplify app.<br>If not provided, a new role will be created if the variable `iam_service_role_enabled` is set to `true`. | `list(string)` | `[]` | no |
| <a name="input_iam_service_role_enabled"></a> [iam\_service\_role\_enabled](#input\_iam\_service\_role\_enabled) | Flag to create the IAM service role for the Amplify app | `bool` | `false` | no |
Expand Down
3 changes: 2 additions & 1 deletion docs/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
|------|--------|---------|
| <a name="module_role"></a> [role](#module\_role) | cloudposse/iam-role/aws | 0.18.0 |
| <a name="module_this"></a> [this](#module\_this) | cloudposse/label/null | 0.25.0 |
| <a name="module_write_ssm_secrets"></a> [write\_ssm\_secrets](#module\_write\_ssm\_secrets) | cloudposse/ssm-parameter-store/aws | 0.13.0 |

## Resources

Expand Down Expand Up @@ -55,7 +56,7 @@
| <a name="input_enabled"></a> [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
| <a name="input_environment"></a> [environment](#input\_environment) | ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |
| <a name="input_environment_variables"></a> [environment\_variables](#input\_environment\_variables) | The environment variables for the Amplify app | `map(string)` | `{}` | no |
| <a name="input_environments"></a> [environments](#input\_environments) | The configuration of the environments for the Amplify App | <pre>map(object({<br> branch_name = optional(string)<br> basic_auth_credentials = optional(string)<br> backend_enabled = optional(bool, false)<br> environment_name = optional(string)<br> deployment_artifacts = optional(string)<br> stack_name = optional(string)<br> display_name = optional(string)<br> description = optional(string)<br> enable_auto_build = optional(bool)<br> enable_basic_auth = optional(bool)<br> enable_notification = optional(bool)<br> enable_performance_mode = optional(bool)<br> enable_pull_request_preview = optional(bool)<br> environment_variables = optional(map(string))<br> framework = optional(string)<br> pull_request_environment_name = optional(string)<br> stage = optional(string)<br> ttl = optional(number)<br> webhook_enabled = optional(bool, false)<br> }))</pre> | `{}` | no |
| <a name="input_environments"></a> [environments](#input\_environments) | The configuration of the environments for the Amplify App | <pre>map(object({<br> branch_name = optional(string)<br> basic_auth_credentials = optional(string)<br> backend_enabled = optional(bool, false)<br> environment_name = optional(string)<br> deployment_artifacts = optional(string)<br> stack_name = optional(string)<br> display_name = optional(string)<br> description = optional(string)<br> enable_auto_build = optional(bool)<br> enable_basic_auth = optional(bool)<br> enable_notification = optional(bool)<br> enable_performance_mode = optional(bool)<br> enable_pull_request_preview = optional(bool)<br> environment_variables = optional(map(string))<br> secrets = optional(map(string), {})<br> framework = optional(string)<br> pull_request_environment_name = optional(string)<br> stage = optional(string)<br> ttl = optional(number)<br> webhook_enabled = optional(bool, false)<br> }))</pre> | `{}` | no |
| <a name="input_iam_service_role_actions"></a> [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.<br>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 |
| <a name="input_iam_service_role_arn"></a> [iam\_service\_role\_arn](#input\_iam\_service\_role\_arn) | The AWS Identity and Access Management (IAM) service role for the Amplify app.<br>If not provided, a new role will be created if the variable `iam_service_role_enabled` is set to `true`. | `list(string)` | `[]` | no |
| <a name="input_iam_service_role_enabled"></a> [iam\_service\_role\_enabled](#input\_iam\_service\_role\_enabled) | Flag to create the IAM service role for the Amplify app | `bool` | `false` | no |
Expand Down
4 changes: 4 additions & 0 deletions examples/complete/fixtures.us-east-2.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ environments = {
enable_pull_request_preview = false
framework = "React"
stage = "PRODUCTION"
secrets = {
TEST = "test_secret"
TEST2 = "test_secret2"
}
}
dev = {
branch_name = "dev"
Expand Down
1 change: 1 addition & 0 deletions examples/complete/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ variable "environments" {
enable_performance_mode = optional(bool)
enable_pull_request_preview = optional(bool)
environment_variables = optional(map(string))
secrets = optional(map(string), {})
framework = optional(string)
pull_request_environment_name = optional(string)
stage = optional(string)
Expand Down
16 changes: 16 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,19 @@ resource "aws_amplify_webhook" "default" {
command = "curl -X POST -d {} '${aws_amplify_webhook.default[each.key].url}&operation=startbuild' -H 'Content-Type:application/json'"
}
}

module "write_ssm_secrets" {
source = "cloudposse/ssm-parameter-store/aws"
version = "0.13.0"

for_each = local.environments

parameter_write = [for secret_key, secret_value in each.value.secrets : {
name = format("/amplify/%s/%s/%s", one(aws_amplify_app.default[*].id), each.key, secret_key)
value = secret_value
type = "SecureString"
description = "AWS Amplify secret."
}]

context = module.this.context
}
Comment on lines +131 to +145
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
module "write_ssm_secrets" {
source = "cloudposse/ssm-parameter-store/aws"
version = "0.13.0"
for_each = local.environments
parameter_write = [for secret_key, secret_value in each.value.secrets : {
name = format("/amplify/%s/%s/%s", one(aws_amplify_app.default[*].id), each.key, secret_key)
value = secret_value
type = "SecureString"
description = "AWS Amplify secret."
}]
context = module.this.context
}
resource "aws_ssm_parameter" "default" {
for_each = local.environments
name = format("/amplify/%s/%s/%s", one(aws_amplify_app.default[*].id), each.key, secret_key)
description = "AWS Amplify secret."
type = "SecureString"
tier = "Standard"
value = secret_value
overwrite = "false"
data_type = "text"
tags = module.this.tags
}

1 change: 1 addition & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ output "domain_associations" {
description = "Created domain associations"
value = aws_amplify_domain_association.default
}

1 change: 1 addition & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ variable "environments" {
enable_performance_mode = optional(bool)
enable_pull_request_preview = optional(bool)
environment_variables = optional(map(string))
secrets = optional(map(string), {})
framework = optional(string)
pull_request_environment_name = optional(string)
stage = optional(string)
Expand Down