94 lines
4.1 KiB
Terraform
94 lines
4.1 KiB
Terraform
resource "aws_key_pair" "amazon" {
|
|
region = var.region
|
|
|
|
key_name = local.key_pair_name
|
|
public_key = var.key_pair.public_key
|
|
tags = var.key_pair.tags
|
|
|
|
lifecycle {
|
|
# Provider 6.73 cannot read public key material during refresh and would
|
|
# otherwise plan a replacement immediately after import.
|
|
ignore_changes = [public_key]
|
|
}
|
|
}
|
|
|
|
resource "aws_instance" "web_protected" {
|
|
count = var.protect_from_destroy ? 1 : 0
|
|
|
|
region = var.region
|
|
ami = var.web_instance.ami
|
|
instance_type = var.web_instance.instance_type
|
|
subnet_id = local.subnet_ids[var.web_instance.subnet_key]
|
|
vpc_security_group_ids = [aws_security_group.web.id]
|
|
key_name = aws_key_pair.amazon.key_name
|
|
associate_public_ip_address = var.web_instance.associate_public_ip_address
|
|
source_dest_check = var.web_instance.source_dest_check
|
|
ebs_optimized = var.web_instance.ebs_optimized
|
|
monitoring = var.web_instance.monitoring
|
|
|
|
metadata_options {
|
|
http_endpoint = var.web_instance.metadata_options.http_endpoint
|
|
http_tokens = var.web_instance.metadata_options.http_tokens
|
|
http_put_response_hop_limit = var.web_instance.metadata_options.http_put_response_hop_limit
|
|
http_protocol_ipv6 = var.web_instance.metadata_options.http_protocol_ipv6
|
|
instance_metadata_tags = var.web_instance.metadata_options.instance_metadata_tags
|
|
}
|
|
|
|
root_block_device {
|
|
delete_on_termination = var.web_instance.root_block_device.delete_on_termination
|
|
encrypted = var.web_instance.root_block_device.encrypted
|
|
volume_size = var.web_instance.root_block_device.volume_size
|
|
volume_type = var.web_instance.root_block_device.volume_type
|
|
iops = var.web_instance.root_block_device.iops
|
|
throughput = var.web_instance.root_block_device.throughput
|
|
}
|
|
|
|
tags = merge(var.web_instance.tags, { Name = local.web_instance_name })
|
|
|
|
lifecycle {
|
|
prevent_destroy = true
|
|
# AMI and user data are intentionally managed outside this import. The
|
|
# provider still reads user data during import/refresh and stores it in
|
|
# state; ignore_changes only suppresses drift and does not hide the value.
|
|
ignore_changes = [ami, user_data, user_data_base64]
|
|
}
|
|
}
|
|
|
|
resource "aws_instance" "web_unprotected" {
|
|
count = var.protect_from_destroy ? 0 : 1
|
|
|
|
region = var.region
|
|
ami = var.web_instance.ami
|
|
instance_type = var.web_instance.instance_type
|
|
subnet_id = local.subnet_ids[var.web_instance.subnet_key]
|
|
vpc_security_group_ids = [aws_security_group.web.id]
|
|
key_name = aws_key_pair.amazon.key_name
|
|
associate_public_ip_address = var.web_instance.associate_public_ip_address
|
|
source_dest_check = var.web_instance.source_dest_check
|
|
ebs_optimized = var.web_instance.ebs_optimized
|
|
monitoring = var.web_instance.monitoring
|
|
|
|
metadata_options {
|
|
http_endpoint = var.web_instance.metadata_options.http_endpoint
|
|
http_tokens = var.web_instance.metadata_options.http_tokens
|
|
http_put_response_hop_limit = var.web_instance.metadata_options.http_put_response_hop_limit
|
|
http_protocol_ipv6 = var.web_instance.metadata_options.http_protocol_ipv6
|
|
instance_metadata_tags = var.web_instance.metadata_options.instance_metadata_tags
|
|
}
|
|
|
|
root_block_device {
|
|
delete_on_termination = var.web_instance.root_block_device.delete_on_termination
|
|
encrypted = var.web_instance.root_block_device.encrypted
|
|
volume_size = var.web_instance.root_block_device.volume_size
|
|
volume_type = var.web_instance.root_block_device.volume_type
|
|
iops = var.web_instance.root_block_device.iops
|
|
throughput = var.web_instance.root_block_device.throughput
|
|
}
|
|
|
|
tags = merge(var.web_instance.tags, { Name = local.web_instance_name })
|
|
|
|
lifecycle {
|
|
ignore_changes = [ami, user_data, user_data_base64]
|
|
}
|
|
}
|