From 143802af4a3a42248cb827242f6e48a8d5db82f7 Mon Sep 17 00:00:00 2001 From: Matheus Mazzoni Date: Tue, 4 Jul 2023 16:51:06 -0300 Subject: [PATCH 1/2] feat: create main and submodules wrappers --- wrappers/alias/main.tf | 26 +++++++ wrappers/alias/outputs.tf | 5 ++ wrappers/alias/variables.tf | 11 +++ wrappers/alias/versions.tf | 3 + wrappers/deploy/main.tf | 41 ++++++++++ wrappers/deploy/outputs.tf | 5 ++ wrappers/deploy/variables.tf | 11 +++ wrappers/deploy/versions.tf | 3 + wrappers/docker-build/main.tf | 20 +++++ wrappers/docker-build/outputs.tf | 5 ++ wrappers/docker-build/variables.tf | 11 +++ wrappers/docker-build/versions.tf | 3 + wrappers/main.tf | 121 +++++++++++++++++++++++++++++ wrappers/outputs.tf | 5 ++ wrappers/variables.tf | 11 +++ wrappers/versions.tf | 3 + 16 files changed, 284 insertions(+) create mode 100644 wrappers/alias/main.tf create mode 100644 wrappers/alias/outputs.tf create mode 100644 wrappers/alias/variables.tf create mode 100644 wrappers/alias/versions.tf create mode 100644 wrappers/deploy/main.tf create mode 100644 wrappers/deploy/outputs.tf create mode 100644 wrappers/deploy/variables.tf create mode 100644 wrappers/deploy/versions.tf create mode 100644 wrappers/docker-build/main.tf create mode 100644 wrappers/docker-build/outputs.tf create mode 100644 wrappers/docker-build/variables.tf create mode 100644 wrappers/docker-build/versions.tf create mode 100644 wrappers/main.tf create mode 100644 wrappers/outputs.tf create mode 100644 wrappers/variables.tf create mode 100644 wrappers/versions.tf diff --git a/wrappers/alias/main.tf b/wrappers/alias/main.tf new file mode 100644 index 00000000..983e3797 --- /dev/null +++ b/wrappers/alias/main.tf @@ -0,0 +1,26 @@ +module "wrapper" { + source = "../../modules/alias" + + for_each = var.items + + create = try(each.value.create, var.defaults.create, true) + use_existing_alias = try(each.value.use_existing_alias, var.defaults.use_existing_alias, false) + refresh_alias = try(each.value.refresh_alias, var.defaults.refresh_alias, true) + create_async_event_config = try(each.value.create_async_event_config, var.defaults.create_async_event_config, false) + create_version_async_event_config = try(each.value.create_version_async_event_config, var.defaults.create_version_async_event_config, true) + create_qualified_alias_async_event_config = try(each.value.create_qualified_alias_async_event_config, var.defaults.create_qualified_alias_async_event_config, true) + create_version_allowed_triggers = try(each.value.create_version_allowed_triggers, var.defaults.create_version_allowed_triggers, true) + create_qualified_alias_allowed_triggers = try(each.value.create_qualified_alias_allowed_triggers, var.defaults.create_qualified_alias_allowed_triggers, true) + name = try(each.value.name, var.defaults.name, null) + description = try(each.value.description, var.defaults.description, null) + function_name = try(each.value.function_name, var.defaults.function_name, null) + function_version = try(each.value.function_version, var.defaults.function_version, null) + routing_additional_version_weights = try(each.value.routing_additional_version_weights, var.defaults.routing_additional_version_weights, {}) + maximum_event_age_in_seconds = try(each.value.maximum_event_age_in_seconds, var.defaults.maximum_event_age_in_seconds, null) + maximum_retry_attempts = try(each.value.maximum_retry_attempts, var.defaults.maximum_retry_attempts, null) + destination_on_failure = try(each.value.destination_on_failure, var.defaults.destination_on_failure, null) + destination_on_success = try(each.value.destination_on_success, var.defaults.destination_on_success, null) + allowed_triggers = try(each.value.allowed_triggers, var.defaults.allowed_triggers, {}) + event_source_mapping = try(each.value.event_source_mapping, var.defaults.event_source_mapping, {}) + +} diff --git a/wrappers/alias/outputs.tf b/wrappers/alias/outputs.tf new file mode 100644 index 00000000..ec6da5f4 --- /dev/null +++ b/wrappers/alias/outputs.tf @@ -0,0 +1,5 @@ +output "wrapper" { + description = "Map of outputs of a wrapper." + value = module.wrapper + # sensitive = false # No sensitive module output found +} diff --git a/wrappers/alias/variables.tf b/wrappers/alias/variables.tf new file mode 100644 index 00000000..a6ea0962 --- /dev/null +++ b/wrappers/alias/variables.tf @@ -0,0 +1,11 @@ +variable "defaults" { + description = "Map of default values which will be used for each item." + type = any + default = {} +} + +variable "items" { + description = "Maps of items to create a wrapper from. Values are passed through to the module." + type = any + default = {} +} diff --git a/wrappers/alias/versions.tf b/wrappers/alias/versions.tf new file mode 100644 index 00000000..6b6318de --- /dev/null +++ b/wrappers/alias/versions.tf @@ -0,0 +1,3 @@ +terraform { + required_version = ">= 0.13" +} diff --git a/wrappers/deploy/main.tf b/wrappers/deploy/main.tf new file mode 100644 index 00000000..cf6c773a --- /dev/null +++ b/wrappers/deploy/main.tf @@ -0,0 +1,41 @@ +module "wrapper" { + source = "../../modules/deploy" + + for_each = var.items + create = try(each.value.create, var.defaults.create, true) + tags = try(each.value.tags, var.defaults.tags, {}) + alias_name = try(each.value.alias_name, var.defaults.alias_name, null) + function_name = try(each.value.function_name, var.defaults.function_name, null) + current_version = try(each.value.current_version, var.defaults.current_version, null) + target_version = try(each.value.target_version, var.defaults.target_version, null) + before_allow_traffic_hook_arn = try(each.value.before_allow_traffic_hook_arn, var.defaults.before_allow_traffic_hook_arn, null) + after_allow_traffic_hook_arn = try(each.value.after_allow_traffic_hook_arn, var.defaults.after_allow_traffic_hook_arn, null) + interpreter = try(each.value.interpreter, var.defaults.interpreter, ["/bin/bash", "-c"]) + description = try(each.value.description, var.defaults.description, null) + create_app = try(each.value.create_app, var.defaults.create_app, false) + use_existing_app = try(each.value.use_existing_app, var.defaults.use_existing_app, false) + app_name = try(each.value.app_name, var.defaults.app_name, null) + create_deployment_group = try(each.value.create_deployment_group, var.defaults.create_deployment_group, false) + use_existing_deployment_group = try(each.value.use_existing_deployment_group, var.defaults.use_existing_deployment_group, false) + deployment_group_name = try(each.value.deployment_group_name, var.defaults.deployment_group_name, null) + deployment_config_name = try(each.value.deployment_config_name, var.defaults.deployment_config_name, "CodeDeployDefault.LambdaAllAtOnce") + auto_rollback_enabled = try(each.value.auto_rollback_enabled, var.defaults.auto_rollback_enabled, true) + auto_rollback_events = try(each.value.auto_rollback_events, var.defaults.auto_rollback_events, ["DEPLOYMENT_STOP_ON_ALARM"]) + alarm_enabled = try(each.value.alarm_enabled, var.defaults.alarm_enabled, false) + alarms = try(each.value.alarms, var.defaults.alarms, []) + alarm_ignore_poll_alarm_failure = try(each.value.alarm_ignore_poll_alarm_failure, var.defaults.alarm_ignore_poll_alarm_failure, false) + triggers = try(each.value.triggers, var.defaults.triggers, {}) + aws_cli_command = try(each.value.aws_cli_command, var.defaults.aws_cli_command, "aws") + save_deploy_script = try(each.value.save_deploy_script, var.defaults.save_deploy_script, false) + create_deployment = try(each.value.create_deployment, var.defaults.create_deployment, false) + run_deployment = try(each.value.run_deployment, var.defaults.run_deployment, false) + force_deploy = try(each.value.force_deploy, var.defaults.force_deploy, false) + wait_deployment_completion = try(each.value.wait_deployment_completion, var.defaults.wait_deployment_completion, false) + create_codedeploy_role = try(each.value.create_codedeploy_role, var.defaults.create_codedeploy_role, true) + codedeploy_role_name = try(each.value.codedeploy_role_name, var.defaults.codedeploy_role_name, null) + codedeploy_principals = try(each.value.codedeploy_principals, var.defaults.codedeploy_principals, ["codedeploy.amazonaws.com"]) + attach_hooks_policy = try(each.value.attach_hooks_policy, var.defaults.attach_hooks_policy, true) + attach_triggers_policy = try(each.value.attach_triggers_policy, var.defaults.attach_triggers_policy, false) + get_deployment_sleep_timer = try(each.value.get_deployment_sleep_timer, var.defaults.get_deployment_sleep_timer, 5) + +} diff --git a/wrappers/deploy/outputs.tf b/wrappers/deploy/outputs.tf new file mode 100644 index 00000000..ec6da5f4 --- /dev/null +++ b/wrappers/deploy/outputs.tf @@ -0,0 +1,5 @@ +output "wrapper" { + description = "Map of outputs of a wrapper." + value = module.wrapper + # sensitive = false # No sensitive module output found +} diff --git a/wrappers/deploy/variables.tf b/wrappers/deploy/variables.tf new file mode 100644 index 00000000..a6ea0962 --- /dev/null +++ b/wrappers/deploy/variables.tf @@ -0,0 +1,11 @@ +variable "defaults" { + description = "Map of default values which will be used for each item." + type = any + default = {} +} + +variable "items" { + description = "Maps of items to create a wrapper from. Values are passed through to the module." + type = any + default = {} +} diff --git a/wrappers/deploy/versions.tf b/wrappers/deploy/versions.tf new file mode 100644 index 00000000..6b6318de --- /dev/null +++ b/wrappers/deploy/versions.tf @@ -0,0 +1,3 @@ +terraform { + required_version = ">= 0.13" +} diff --git a/wrappers/docker-build/main.tf b/wrappers/docker-build/main.tf new file mode 100644 index 00000000..e92cd2b6 --- /dev/null +++ b/wrappers/docker-build/main.tf @@ -0,0 +1,20 @@ +module "wrapper" { + source = "../../modules/docker-build" + + for_each = var.items + + create_ecr_repo = try(each.value.create_ecr_repo, var.defaults.create_ecr_repo, false) + ecr_address = try(each.value.ecr_address, var.defaults.ecr_address, null) + ecr_repo = try(each.value.ecr_repo, var.defaults.ecr_repo, null) + image_tag = try(each.value.image_tag, var.defaults.image_tag, null) + source_path = try(each.value.source_path, var.defaults.source_path, null) + docker_file_path = try(each.value.docker_file_path, var.defaults.docker_file_path, "Dockerfile") + image_tag_mutability = try(each.value.image_tag_mutability, var.defaults.image_tag_mutability, "MUTABLE") + scan_on_push = try(each.value.scan_on_push, var.defaults.scan_on_push, false) + ecr_force_delete = try(each.value.ecr_force_delete, var.defaults.ecr_force_delete, true) + ecr_repo_tags = try(each.value.ecr_repo_tags, var.defaults.ecr_repo_tags, {}) + build_args = try(each.value.build_args, var.defaults.build_args, {}) + ecr_repo_lifecycle_policy = try(each.value.ecr_repo_lifecycle_policy, var.defaults.ecr_repo_lifecycle_policy, null) + keep_remotely = try(each.value.keep_remotely, var.defaults.keep_remotely, false) + platform = try(each.value.platform, var.defaults.platform, null) +} diff --git a/wrappers/docker-build/outputs.tf b/wrappers/docker-build/outputs.tf new file mode 100644 index 00000000..ec6da5f4 --- /dev/null +++ b/wrappers/docker-build/outputs.tf @@ -0,0 +1,5 @@ +output "wrapper" { + description = "Map of outputs of a wrapper." + value = module.wrapper + # sensitive = false # No sensitive module output found +} diff --git a/wrappers/docker-build/variables.tf b/wrappers/docker-build/variables.tf new file mode 100644 index 00000000..a6ea0962 --- /dev/null +++ b/wrappers/docker-build/variables.tf @@ -0,0 +1,11 @@ +variable "defaults" { + description = "Map of default values which will be used for each item." + type = any + default = {} +} + +variable "items" { + description = "Maps of items to create a wrapper from. Values are passed through to the module." + type = any + default = {} +} diff --git a/wrappers/docker-build/versions.tf b/wrappers/docker-build/versions.tf new file mode 100644 index 00000000..6b6318de --- /dev/null +++ b/wrappers/docker-build/versions.tf @@ -0,0 +1,3 @@ +terraform { + required_version = ">= 0.13" +} diff --git a/wrappers/main.tf b/wrappers/main.tf new file mode 100644 index 00000000..69e09b81 --- /dev/null +++ b/wrappers/main.tf @@ -0,0 +1,121 @@ +module "wrapper" { + source = "../" + + for_each = var.items + + create = try(each.value.create, var.defaults.create, true) + create_package = try(each.value.create_package, var.defaults.create_package, true) + create_function = try(each.value.create_function, var.defaults.create_function, true) + create_layer = try(each.value.create_layer, var.defaults.create_layer, false) + create_role = try(each.value.create_role, var.defaults.create_role, true) + create_lambda_function_url = try(each.value.create_lambda_function_url, var.defaults.create_lambda_function_url, false) + putin_khuylo = try(each.value.putin_khuylo, var.defaults.putin_khuylo, true) + lambda_at_edge = try(each.value.lambda_at_edge, var.defaults.lambda_at_edge, false) + lambda_at_edge_logs_all_regions = try(each.value.lambda_at_edge_logs_all_regions, var.defaults.lambda_at_edge_logs_all_regions, true) + function_name = try(each.value.function_name, var.defaults.function_name, null) + handler = try(each.value.handler, var.defaults.handler, null) + runtime = try(each.value.runtime, var.defaults.runtime, null) + lambda_role = try(each.value.lambda_role, var.defaults.lambda_role, null) + description = try(each.value.description, var.defaults.description, null) + code_signing_config_arn = try(each.value.code_signing_config_arn, var.defaults.code_signing_config_arn, null) + layers = try(each.value.layers, var.defaults.layers, null) + architectures = try(each.value.architectures, var.defaults.architectures, null) + kms_key_arn = try(each.value.kms_key_arn, var.defaults.kms_key_arn, null) + memory_size = try(each.value.memory_size, var.defaults.memory_size, 128) + ephemeral_storage_size = try(each.value.ephemeral_storage_size, var.defaults.ephemeral_storage_size, 512) + publish = try(each.value.publish, var.defaults.publish, false) + reserved_concurrent_executions = try(each.value.reserved_concurrent_executions, var.defaults.reserved_concurrent_executions, -1) + timeout = try(each.value.timeout, var.defaults.timeout, 3) + dead_letter_target_arn = try(each.value.dead_letter_target_arn, var.defaults.dead_letter_target_arn, null) + environment_variables = try(each.value.environment_variables, var.defaults.environment_variables, {}) + tracing_mode = try(each.value.tracing_mode, var.defaults.tracing_mode, null) + vpc_subnet_ids = try(each.value.vpc_subnet_ids, var.defaults.vpc_subnet_ids, null) + vpc_security_group_ids = try(each.value.vpc_security_group_ids, var.defaults.vpc_security_group_ids, null) + tags = try(each.value.tags, var.defaults.tags, {}) + s3_object_tags = try(each.value.s3_object_tags, var.defaults.s3_object_tags, {}) + s3_object_tags_only = try(each.value.s3_object_tags_only, var.defaults.s3_object_tags_only, false) + package_type = try(each.value.package_type, var.defaults.package_type, "Zip") + image_uri = try(each.value.image_uri, var.defaults.image_uri, null) + image_config_entry_point = try(each.value.image_config_entry_point, var.defaults.image_config_entry_point, []) + image_config_command = try(each.value.image_config_command, var.defaults.image_config_command, []) + image_config_working_directory = try(each.value.image_config_working_directory, var.defaults.image_config_working_directory, null) + snap_start = try(each.value.snap_start, var.defaults.snap_start, false) + replace_security_groups_on_destroy = try(each.value.replace_security_groups_on_destroy, var.defaults.replace_security_groups_on_destroy, null) + replacement_security_group_ids = try(each.value.replacement_security_group_ids, var.defaults.replacement_security_group_ids, null) + create_unqualified_alias_lambda_function_url = try(each.value.create_unqualified_alias_lambda_function_url, var.defaults.create_unqualified_alias_lambda_function_url, true) + authorization_type = try(each.value.authorization_type, var.defaults.authorization_type, "NONE") + cors = try(each.value.cors, var.defaults.cors, {}) + invoke_mode = try(each.value.invoke_mode, var.defaults.invoke_mode, null) + layer_name = try(each.value.layer_name, var.defaults.layer_name, null) + layer_skip_destroy = try(each.value.layer_skip_destroy, var.defaults.layer_skip_destroy, false) + license_info = try(each.value.license_info, var.defaults.license_info, null) + compatible_runtimes = try(each.value.compatible_runtimes, var.defaults.compatible_runtimes, []) + compatible_architectures = try(each.value.compatible_architectures, var.defaults.compatible_architectures, null) + create_async_event_config = try(each.value.create_async_event_config, var.defaults.create_async_event_config, false) + create_current_version_async_event_config = try(each.value.create_current_version_async_event_config, var.defaults.create_current_version_async_event_config, true) + create_unqualified_alias_async_event_config = try(each.value.create_unqualified_alias_async_event_config, var.defaults.create_unqualified_alias_async_event_config, true) + maximum_event_age_in_seconds = try(each.value.maximum_event_age_in_seconds, var.defaults.maximum_event_age_in_seconds, null) + maximum_retry_attempts = try(each.value.maximum_retry_attempts, var.defaults.maximum_retry_attempts, null) + destination_on_failure = try(each.value.destination_on_failure, var.defaults.destination_on_failure, null) + destination_on_success = try(each.value.destination_on_success, var.defaults.destination_on_success, null) + provisioned_concurrent_executions = try(each.value.provisioned_concurrent_executions, var.defaults.provisioned_concurrent_executions, -1) + create_current_version_allowed_triggers = try(each.value.create_current_version_allowed_triggers, var.defaults.create_current_version_allowed_triggers, true) + create_unqualified_alias_allowed_triggers = try(each.value.create_unqualified_alias_allowed_triggers, var.defaults.create_unqualified_alias_allowed_triggers, true) + allowed_triggers = try(each.value.allowed_triggers, var.defaults.allowed_triggers, {}) + event_source_mapping = try(each.value.event_source_mapping, var.defaults.event_source_mapping, {}) + use_existing_cloudwatch_log_group = try(each.value.use_existing_cloudwatch_log_group, var.defaults.use_existing_cloudwatch_log_group, false) + cloudwatch_logs_retention_in_days = try(each.value.cloudwatch_logs_retention_in_days, var.defaults.cloudwatch_logs_retention_in_days, null) + cloudwatch_logs_kms_key_id = try(each.value.cloudwatch_logs_kms_key_id, var.defaults.cloudwatch_logs_kms_key_id, null) + cloudwatch_logs_tags = try(each.value.cloudwatch_logs_tags, var.defaults.cloudwatch_logs_tags, {}) + role_name = try(each.value.role_name, var.defaults.role_name, null) + role_description = try(each.value.role_description, var.defaults.role_description, null) + role_path = try(each.value.role_path, var.defaults.role_path, null) + role_force_detach_policies = try(each.value.role_force_detach_policies, var.defaults.role_force_detach_policies, true) + role_permissions_boundary = try(each.value.role_permissions_boundary, var.defaults.role_permissions_boundary, null) + role_tags = try(each.value.role_tags, var.defaults.role_tags, {}) + role_maximum_session_duration = try(each.value.role_maximum_session_duration, var.defaults.role_maximum_session_duration, 3600) + policy_name = try(each.value.policy_name, var.defaults.policy_name, null) + attach_cloudwatch_logs_policy = try(each.value.attach_cloudwatch_logs_policy, var.defaults.attach_cloudwatch_logs_policy, true) + attach_dead_letter_policy = try(each.value.attach_dead_letter_policy, var.defaults.attach_dead_letter_policy, false) + attach_network_policy = try(each.value.attach_network_policy, var.defaults.attach_network_policy, false) + attach_tracing_policy = try(each.value.attach_tracing_policy, var.defaults.attach_tracing_policy, false) + attach_async_event_policy = try(each.value.attach_async_event_policy, var.defaults.attach_async_event_policy, false) + attach_policy_json = try(each.value.attach_policy_json, var.defaults.attach_policy_json, false) + attach_policy_jsons = try(each.value.attach_policy_jsons, var.defaults.attach_policy_jsons, false) + attach_policy = try(each.value.attach_policy, var.defaults.attach_policy, false) + attach_policies = try(each.value.attach_policies, var.defaults.attach_policies, false) + policy_path = try(each.value.policy_path, var.defaults.policy_path, null) + number_of_policy_jsons = try(each.value.number_of_policy_jsons, var.defaults.number_of_policy_jsons, 0) + number_of_policies = try(each.value.number_of_policies, var.defaults.number_of_policies, 0) + attach_policy_statements = try(each.value.attach_policy_statements, var.defaults.attach_policy_statements, false) + trusted_entities = try(each.value.trusted_entities, var.defaults.trusted_entities, []) + assume_role_policy_statements = try(each.value.assume_role_policy_statements, var.defaults.assume_role_policy_statements, {}) + policy_json = try(each.value.policy_json, var.defaults.policy_json, null) + policy_jsons = try(each.value.policy_jsons, var.defaults.policy_jsons, []) + policy = try(each.value.policy, var.defaults.policy, null) + policies = try(each.value.policies, var.defaults.policies, []) + policy_statements = try(each.value.policy_statements, var.defaults.policy_statements, {}) + file_system_arn = try(each.value.file_system_arn, var.defaults.file_system_arn, null) + file_system_local_mount_path = try(each.value.file_system_local_mount_path, var.defaults.file_system_local_mount_path, null) + artifacts_dir = try(each.value.artifacts_dir, var.defaults.artifacts_dir, "builds") + s3_prefix = try(each.value.s3_prefix, var.defaults.s3_prefix, null) + ignore_source_code_hash = try(each.value.ignore_source_code_hash, var.defaults.ignore_source_code_hash, false) + local_existing_package = try(each.value.local_existing_package, var.defaults.local_existing_package, null) + s3_existing_package = try(each.value.s3_existing_package, var.defaults.s3_existing_package, null) + store_on_s3 = try(each.value.store_on_s3, var.defaults.store_on_s3, false) + s3_object_storage_class = try(each.value.s3_object_storage_class, var.defaults.s3_object_storage_class, "ONEZONE_IA") + s3_bucket = try(each.value.s3_bucket, var.defaults.s3_bucket, null) + s3_acl = try(each.value.s3_acl, var.defaults.s3_acl, "private") + s3_server_side_encryption = try(each.value.s3_server_side_encryption, var.defaults.s3_server_side_encryption, null) + source_path = try(each.value.source_path, var.defaults.source_path, null) + hash_extra = try(each.value.hash_extra, var.defaults.hash_extra, null) + build_in_docker = try(each.value.build_in_docker, var.defaults.build_in_docker, false) + docker_file = try(each.value.docker_file, var.defaults.docker_file, null) + docker_build_root = try(each.value.docker_build_root, var.defaults.docker_build_root, null) + docker_image = try(each.value.docker_image, var.defaults.docker_image, null) + docker_with_ssh_agent = try(each.value.docker_with_ssh_agent, var.defaults.docker_with_ssh_agent, false) + docker_pip_cache = try(each.value.docker_pip_cache, var.defaults.docker_pip_cache, null) + docker_additional_options = try(each.value.docker_additional_options, var.defaults.docker_additional_options, []) + docker_entrypoint = try(each.value.docker_entrypoint, var.defaults.docker_entrypoint, null) + recreate_missing_package = try(each.value.recreate_missing_package, var.defaults.recreate_missing_package, true) +} diff --git a/wrappers/outputs.tf b/wrappers/outputs.tf new file mode 100644 index 00000000..ec6da5f4 --- /dev/null +++ b/wrappers/outputs.tf @@ -0,0 +1,5 @@ +output "wrapper" { + description = "Map of outputs of a wrapper." + value = module.wrapper + # sensitive = false # No sensitive module output found +} diff --git a/wrappers/variables.tf b/wrappers/variables.tf new file mode 100644 index 00000000..a6ea0962 --- /dev/null +++ b/wrappers/variables.tf @@ -0,0 +1,11 @@ +variable "defaults" { + description = "Map of default values which will be used for each item." + type = any + default = {} +} + +variable "items" { + description = "Maps of items to create a wrapper from. Values are passed through to the module." + type = any + default = {} +} diff --git a/wrappers/versions.tf b/wrappers/versions.tf new file mode 100644 index 00000000..6b6318de --- /dev/null +++ b/wrappers/versions.tf @@ -0,0 +1,3 @@ +terraform { + required_version = ">= 0.13" +} From 94910671b5ad96fd9a776d3b2057123c9c2cc89f Mon Sep 17 00:00:00 2001 From: Matheus Mazzoni Date: Tue, 4 Jul 2023 20:44:27 -0300 Subject: [PATCH 2/2] docs: create wrappers documentation --- wrappers/README.md | 106 +++++++++++++++++++++++++ wrappers/alias/README.md | 103 ++++++++++++++++++++++++ wrappers/deploy/README.md | 134 ++++++++++++++++++++++++++++++++ wrappers/docker-build/README.md | 109 ++++++++++++++++++++++++++ 4 files changed, 452 insertions(+) create mode 100644 wrappers/README.md create mode 100644 wrappers/alias/README.md create mode 100644 wrappers/deploy/README.md create mode 100644 wrappers/docker-build/README.md diff --git a/wrappers/README.md b/wrappers/README.md new file mode 100644 index 00000000..9100f135 --- /dev/null +++ b/wrappers/README.md @@ -0,0 +1,106 @@ +# Wrapper for the root module + +The configuration in this directory contains an implementation of a single module wrapper pattern, which allows managing several copies of a module in places where using the native Terraform 0.13+ `for_each` feature is not feasible (e.g., with Terragrunt). + +You may want to use a single Terragrunt configuration file to manage multiple resources without duplicating `terragrunt.hcl` files for each copy of the same module. + +This wrapper does not implement any extra functionality. + +## Usage with Terragrunt + +`terragrunt.hcl`: + +```hcl +terraform { + source = "tfr:///terraform-aws-modules/lambda/aws//wrappers" + # Alternative source: + # source = "git::git@github.com:terraform-aws-modules/terraform-aws-lambda.git//wrappers?ref=master" +} + +inputs = { + defaults = { # Default values + create = true + handler = "index.lambda_handler" + runtime = "python3.8" + tags = { + Terraform = "true" + Environment = "dev" + } + } + + items = { + my-item = { + # omitted... can be any argument supported by the module + } + my-second-item = { + # omitted... can be any argument supported by the module + } + # omitted... + } +} +``` + +## Usage with Terraform + +```hcl +module "wrapper" { + source = "terraform-aws-modules/lambda/aws//wrappers" + + defaults = { # Default values + create = true + handler = "index.lambda_handler" + runtime = "python3.8" + tags = { + Terraform = "true" + Environment = "dev" + } + } + + items = { + my-item = { + # omitted... can be any argument supported by the module + } + my-second-item = { + # omitted... can be any argument supported by the module + } + # omitted... + } +} +``` + +## Example: Manage multiple Lambdas in one Terragrunt layer + +`eu-west-1/lambdas/terragrunt.hcl`: + +```hcl +terraform { + source = "tfr:///terraform-aws-modules/lambda/aws//wrappers" + # Alternative source: + # source = "git::git@github.com:terraform-aws-modules/terraform-aws-lambda.git//wrappers?ref=master" +} + +inputs = { + defaults = { + create = true + handler = "index.lambda_handler" + runtime = "python3.8" + tags = { + Terraform = "true" + Environment = "dev" + } + } + + items = { + lambda1 = { + function_name = "my-lambda1" + description = "My awesome lambda function"\ + source_path = "../src/lambda-function1" + } + lambda2 = { + function_name = "my-lambda2" + description = "My second awesome lambda function" + source_path = "../src/lambda-function2" + } + } +} +``` diff --git a/wrappers/alias/README.md b/wrappers/alias/README.md new file mode 100644 index 00000000..3f2b5013 --- /dev/null +++ b/wrappers/alias/README.md @@ -0,0 +1,103 @@ +# Wrapper for module: `modules/alias` + +The configuration in this directory contains an implementation of a single module wrapper pattern, which allows managing several copies of a module in places where using the native Terraform 0.13+ `for_each` feature is not feasible (e.g., with Terragrunt). + +You may want to use a single Terragrunt configuration file to manage multiple resources without duplicating `terragrunt.hcl` files for each copy of the same module. + +This wrapper does not implement any extra functionality. + +## Usage with Terragrunt + +`terragrunt.hcl`: + +```hcl +terraform { + source = "tfr:///terraform-aws-modules/lambda/aws" + # Alternative source: + # source = "git::git@github.com:terraform-aws-modules/terraform-aws-lambda.git//wrappers/alias?ref=master" +} + +inputs = { + defaults = { # Default values + create = true + refresh_alias = true + } + + items = { + my-item = { + # omitted... can be any argument supported by the module + } + my-second-item = { + # omitted... can be any argument supported by the module + } + # omitted... + } +} +``` + +## Usage with Terraform + +```hcl +module "wrapper" { + source = "terraform-aws-modules/lambda/aws//wrappers/alias" + + defaults = { # Default values + create = true + refresh_alias = true + } + + items = { + my-item = { + # omitted... can be any argument supported by the module + } + my-second-item = { + # omitted... can be any argument supported by the module + } + # omitted... + } +} +``` + +## Example: Manage multiple aliases in one Terragrunt layer + +`eu-west-1/lambda-aliases/terragrunt.hcl`: + +```hcl +terraform { + source = "tfr:///terraform-aws-modules/lambda/aws//wrappers/alias" + # Alternative source: + # source = "git::git@github.com:terraform-aws-modules/terraform-aws-lambda.git//wrappers/alias?ref=master" +} + +dependency "lambda1" { + config_path = "../lambdas/lambda1" +} +dependency "lambda2" { + config_path = "../lambdas/lambda2" +} + +inputs = { + defaults = { + refresh_alias = true + allowed_triggers = { + AnotherAPIGatewayAny = { + service = "apigateway" + source_arn = "arn:aws:execute-api:eu-west-1:135367859851:abcdedfgse/*/*/*" + } + } + } + + items = { + alias1 = { + name = "my-random-alias-1" + function_name = dependency.lambda1.outputs.lambda_function_name + function_version = dependency.lambda1.outputs.lambda_function_version + } + alias2 = { + name = "my-random-alias-2" + function_name = dependency.lambda2.outputs.lambda_function_name + function_version = dependency.lambda2.outputs.lambda_function_version + } + } +} +``` diff --git a/wrappers/deploy/README.md b/wrappers/deploy/README.md new file mode 100644 index 00000000..699ae062 --- /dev/null +++ b/wrappers/deploy/README.md @@ -0,0 +1,134 @@ +# Wrapper for module: `modules/deploy` + +The configuration in this directory contains an implementation of a single module wrapper pattern, which allows managing several copies of a module in places where using the native Terraform 0.13+ `for_each` feature is not feasible (e.g., with Terragrunt). + +You may want to use a single Terragrunt configuration file to manage multiple resources without duplicating `terragrunt.hcl` files for each copy of the same module. + +This wrapper does not implement any extra functionality. + +## Usage with Terragrunt + +`terragrunt.hcl`: + +```hcl +terraform { + source = "tfr:///terraform-aws-modules/lambda/aws//wrappers/deploy" + # Alternative source: + # source = "git::git@github.com:terraform-aws-modules/terraform-aws-lambda.git//wrappers/deploy?ref=master" +} + +inputs = { + defaults = { # Default values + create_app = true + tags = { + Terraform = "true" + Environment = "dev" + } + } + + items = { + my-item = { + # omitted... can be any argument supported by the module + } + my-second-item = { + # omitted... can be any argument supported by the module + } + # omitted... + } +} +``` + +## Usage with Terraform + +```hcl +module "wrapper" { + source = "terraform-aws-modules/lambda/aws//wrappers/deploy" + + defaults = { # Default values + create_app = true + tags = { + Terraform = "true" + Environment = "dev" + } + } + + items = { + my-item = { + # omitted... can be any argument supported by the module + } + my-second-item = { + # omitted... can be any argument supported by the module + } + # omitted... + } +} +``` + +## Example: Manage multiple deployment via AWS CodeDeploy in one Terragrunt layer + +`eu-west-1/lambda-deploys/terragrunt.hcl`: + +```hcl +terraform { + source = "tfr:///terraform-aws-modules/lambda/aws//wrappers/deploy" + # Alternative source: + # source = "git::git@github.com:terraform-aws-modules/terraform-aws-lambda.git//wrappers/deploy?ref=master" +} + +dependency "aliases" { + config_path = "../lambdas-aliases/" +} +dependency "lambda1" { + config_path = "../lambdas/lambda1" +} +dependency "lambda2" { + config_path = "../lambdas/lambda2" +} + +inputs = { + defaults = { + create_app = true + reate_deployment_group = true + create_deployment = true + run_deployment = true + wait_deployment_completion = true + + triggers = { + start = { + events = ["DeploymentStart"] + name = "DeploymentStart" + target_arn = "arn:aws:sns:eu-west-1:135367859851:sns1" + } + success = { + events = ["DeploymentSuccess"] + name = "DeploymentSuccess" + target_arn = "arn:aws:sns:eu-west-1:135367859851:sns2" + } + } + + tags = { + Terraform = "true" + Environment = "dev" + } + } + + items = { + deploy1 = { + app_name = "my-random-app-1" + deployment_group_name = "something1" + + alias_name = dependency.aliases.outputs.wrapper.alias1.lambda_alias_name + function_name = dependency.lambda1.outputs.lambda_function_name + target_version = dependency.lambda1.outputs.lambda_function_version + } + deploy2 = { + app_name = "my-random-app-2" + deployment_group_name = "something2" + + alias_name = dependency.aliases.outputs.wrapper.alias2.lambda_alias_name + function_name = dependency.lambda2.outputs.lambda_function_name + target_version = dependency.lambda2.outputs.lambda_function_version + } + } +} +``` diff --git a/wrappers/docker-build/README.md b/wrappers/docker-build/README.md new file mode 100644 index 00000000..8d55dd6a --- /dev/null +++ b/wrappers/docker-build/README.md @@ -0,0 +1,109 @@ +# Wrapper for module: `modules/docker-build` + +The configuration in this directory contains an implementation of a single module wrapper pattern, which allows managing several copies of a module in places where using the native Terraform 0.13+ `for_each` feature is not feasible (e.g., with Terragrunt). + +You may want to use a single Terragrunt configuration file to manage multiple resources without duplicating `terragrunt.hcl` files for each copy of the same module. + +This wrapper does not implement any extra functionality. + +## Usage with Terragrunt + +`terragrunt.hcl`: + +```hcl +terraform { + source = "tfr:///terraform-aws-modules/lambda/aws//wrappers/docker-build" + # Alternative source: + # source = "git::git@github.com:terraform-aws-modules/terraform-aws-lambda.git//wrappers/docker-build?ref=master" +} + +inputs = { + defaults = { # Default values + create_ecr_repo = true + } + + items = { + my-item = { + # omitted... can be any argument supported by the module + } + my-second-item = { + # omitted... can be any argument supported by the module + } + # omitted... + } +} +``` + +## Usage with Terraform + +```hcl +module "wrapper" { + source = "terraform-aws-modules/lambda/aws//wrappers/docker-build" + + defaults = { # Default values + create_ecr_repo = true + } + + items = { + my-item = { + # omitted... can be any argument supported by the module + } + my-second-item = { + # omitted... can be any argument supported by the module + } + # omitted... + } +} +``` + +## Example: Manage multiple Docker Container Image in one Terragrunt layer + +`eu-west-1/docker-builds/terragrunt.hcl`: + +```hcl +terraform { + source = "tfr:///terraform-aws-modules/lambda/aws//wrappers" + # Alternative source: + # source = "git::git@github.com:terraform-aws-modules/terraform-aws-lambda.git//wrappers?ref=master" +} + +# Generate an Docker provider block +generate "provider" { + path = "provider.tf" + if_exists = "overwrite" + contents = <