forked from terraform-aws-modules/terraform-aws-ec2-instance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
88 lines (73 loc) · 3.81 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
locals {
is_t_instance_type = "${replace(var.instance_type, "/^t[23]{1}\\..*$/", "1") == "1" ? "1" : "0"}"
}
######
# Note: network_interface can't be specified together with associate_public_ip_address
######
resource "aws_instance" "this" {
count = "${var.instance_count * (1 - local.is_t_instance_type)}"
ami = "${var.ami}"
instance_type = "${var.instance_type}"
user_data = "${var.user_data}"
subnet_id = "${var.subnet_id}"
key_name = "${var.key_name}"
monitoring = "${var.monitoring}"
vpc_security_group_ids = ["${var.vpc_security_group_ids}"]
iam_instance_profile = "${var.iam_instance_profile}"
associate_public_ip_address = "${var.associate_public_ip_address}"
private_ip = "${var.private_ip}"
ipv6_address_count = "${var.ipv6_address_count}"
ipv6_addresses = "${var.ipv6_addresses}"
ebs_optimized = "${var.ebs_optimized}"
volume_tags = "${var.volume_tags}"
root_block_device = "${var.root_block_device}"
ebs_block_device = "${var.ebs_block_device}"
ephemeral_block_device = "${var.ephemeral_block_device}"
source_dest_check = "${var.source_dest_check}"
disable_api_termination = "${var.disable_api_termination}"
instance_initiated_shutdown_behavior = "${var.instance_initiated_shutdown_behavior}"
placement_group = "${var.placement_group}"
tenancy = "${var.tenancy}"
tags = "${merge(var.tags, map("Name", var.instance_count > 1 ? format("%s-%d", var.name, count.index+1) : var.name))}"
lifecycle {
# Due to several known issues in Terraform AWS provider related to arguments of aws_instance:
# (eg, https://github.com/terraform-providers/terraform-provider-aws/issues/2036)
# we have to ignore changes in the following arguments
ignore_changes = ["private_ip", "root_block_device", "ebs_block_device"]
}
}
resource "aws_instance" "this_t2" {
count = "${var.instance_count * local.is_t_instance_type}"
ami = "${var.ami}"
instance_type = "${var.instance_type}"
user_data = "${var.user_data}"
subnet_id = "${var.subnet_id}"
key_name = "${var.key_name}"
monitoring = "${var.monitoring}"
vpc_security_group_ids = ["${var.vpc_security_group_ids}"]
iam_instance_profile = "${var.iam_instance_profile}"
associate_public_ip_address = "${var.associate_public_ip_address}"
private_ip = "${var.private_ip}"
ipv6_address_count = "${var.ipv6_address_count}"
ipv6_addresses = "${var.ipv6_addresses}"
ebs_optimized = "${var.ebs_optimized}"
volume_tags = "${var.volume_tags}"
root_block_device = "${var.root_block_device}"
ebs_block_device = "${var.ebs_block_device}"
ephemeral_block_device = "${var.ephemeral_block_device}"
source_dest_check = "${var.source_dest_check}"
disable_api_termination = "${var.disable_api_termination}"
instance_initiated_shutdown_behavior = "${var.instance_initiated_shutdown_behavior}"
placement_group = "${var.placement_group}"
tenancy = "${var.tenancy}"
credit_specification {
cpu_credits = "${var.cpu_credits}"
}
tags = "${merge(var.tags, map("Name", var.instance_count > 1 ? format("%s-%d", var.name, count.index+1) : var.name))}"
lifecycle {
# Due to several known issues in Terraform AWS provider related to arguments of aws_instance:
# (eg, https://github.com/terraform-providers/terraform-provider-aws/issues/2036)
# we have to ignore changes in the following arguments
ignore_changes = ["private_ip", "root_block_device", "ebs_block_device"]
}
}