1
1
locals {
2
- is_t_instance_type = replace (var. instance_type , " /^t[23]{1}\\ ..*$/" , " 1" ) == " 1" ? 1 : 0
3
-
4
- instance_count = var. instance_count * (1 - local. is_t_instance_type )
5
- t_instance_count = var. instance_count * local. is_t_instance_type
2
+ is_t_instance_type = replace (var. instance_type , " /^t[23]{1}\\ ..*$/" , " 1" ) == " 1" ? true : false
6
3
}
7
4
8
5
# #####
9
6
# Note: network_interface can't be specified together with associate_public_ip_address
10
7
# #####
11
8
resource "aws_instance" "this" {
12
- count = local . instance_count > 0 ? local . instance_count : 0
9
+ count = var . instance_count
13
10
14
11
ami = var. ami
15
12
instance_type = var. instance_type
@@ -83,96 +80,10 @@ resource "aws_instance" "this" {
83
80
var. volume_tags ,
84
81
)
85
82
86
- lifecycle {
87
- # Due to several known issues in Terraform AWS provider related to arguments of aws_instance:
88
- # (eg, https://github.com/terraform-providers/terraform-provider-aws/issues/2036)
89
- # we have to ignore changes in the following arguments
90
- ignore_changes = [
91
- root_block_device ,
92
- ebs_block_device ,
93
- ]
94
- }
95
- }
96
-
97
- resource "aws_instance" "this_t2" {
98
- count = local. t_instance_count > 0 ? local. t_instance_count : 0
99
-
100
- ami = var. ami
101
- instance_type = var. instance_type
102
- user_data = var. user_data
103
- subnet_id = element (
104
- distinct (compact (concat ([var . subnet_id ], var. subnet_ids ))),
105
- count. index ,
106
- )
107
- key_name = var. key_name
108
- monitoring = var. monitoring
109
- get_password_data = var. get_password_data
110
- vpc_security_group_ids = var. vpc_security_group_ids
111
- iam_instance_profile = var. iam_instance_profile
112
-
113
- associate_public_ip_address = var. associate_public_ip_address
114
- private_ip = length (var. private_ips ) > 0 ? element (var. private_ips , count. index ) : var. private_ip
115
- ipv6_address_count = var. ipv6_address_count
116
- ipv6_addresses = var. ipv6_addresses
117
-
118
- ebs_optimized = var. ebs_optimized
119
-
120
- dynamic "root_block_device" {
121
- for_each = var. root_block_device
122
- content {
123
- delete_on_termination = lookup (root_block_device. value , " delete_on_termination" , null )
124
- iops = lookup (root_block_device. value , " iops" , null )
125
- volume_size = lookup (root_block_device. value , " volume_size" , null )
126
- volume_type = lookup (root_block_device. value , " volume_type" , null )
127
- }
128
- }
129
-
130
- dynamic "ebs_block_device" {
131
- for_each = var. ebs_block_device
132
- content {
133
- delete_on_termination = lookup (ebs_block_device. value , " delete_on_termination" , null )
134
- device_name = ebs_block_device. value . device_name
135
- encrypted = lookup (ebs_block_device. value , " encrypted" , null )
136
- iops = lookup (ebs_block_device. value , " iops" , null )
137
- snapshot_id = lookup (ebs_block_device. value , " snapshot_id" , null )
138
- volume_size = lookup (ebs_block_device. value , " volume_size" , null )
139
- volume_type = lookup (ebs_block_device. value , " volume_type" , null )
140
- }
141
- }
142
-
143
- dynamic "ephemeral_block_device" {
144
- for_each = var. ephemeral_block_device
145
- content {
146
- device_name = ephemeral_block_device. value . device_name
147
- no_device = lookup (ephemeral_block_device. value , " no_device" , null )
148
- virtual_name = lookup (ephemeral_block_device. value , " virtual_name" , null )
149
- }
150
- }
151
-
152
- source_dest_check = var. source_dest_check
153
- disable_api_termination = var. disable_api_termination
154
- instance_initiated_shutdown_behavior = var. instance_initiated_shutdown_behavior
155
- placement_group = var. placement_group
156
- tenancy = var. tenancy
157
-
158
83
credit_specification {
159
- cpu_credits = var. cpu_credits
84
+ cpu_credits = local . is_t_instance_type ? var. cpu_credits : null
160
85
}
161
86
162
- tags = merge (
163
- {
164
- " Name" = var.instance_count > 1 || var.use_num_suffix ? format (" %s-%d" , var. name , count. index + 1 ) : var.name
165
- },
166
- var. tags ,
167
- )
168
-
169
- volume_tags = merge (
170
- {
171
- " Name" = var.instance_count > 1 || var.use_num_suffix ? format (" %s-%d" , var. name , count. index + 1 ) : var.name
172
- },
173
- var. volume_tags ,
174
- )
175
-
176
87
lifecycle {
177
88
# Due to several known issues in Terraform AWS provider related to arguments of aws_instance:
178
89
# (eg, https://github.com/terraform-providers/terraform-provider-aws/issues/2036)
@@ -183,4 +94,3 @@ resource "aws_instance" "this_t2" {
183
94
]
184
95
}
185
96
}
186
-
0 commit comments