Created
June 13, 2022 09:14
-
-
Save whoiskai/8b8b1e68138d2498b3d688406cbf7b95 to your computer and use it in GitHub Desktop.
appconfig module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "aws_appconfig_application" "main" { | |
name = var.application_name | |
description = var.description | |
tags = var.tags | |
} | |
resource "aws_appconfig_environment" "main" { | |
name = var.environment_name | |
description = var.environment_description | |
application_id = aws_appconfig_application.main.id | |
# monitor { | |
# alarm_arn = aws_cloudwatch_metric_alarm.main.arn | |
# alarm_role_arn = aws_iam_role.main.arn | |
# } | |
tags = merge(var.tags, var.environment_tags) | |
} | |
resource "aws_appconfig_deployment" "main" { | |
application_id = aws_appconfig_application.main.id | |
configuration_profile_id = aws_appconfig_configuration_profile.main.configuration_profile_id | |
configuration_version = module.paramstore.ssm_parameters_versions["appconfig_release_toggles"] | |
deployment_strategy_id = var.create_deployment_strategy ? aws_appconfig_deployment_strategy.main[0].id : var.deployment_strategy_id | |
description = var.deployment_description | |
environment_id = aws_appconfig_environment.main.environment_id | |
tags = merge(var.tags, var.deployment_tags) | |
} | |
resource "aws_appconfig_deployment_strategy" "main" { | |
count = var.create_deployment_strategy ? 1 : 0 | |
name = var.deployment_strategy_name | |
description = null | |
deployment_duration_in_minutes = var.deployment_strategy_deployment_duration_in_minutes | |
final_bake_time_in_minutes = var.deployment_strategy_final_bake_time_in_minutes | |
growth_factor = var.deployment_strategy_growth_factor | |
growth_type = var.deployment_strategy_growth_type | |
replicate_to = var.deployment_strategy_replicate_to | |
tags = merge(var.tags, var.deployment_strategy_tags) | |
} | |
resource "aws_appconfig_configuration_profile" "main" { | |
application_id = aws_appconfig_application.main.id | |
name = var.configuration_profile_name | |
description = var.configuration_profile_description | |
retrieval_role_arn = var.retrieval_role_arn | |
location_uri = "ssm-parameter://${var.ssm_path}" | |
dynamic "validator" { | |
for_each = var.configuration_profile_validator | |
content { | |
content = lookup(validator.value, "content", null) | |
type = lookup(validator.value, "type", null) | |
} | |
} | |
tags = merge(var.tags, var.config_profile_tags) | |
} | |
# Using paramstore because hosted config has a weird behaviour where it doesn't update version | |
module "paramstore" { | |
source = "../ssm-parameter-store" | |
params = { | |
appconfig_release_toggles = { | |
name = var.ssm_path | |
type = "String" | |
overwrite = true | |
value = var.ssm_content | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
output "ssm_parameters" { | |
value = module.paramstore.ssm_parameters | |
} | |
output "application_name" { | |
value = aws_appconfig_application.main.name | |
} | |
output "environment_name" { | |
value = aws_appconfig_environment.main.name | |
} | |
output "environment_description" { | |
value = aws_appconfig_environment.main.description | |
} | |
output "configuration_profile_location_uri" { | |
value = aws_appconfig_configuration_profile.main.location_uri | |
} | |
output "deployment_version" { | |
value = aws_appconfig_deployment.main.configuration_version | |
} | |
output "deployment_number" { | |
value = aws_appconfig_deployment.main.deployment_number | |
} | |
output "deployment_strategy_id" { | |
value = aws_appconfig_deployment.main.deployment_strategy_id | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable "application_name" { | |
description = "The name for the application. Must be between 1 and 64 characters in length." | |
type = string | |
} | |
variable "description" { | |
description = "The description of the application. Can be at most 1024 characters" | |
type = string | |
default = null | |
} | |
variable "environment_name" { | |
description = "(Required) The name for the environment. Must be between 1 and 64 characters in length." | |
type = string | |
} | |
variable "environment_description" { | |
description = "(Optional) The description of the environment. Can be at most 1024 characters." | |
type = string | |
} | |
variable "configuration_profile_name" { | |
description = "(Required) The name for the configuration profile. Must be between 1 and 64 characters in length." | |
type = string | |
} | |
variable "configuration_profile_description" { | |
description = "(Optional) The description of the configuration profile. Can be at most 1024 characters." | |
type = string | |
default = null | |
} | |
variable "configuration_profile_validator" { | |
description = "A set of methods for validating the configuration. Maximum of 2" | |
type = list(map(any)) | |
default = [] | |
} | |
variable "ssm_content" { | |
description = "The content of ssm param to be used by configuration profile" | |
type = string | |
default = null | |
} | |
variable "ssm_path" { | |
description = "Path to SSM param for configuration profile to reference" | |
type = string | |
} | |
variable "retrieval_role_arn" { | |
description = "(Optional) The ARN of an IAM role with permission to access the configuration at the specified location_uri. A retrieval role ARN is not required for configurations stored in the AWS AppConfig hosted configuration store. It is required for all other sources that store your configuration." | |
type = string | |
default = null | |
} | |
variable "deployment_description" { | |
description = "(Optional, Forces new resource) The description of the deployment. Can be at most 1024 characters." | |
type = string | |
default = null | |
} | |
variable "create_deployment_strategy" { | |
description = "Whether to create a new strategy or not" | |
type = bool | |
default = false | |
} | |
# https://docs.aws.amazon.com/appconfig/latest/userguide/appconfig-creating-deployment-strategy.html#appconfig-creating-deployment-strategy-predefined | |
variable "deployment_strategy_id" { | |
description = "(Required, Forces new resource) The deployment strategy ID or name of a predefined deployment strategy." | |
type = string | |
default = "AppConfig.AllAtOnce" | |
} | |
variable "deployment_strategy_name" { | |
description = "A name for the deployment strategy. Must be between 1 and 64 characters in length" | |
type = string | |
default = null | |
} | |
variable "deployment_strategy_description" { | |
description = "A description of the deployment strategy. Can be at most 1024 characters" | |
type = string | |
default = null | |
} | |
variable "deployment_strategy_deployment_duration_in_minutes" { | |
description = "Total amount of time for a deployment to last. Minimum value of 0, maximum value of 1440" | |
type = number | |
default = 0 | |
} | |
variable "deployment_strategy_final_bake_time_in_minutes" { | |
description = "Total amount of time for a deployment to last. Minimum value of 0, maximum value of 1440" | |
type = number | |
default = 0 | |
} | |
variable "deployment_strategy_growth_factor" { | |
description = "The percentage of targets to receive a deployed configuration during each interval. Minimum value of 1, maximum value of 100" | |
type = number | |
default = 100 | |
} | |
variable "deployment_strategy_growth_type" { | |
description = "The algorithm used to define how percentage grows over time. Valid value: `LINEAR` and `EXPONENTIAL`. Defaults to `LINEAR`" | |
type = string | |
default = "LINEAR" | |
} | |
variable "deployment_strategy_replicate_to" { | |
description = "Where to save the deployment strategy. Valid values: `NONE` and `SSM_DOCUMENT`" | |
type = string | |
default = "NONE" | |
} | |
variable "tags" { | |
description = "A list of tag blocks. Each element should have keys named key, value, and propagate_at_launch" | |
type = map(string) | |
default = {} | |
} | |
variable "config_profile_tags" { | |
description = "A map of additional tags to apply to the configuration profile" | |
type = map(string) | |
default = {} | |
} | |
variable "deployment_tags" { | |
description = "A map of additional tags to apply to the deployment" | |
type = map(string) | |
default = {} | |
} | |
variable "environment_tags" { | |
description = "A map of additional tags to apply to the environment" | |
type = map(string) | |
default = {} | |
} | |
variable "deployment_strategy_tags" { | |
description = "A map of additional tags to apply to the deployment strategy" | |
type = map(string) | |
default = {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment