Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
terraform-aws-ec2-instance
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Terraform Modules
terraform-aws-ec2-instance
Commits
4cc5f2ce
Commit
4cc5f2ce
authored
Jul 21, 2019
by
Stefan Mihajlovic
Committed by
Anton Babenko
Jul 21, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove T2 specifics to unify Terraform object names inside TF State (#111)
parent
461a5712
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
109 deletions
+19
-109
main.tf
main.tf
+3
-93
outputs.tf
outputs.tf
+16
-16
No files found.
main.tf
View file @
4cc5f2ce
locals
{
locals
{
is_t_instance_type
=
replace
(
var
.
instance_type
,
"/^t[23]{1}
\\
..*
$
/"
,
"1"
)
==
"1"
?
1
:
0
is_t_instance_type
=
replace
(
var
.
instance_type
,
"/^t[23]{1}
\\
..*
$
/"
,
"1"
)
==
"1"
?
true
:
false
instance_count
=
var
.
instance_count
*
(
1
-
local
.
is_t_instance_type
)
t_instance_count
=
var
.
instance_count
*
local
.
is_t_instance_type
}
}
######
######
# Note: network_interface can't be specified together with associate_public_ip_address
# Note: network_interface can't be specified together with associate_public_ip_address
######
######
resource
"aws_instance"
"this"
{
resource
"aws_instance"
"this"
{
count
=
local
.
instance_count
>
0
?
local
.
instance_count
:
0
count
=
var
.
instance_count
ami
=
var
.
ami
ami
=
var
.
ami
instance_type
=
var
.
instance_type
instance_type
=
var
.
instance_type
...
@@ -83,96 +80,10 @@ resource "aws_instance" "this" {
...
@@ -83,96 +80,10 @@ resource "aws_instance" "this" {
var
.
volume_tags
,
var
.
volume_tags
,
)
)
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
=
[
root_block_device
,
ebs_block_device
,
]
}
}
resource
"aws_instance"
"this_t2"
{
count
=
local
.
t_instance_count
>
0
?
local
.
t_instance_count
:
0
ami
=
var
.
ami
instance_type
=
var
.
instance_type
user_data
=
var
.
user_data
subnet_id
=
element
(
distinct
(
compact
(
concat
(
[
var
.
subnet_id
]
,
var
.
subnet_ids
))),
count
.
index
,
)
key_name
=
var
.
key_name
monitoring
=
var
.
monitoring
get_password_data
=
var
.
get_password_data
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
=
length
(
var
.
private_ips
)
>
0
?
element
(
var
.
private_ips
,
count
.
index
)
:
var
.
private_ip
ipv6_address_count
=
var
.
ipv6_address_count
ipv6_addresses
=
var
.
ipv6_addresses
ebs_optimized
=
var
.
ebs_optimized
dynamic
"root_block_device"
{
for_each
=
var
.
root_block_device
content
{
delete_on_termination
=
lookup
(
root_block_device
.
value
,
"delete_on_termination"
,
null
)
iops
=
lookup
(
root_block_device
.
value
,
"iops"
,
null
)
volume_size
=
lookup
(
root_block_device
.
value
,
"volume_size"
,
null
)
volume_type
=
lookup
(
root_block_device
.
value
,
"volume_type"
,
null
)
}
}
dynamic
"ebs_block_device"
{
for_each
=
var
.
ebs_block_device
content
{
delete_on_termination
=
lookup
(
ebs_block_device
.
value
,
"delete_on_termination"
,
null
)
device_name
=
ebs_block_device
.
value
.
device_name
encrypted
=
lookup
(
ebs_block_device
.
value
,
"encrypted"
,
null
)
iops
=
lookup
(
ebs_block_device
.
value
,
"iops"
,
null
)
snapshot_id
=
lookup
(
ebs_block_device
.
value
,
"snapshot_id"
,
null
)
volume_size
=
lookup
(
ebs_block_device
.
value
,
"volume_size"
,
null
)
volume_type
=
lookup
(
ebs_block_device
.
value
,
"volume_type"
,
null
)
}
}
dynamic
"ephemeral_block_device"
{
for_each
=
var
.
ephemeral_block_device
content
{
device_name
=
ephemeral_block_device
.
value
.
device_name
no_device
=
lookup
(
ephemeral_block_device
.
value
,
"no_device"
,
null
)
virtual_name
=
lookup
(
ephemeral_block_device
.
value
,
"virtual_name"
,
null
)
}
}
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
{
credit_specification
{
cpu_credits
=
var
.
cpu_credits
cpu_credits
=
local
.
is_t_instance_type
?
var
.
cpu_credits
:
null
}
}
tags
=
merge
(
{
"Name"
=
var
.
instance_count
>
1
||
var
.
use_num_suffix
?
format
(
"%s-%d"
,
var
.
name
,
count
.
index
+
1
)
:
var
.
name
}
,
var
.
tags
,
)
volume_tags
=
merge
(
{
"Name"
=
var
.
instance_count
>
1
||
var
.
use_num_suffix
?
format
(
"%s-%d"
,
var
.
name
,
count
.
index
+
1
)
:
var
.
name
}
,
var
.
volume_tags
,
)
lifecycle
{
lifecycle
{
# Due to several known issues in Terraform AWS provider related to arguments of aws_instance:
# 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)
# (eg, https://github.com/terraform-providers/terraform-provider-aws/issues/2036)
...
@@ -183,4 +94,3 @@ resource "aws_instance" "this_t2" {
...
@@ -183,4 +94,3 @@ resource "aws_instance" "this_t2" {
]
]
}
}
}
}
outputs.tf
View file @
4cc5f2ce
locals
{
locals
{
this_id
=
compact
(
coalescelist
(
aws_instance
.
this
.*.
id
,
aws_instance
.
this_t2
.*.
id
,
[
""
]
))
this_id
=
compact
(
coalescelist
(
aws_instance
.
this
.*.
id
,
[
""
]
))
this_availability_zone
=
compact
(
coalescelist
(
aws_instance
.
this
.*.
availability_zone
,
aws_instance
.
this_t2
.*.
availability_zone
,
[
""
]
))
this_availability_zone
=
compact
(
coalescelist
(
aws_instance
.
this
.*.
availability_zone
,
[
""
]
))
this_key_name
=
compact
(
coalescelist
(
aws_instance
.
this
.*.
key_name
,
aws_instance
.
this_t2
.*.
key_name
,
[
""
]
))
this_key_name
=
compact
(
coalescelist
(
aws_instance
.
this
.*.
key_name
,
[
""
]
))
this_public_dns
=
compact
(
coalescelist
(
aws_instance
.
this
.*.
public_dns
,
aws_instance
.
this_t2
.*.
public_dns
,
[
""
]
))
this_public_dns
=
compact
(
coalescelist
(
aws_instance
.
this
.*.
public_dns
,
[
""
]
))
this_public_ip
=
compact
(
coalescelist
(
aws_instance
.
this
.*.
public_ip
,
aws_instance
.
this_t2
.*.
public_ip
,
[
""
]
))
this_public_ip
=
compact
(
coalescelist
(
aws_instance
.
this
.*.
public_ip
,
[
""
]
))
this_primary_network_interface_id
=
compact
(
coalescelist
(
aws_instance
.
this
.*.
primary_network_interface_id
,
aws_instance
.
this_t2
.*.
primary_network_interface_id
,
[
""
]
))
this_primary_network_interface_id
=
compact
(
coalescelist
(
aws_instance
.
this
.*.
primary_network_interface_id
,
[
""
]
))
this_private_dns
=
compact
(
coalescelist
(
aws_instance
.
this
.*.
private_dns
,
aws_instance
.
this_t2
.*.
private_dns
,
[
""
]
))
this_private_dns
=
compact
(
coalescelist
(
aws_instance
.
this
.*.
private_dns
,
[
""
]
))
this_private_ip
=
compact
(
coalescelist
(
aws_instance
.
this
.*.
private_ip
,
aws_instance
.
this_t2
.*.
private_ip
,
[
""
]
))
this_private_ip
=
compact
(
coalescelist
(
aws_instance
.
this
.*.
private_ip
,
[
""
]
))
this_placement_group
=
compact
(
coalescelist
(
aws_instance
.
this
.*.
placement_group
,
aws_instance
.
this_t2
.*.
placement_group
,
[
""
]
))
this_placement_group
=
compact
(
coalescelist
(
aws_instance
.
this
.*.
placement_group
,
[
""
]
))
this_security_groups
=
coalescelist
(
aws_instance
.
this
.*.
security_groups
,
aws_instance
.
this_t2
.*.
security_groups
,
[
""
]
)
this_security_groups
=
coalescelist
(
aws_instance
.
this
.*.
security_groups
,
[
""
]
)
this_vpc_security_group_ids
=
coalescelist
(
flatten
(
aws_instance
.
this
.*.
vpc_security_group_ids
),
flatten
(
aws_instance
.
this_t2
.*.
vpc_security_group_ids
),
[
""
]
)
this_vpc_security_group_ids
=
coalescelist
(
flatten
(
aws_instance
.
this
.*.
vpc_security_group_ids
),
[
""
]
)
this_subnet_id
=
compact
(
coalescelist
(
aws_instance
.
this
.*.
subnet_id
,
aws_instance
.
this_t2
.*.
subnet_id
,
[
""
]
))
this_subnet_id
=
compact
(
coalescelist
(
aws_instance
.
this
.*.
subnet_id
,
[
""
]
))
this_credit_specification
=
flatten
(
aws_instance
.
this
_t2
.*.
credit_specification
)
this_credit_specification
=
flatten
(
aws_instance
.
this
.*.
credit_specification
)
this_tags
=
coalescelist
(
aws_instance
.
this
.*.
tags
,
aws_instance
.
this_t2
.*.
tags
,
[
""
]
)
this_tags
=
coalescelist
(
aws_instance
.
this
.*.
tags
,
[
""
]
)
this_volume_tags
=
coalescelist
(
aws_instance
.
this
.*.
volume_tags
,
aws_instance
.
this_t2
.*.
volume_tags
,
[
""
]
)
this_volume_tags
=
coalescelist
(
aws_instance
.
this
.*.
volume_tags
,
[
""
]
)
this_password_data
=
coalescelist
(
aws_instance
.
this
.*.
password_data
,
aws_instance
.
this_t2
.*.
password_data
,
[
""
]
)
this_password_data
=
coalescelist
(
aws_instance
.
this
.*.
password_data
,
[
""
]
)
}
}
output
"id"
{
output
"id"
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment