From d3520fd9afc35a2598604e4219ade15021960ba9 Mon Sep 17 00:00:00 2001 From: Dmitry Yurchenko Date: Mon, 25 Dec 2023 16:48:20 +0300 Subject: [PATCH] feat: Support Private DNS name options (#370) Co-authored-by: Bryant Biggs --- .pre-commit-config.yaml | 4 +-- README.md | 1 + main.tf | 20 ++++++++++++++ variables.tf | 6 ++++ wrappers/main.tf | 61 +++++++++++++++++++++-------------------- 5 files changed, 60 insertions(+), 32 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 762423e1..61ef1782 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/antonbabenko/pre-commit-terraform - rev: v1.83.0 + rev: v1.86.0 hooks: - id: terraform_fmt - id: terraform_wrapper_module_for_each @@ -24,7 +24,7 @@ repos: - '--args=--only=terraform_standard_module_structure' - '--args=--only=terraform_workspace_remote' - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-merge-conflict - id: end-of-file-fixer diff --git a/README.md b/README.md index 54c21f6d..8f22cb7d 100644 --- a/README.md +++ b/README.md @@ -237,6 +237,7 @@ No modules. | [name](#input\_name) | Name to be used on EC2 instance created | `string` | `""` | no | | [network\_interface](#input\_network\_interface) | Customize network interfaces to be attached at instance boot time | `list(map(string))` | `[]` | no | | [placement\_group](#input\_placement\_group) | The Placement Group to start the instance in | `string` | `null` | no | +| [private\_dns\_name\_options](#input\_private\_dns\_name\_options) | Customize the private DNS name options of the instance | `map(string)` | `{}` | no | | [private\_ip](#input\_private\_ip) | Private IP address to associate with the instance in a VPC | `string` | `null` | no | | [putin\_khuylo](#input\_putin\_khuylo) | Do you agree that Putin doesn't respect Ukrainian sovereignty and territorial integrity? More info: https://en.wikipedia.org/wiki/Putin_khuylo! | `bool` | `true` | no | | [root\_block\_device](#input\_root\_block\_device) | Customize details about the root block device of the instance. See Block Devices below for details | `list(any)` | `[]` | no | diff --git a/main.tf b/main.tf index 91ab79a8..2f291307 100644 --- a/main.tf +++ b/main.tf @@ -138,6 +138,16 @@ resource "aws_instance" "this" { } } + dynamic "private_dns_name_options" { + for_each = length(var.private_dns_name_options) > 0 ? [var.private_dns_name_options] : [] + + content { + hostname_type = try(private_dns_name_options.value.hostname_type, null) + enable_resource_name_dns_a_record = try(private_dns_name_options.value.enable_resource_name_dns_a_record, null) + enable_resource_name_dns_aaaa_record = try(private_dns_name_options.value.enable_resource_name_dns_aaaa_record, null) + } + } + dynamic "launch_template" { for_each = length(var.launch_template) > 0 ? [var.launch_template] : [] @@ -306,6 +316,16 @@ resource "aws_instance" "ignore_ami" { } } + dynamic "private_dns_name_options" { + for_each = length(var.private_dns_name_options) > 0 ? [var.private_dns_name_options] : [] + + content { + hostname_type = try(private_dns_name_options.value.hostname_type, null) + enable_resource_name_dns_a_record = try(private_dns_name_options.value.enable_resource_name_dns_a_record, null) + enable_resource_name_dns_aaaa_record = try(private_dns_name_options.value.enable_resource_name_dns_aaaa_record, null) + } + } + dynamic "launch_template" { for_each = length(var.launch_template) > 0 ? [var.launch_template] : [] diff --git a/variables.tf b/variables.tf index a05e3043..d5b8bc0e 100644 --- a/variables.tf +++ b/variables.tf @@ -176,6 +176,12 @@ variable "network_interface" { default = [] } +variable "private_dns_name_options" { + description = "Customize the private DNS name options of the instance" + type = map(string) + default = {} +} + variable "placement_group" { description = "The Placement Group to start the instance in" type = string diff --git a/wrappers/main.tf b/wrappers/main.tf index c6639eed..494d2cbc 100644 --- a/wrappers/main.tf +++ b/wrappers/main.tf @@ -3,74 +3,75 @@ module "wrapper" { for_each = var.items - create = try(each.value.create, var.defaults.create, true) - name = try(each.value.name, var.defaults.name, "") - ami_ssm_parameter = try(each.value.ami_ssm_parameter, var.defaults.ami_ssm_parameter, "/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2") ami = try(each.value.ami, var.defaults.ami, null) - ignore_ami_changes = try(each.value.ignore_ami_changes, var.defaults.ignore_ami_changes, false) + ami_ssm_parameter = try(each.value.ami_ssm_parameter, var.defaults.ami_ssm_parameter, "/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2") associate_public_ip_address = try(each.value.associate_public_ip_address, var.defaults.associate_public_ip_address, null) - maintenance_options = try(each.value.maintenance_options, var.defaults.maintenance_options, {}) availability_zone = try(each.value.availability_zone, var.defaults.availability_zone, null) capacity_reservation_specification = try(each.value.capacity_reservation_specification, var.defaults.capacity_reservation_specification, {}) + cpu_core_count = try(each.value.cpu_core_count, var.defaults.cpu_core_count, null) cpu_credits = try(each.value.cpu_credits, var.defaults.cpu_credits, null) + cpu_options = try(each.value.cpu_options, var.defaults.cpu_options, {}) + cpu_threads_per_core = try(each.value.cpu_threads_per_core, var.defaults.cpu_threads_per_core, null) + create = try(each.value.create, var.defaults.create, true) + create_iam_instance_profile = try(each.value.create_iam_instance_profile, var.defaults.create_iam_instance_profile, false) + create_spot_instance = try(each.value.create_spot_instance, var.defaults.create_spot_instance, false) + disable_api_stop = try(each.value.disable_api_stop, var.defaults.disable_api_stop, null) disable_api_termination = try(each.value.disable_api_termination, var.defaults.disable_api_termination, null) ebs_block_device = try(each.value.ebs_block_device, var.defaults.ebs_block_device, []) ebs_optimized = try(each.value.ebs_optimized, var.defaults.ebs_optimized, null) + enable_volume_tags = try(each.value.enable_volume_tags, var.defaults.enable_volume_tags, true) enclave_options_enabled = try(each.value.enclave_options_enabled, var.defaults.enclave_options_enabled, null) ephemeral_block_device = try(each.value.ephemeral_block_device, var.defaults.ephemeral_block_device, []) get_password_data = try(each.value.get_password_data, var.defaults.get_password_data, null) hibernation = try(each.value.hibernation, var.defaults.hibernation, null) host_id = try(each.value.host_id, var.defaults.host_id, null) iam_instance_profile = try(each.value.iam_instance_profile, var.defaults.iam_instance_profile, null) + iam_role_description = try(each.value.iam_role_description, var.defaults.iam_role_description, null) + iam_role_name = try(each.value.iam_role_name, var.defaults.iam_role_name, null) + iam_role_path = try(each.value.iam_role_path, var.defaults.iam_role_path, null) + iam_role_permissions_boundary = try(each.value.iam_role_permissions_boundary, var.defaults.iam_role_permissions_boundary, null) + iam_role_policies = try(each.value.iam_role_policies, var.defaults.iam_role_policies, {}) + iam_role_tags = try(each.value.iam_role_tags, var.defaults.iam_role_tags, {}) + iam_role_use_name_prefix = try(each.value.iam_role_use_name_prefix, var.defaults.iam_role_use_name_prefix, true) + ignore_ami_changes = try(each.value.ignore_ami_changes, var.defaults.ignore_ami_changes, false) instance_initiated_shutdown_behavior = try(each.value.instance_initiated_shutdown_behavior, var.defaults.instance_initiated_shutdown_behavior, null) - instance_type = try(each.value.instance_type, var.defaults.instance_type, "t3.micro") instance_tags = try(each.value.instance_tags, var.defaults.instance_tags, {}) + instance_type = try(each.value.instance_type, var.defaults.instance_type, "t3.micro") ipv6_address_count = try(each.value.ipv6_address_count, var.defaults.ipv6_address_count, null) ipv6_addresses = try(each.value.ipv6_addresses, var.defaults.ipv6_addresses, null) key_name = try(each.value.key_name, var.defaults.key_name, null) launch_template = try(each.value.launch_template, var.defaults.launch_template, {}) + maintenance_options = try(each.value.maintenance_options, var.defaults.maintenance_options, {}) metadata_options = try(each.value.metadata_options, var.defaults.metadata_options, { "http_endpoint" = "enabled" "http_put_response_hop_limit" = 1 "http_tokens" = "optional" }) monitoring = try(each.value.monitoring, var.defaults.monitoring, null) + name = try(each.value.name, var.defaults.name, "") network_interface = try(each.value.network_interface, var.defaults.network_interface, []) placement_group = try(each.value.placement_group, var.defaults.placement_group, null) + private_dns_name_options = try(each.value.private_dns_name_options, var.defaults.private_dns_name_options, {}) private_ip = try(each.value.private_ip, var.defaults.private_ip, null) + putin_khuylo = try(each.value.putin_khuylo, var.defaults.putin_khuylo, true) root_block_device = try(each.value.root_block_device, var.defaults.root_block_device, []) secondary_private_ips = try(each.value.secondary_private_ips, var.defaults.secondary_private_ips, null) source_dest_check = try(each.value.source_dest_check, var.defaults.source_dest_check, null) + spot_block_duration_minutes = try(each.value.spot_block_duration_minutes, var.defaults.spot_block_duration_minutes, null) + spot_instance_interruption_behavior = try(each.value.spot_instance_interruption_behavior, var.defaults.spot_instance_interruption_behavior, null) + spot_launch_group = try(each.value.spot_launch_group, var.defaults.spot_launch_group, null) + spot_price = try(each.value.spot_price, var.defaults.spot_price, null) + spot_type = try(each.value.spot_type, var.defaults.spot_type, null) + spot_valid_from = try(each.value.spot_valid_from, var.defaults.spot_valid_from, null) + spot_valid_until = try(each.value.spot_valid_until, var.defaults.spot_valid_until, null) + spot_wait_for_fulfillment = try(each.value.spot_wait_for_fulfillment, var.defaults.spot_wait_for_fulfillment, null) subnet_id = try(each.value.subnet_id, var.defaults.subnet_id, null) tags = try(each.value.tags, var.defaults.tags, {}) tenancy = try(each.value.tenancy, var.defaults.tenancy, null) + timeouts = try(each.value.timeouts, var.defaults.timeouts, {}) user_data = try(each.value.user_data, var.defaults.user_data, null) user_data_base64 = try(each.value.user_data_base64, var.defaults.user_data_base64, null) user_data_replace_on_change = try(each.value.user_data_replace_on_change, var.defaults.user_data_replace_on_change, null) volume_tags = try(each.value.volume_tags, var.defaults.volume_tags, {}) - enable_volume_tags = try(each.value.enable_volume_tags, var.defaults.enable_volume_tags, true) vpc_security_group_ids = try(each.value.vpc_security_group_ids, var.defaults.vpc_security_group_ids, null) - timeouts = try(each.value.timeouts, var.defaults.timeouts, {}) - cpu_options = try(each.value.cpu_options, var.defaults.cpu_options, {}) - cpu_core_count = try(each.value.cpu_core_count, var.defaults.cpu_core_count, null) - cpu_threads_per_core = try(each.value.cpu_threads_per_core, var.defaults.cpu_threads_per_core, null) - create_spot_instance = try(each.value.create_spot_instance, var.defaults.create_spot_instance, false) - spot_price = try(each.value.spot_price, var.defaults.spot_price, null) - spot_wait_for_fulfillment = try(each.value.spot_wait_for_fulfillment, var.defaults.spot_wait_for_fulfillment, null) - spot_type = try(each.value.spot_type, var.defaults.spot_type, null) - spot_launch_group = try(each.value.spot_launch_group, var.defaults.spot_launch_group, null) - spot_block_duration_minutes = try(each.value.spot_block_duration_minutes, var.defaults.spot_block_duration_minutes, null) - spot_instance_interruption_behavior = try(each.value.spot_instance_interruption_behavior, var.defaults.spot_instance_interruption_behavior, null) - spot_valid_until = try(each.value.spot_valid_until, var.defaults.spot_valid_until, null) - spot_valid_from = try(each.value.spot_valid_from, var.defaults.spot_valid_from, null) - disable_api_stop = try(each.value.disable_api_stop, var.defaults.disable_api_stop, null) - putin_khuylo = try(each.value.putin_khuylo, var.defaults.putin_khuylo, true) - create_iam_instance_profile = try(each.value.create_iam_instance_profile, var.defaults.create_iam_instance_profile, false) - iam_role_name = try(each.value.iam_role_name, var.defaults.iam_role_name, null) - iam_role_use_name_prefix = try(each.value.iam_role_use_name_prefix, var.defaults.iam_role_use_name_prefix, true) - iam_role_path = try(each.value.iam_role_path, var.defaults.iam_role_path, null) - iam_role_description = try(each.value.iam_role_description, var.defaults.iam_role_description, null) - iam_role_permissions_boundary = try(each.value.iam_role_permissions_boundary, var.defaults.iam_role_permissions_boundary, null) - iam_role_policies = try(each.value.iam_role_policies, var.defaults.iam_role_policies, {}) - iam_role_tags = try(each.value.iam_role_tags, var.defaults.iam_role_tags, {}) }