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
135145e2
Unverified
Commit
135145e2
authored
Aug 13, 2022
by
Bryant Biggs
Committed by
GitHub
Aug 13, 2022
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: Correct capacity reservation target (#288)
parent
dbf16a26
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
81 additions
and
89 deletions
+81
-89
.pre-commit-config.yaml
.pre-commit-config.yaml
+2
-2
main.tf
examples/complete/main.tf
+74
-83
main.tf
main.tf
+5
-4
No files found.
.pre-commit-config.yaml
View file @
135145e2
repos
:
repos
:
-
repo
:
https://github.com/antonbabenko/pre-commit-terraform
-
repo
:
https://github.com/antonbabenko/pre-commit-terraform
rev
:
v1.7
1.0
rev
:
v1.7
4.1
hooks
:
hooks
:
-
id
:
terraform_fmt
-
id
:
terraform_fmt
-
id
:
terraform_wrapper_module_for_each
-
id
:
terraform_wrapper_module_for_each
...
@@ -24,7 +24,7 @@ repos:
...
@@ -24,7 +24,7 @@ repos:
-
'
--args=--only=terraform_standard_module_structure'
-
'
--args=--only=terraform_standard_module_structure'
-
'
--args=--only=terraform_workspace_remote'
-
'
--args=--only=terraform_workspace_remote'
-
repo
:
https://github.com/pre-commit/pre-commit-hooks
-
repo
:
https://github.com/pre-commit/pre-commit-hooks
rev
:
v4.
2
.0
rev
:
v4.
3
.0
hooks
:
hooks
:
-
id
:
check-merge-conflict
-
id
:
check-merge-conflict
-
id
:
end-of-file-fixer
-
id
:
end-of-file-fixer
examples/complete/main.tf
View file @
135145e2
...
@@ -18,81 +18,9 @@ locals {
...
@@ -18,81 +18,9 @@ locals {
}
}
################################################################################
################################################################################
#
Supporting Resources
#
EC2 Module
################################################################################
################################################################################
module
"vpc"
{
source
=
"terraform-aws-modules/vpc/aws"
version
=
"~> 3.0"
name
=
local
.
name
cidr
=
"10.99.0.0/18"
azs
=
[
"
${
local
.
region
}
a"
,
"
${
local
.
region
}
b"
,
"
${
local
.
region
}
c"
]
public_subnets
=
[
"10.99.0.0/24"
,
"10.99.1.0/24"
,
"10.99.2.0/24"
]
private_subnets
=
[
"10.99.3.0/24"
,
"10.99.4.0/24"
,
"10.99.5.0/24"
]
database_subnets
=
[
"10.99.7.0/24"
,
"10.99.8.0/24"
,
"10.99.9.0/24"
]
tags
=
local
.
tags
}
data
"aws_ami"
"amazon_linux"
{
most_recent
=
true
owners
=
[
"amazon"
]
filter
{
name
=
"name"
values
=
[
"amzn-ami-hvm-*-x86_64-gp2"
]
}
}
module
"security_group"
{
source
=
"terraform-aws-modules/security-group/aws"
version
=
"~> 4.0"
name
=
local
.
name
description
=
"Security group for example usage with EC2 instance"
vpc_id
=
module
.
vpc
.
vpc_id
ingress_cidr_blocks
=
[
"0.0.0.0/0"
]
ingress_rules
=
[
"http-80-tcp"
,
"all-icmp"
]
egress_rules
=
[
"all-all"
]
tags
=
local
.
tags
}
resource
"aws_placement_group"
"web"
{
name
=
local
.
name
strategy
=
"cluster"
}
resource
"aws_kms_key"
"this"
{
}
resource
"aws_network_interface"
"this"
{
subnet_id
=
element
(
module
.
vpc
.
private_subnets
,
0
)
}
resource
"aws_ec2_capacity_reservation"
"open"
{
instance_type
=
"t3.micro"
instance_platform
=
"Linux/UNIX"
availability_zone
=
"
${
local
.
region
}
a"
instance_count
=
1
instance_match_criteria
=
"open"
}
resource
"aws_ec2_capacity_reservation"
"targeted"
{
instance_type
=
"t3.micro"
instance_platform
=
"Linux/UNIX"
availability_zone
=
"
${
local
.
region
}
a"
instance_count
=
1
instance_match_criteria
=
"targeted"
}
# # ################################################################################
# # # EC2 Module
# # ################################################################################
module
"ec2_disabled"
{
module
"ec2_disabled"
{
source
=
"../../"
source
=
"../../"
...
@@ -123,10 +51,6 @@ module "ec2_complete" {
...
@@ -123,10 +51,6 @@ module "ec2_complete" {
cpu_core_count
=
2
# default 4
cpu_core_count
=
2
# default 4
cpu_threads_per_core
=
1
# default 2
cpu_threads_per_core
=
1
# default 2
capacity_reservation_specification
=
{
capacity_reservation_preference
=
"open"
}
enable_volume_tags
=
false
enable_volume_tags
=
false
root_block_device
=
[
root_block_device
=
[
{
{
...
@@ -295,15 +219,13 @@ module "ec2_spot_instance" {
...
@@ -295,15 +219,13 @@ module "ec2_spot_instance" {
create_spot_instance
=
true
create_spot_instance
=
true
ami
=
data
.
aws_ami
.
amazon_linux
.
id
ami
=
data
.
aws_ami
.
amazon_linux
.
id
instance_type
=
"c4.4xlarge"
availability_zone
=
element
(
module
.
vpc
.
azs
,
0
)
availability_zone
=
element
(
module
.
vpc
.
azs
,
0
)
subnet_id
=
element
(
module
.
vpc
.
private_subnets
,
0
)
subnet_id
=
element
(
module
.
vpc
.
private_subnets
,
0
)
vpc_security_group_ids
=
[
module
.
security_group
.
security_group_id
]
vpc_security_group_ids
=
[
module
.
security_group
.
security_group_id
]
placement_group
=
aws_placement_group
.
web
.
id
associate_public_ip_address
=
true
associate_public_ip_address
=
true
# Spot request specific attributes
# Spot request specific attributes
spot_price
=
"0.
60
"
spot_price
=
"0.
1
"
spot_wait_for_fulfillment
=
true
spot_wait_for_fulfillment
=
true
spot_type
=
"persistent"
spot_type
=
"persistent"
spot_instance_interruption_behavior
=
"terminate"
spot_instance_interruption_behavior
=
"terminate"
...
@@ -314,9 +236,6 @@ module "ec2_spot_instance" {
...
@@ -314,9 +236,6 @@ module "ec2_spot_instance" {
cpu_core_count
=
2
# default 4
cpu_core_count
=
2
# default 4
cpu_threads_per_core
=
1
# default 2
cpu_threads_per_core
=
1
# default 2
capacity_reservation_specification
=
{
capacity_reservation_preference
=
"open"
}
enable_volume_tags
=
false
enable_volume_tags
=
false
root_block_device
=
[
root_block_device
=
[
...
@@ -388,3 +307,75 @@ module "ec2_targeted_capacity_reservation" {
...
@@ -388,3 +307,75 @@ module "ec2_targeted_capacity_reservation" {
tags
=
local
.
tags
tags
=
local
.
tags
}
}
################################################################################
# Supporting Resources
################################################################################
module
"vpc"
{
source
=
"terraform-aws-modules/vpc/aws"
version
=
"~> 3.0"
name
=
local
.
name
cidr
=
"10.99.0.0/18"
azs
=
[
"
${
local
.
region
}
a"
,
"
${
local
.
region
}
b"
,
"
${
local
.
region
}
c"
]
public_subnets
=
[
"10.99.0.0/24"
,
"10.99.1.0/24"
,
"10.99.2.0/24"
]
private_subnets
=
[
"10.99.3.0/24"
,
"10.99.4.0/24"
,
"10.99.5.0/24"
]
database_subnets
=
[
"10.99.7.0/24"
,
"10.99.8.0/24"
,
"10.99.9.0/24"
]
tags
=
local
.
tags
}
data
"aws_ami"
"amazon_linux"
{
most_recent
=
true
owners
=
[
"amazon"
]
filter
{
name
=
"name"
values
=
[
"amzn-ami-hvm-*-x86_64-gp2"
]
}
}
module
"security_group"
{
source
=
"terraform-aws-modules/security-group/aws"
version
=
"~> 4.0"
name
=
local
.
name
description
=
"Security group for example usage with EC2 instance"
vpc_id
=
module
.
vpc
.
vpc_id
ingress_cidr_blocks
=
[
"0.0.0.0/0"
]
ingress_rules
=
[
"http-80-tcp"
,
"all-icmp"
]
egress_rules
=
[
"all-all"
]
tags
=
local
.
tags
}
resource
"aws_placement_group"
"web"
{
name
=
local
.
name
strategy
=
"cluster"
}
resource
"aws_kms_key"
"this"
{
}
resource
"aws_network_interface"
"this"
{
subnet_id
=
element
(
module
.
vpc
.
private_subnets
,
0
)
}
resource
"aws_ec2_capacity_reservation"
"open"
{
instance_type
=
"t3.micro"
instance_platform
=
"Linux/UNIX"
availability_zone
=
"
${
local
.
region
}
a"
instance_count
=
1
instance_match_criteria
=
"open"
}
resource
"aws_ec2_capacity_reservation"
"targeted"
{
instance_type
=
"t3.micro"
instance_platform
=
"Linux/UNIX"
availability_zone
=
"
${
local
.
region
}
a"
instance_count
=
1
instance_match_criteria
=
"targeted"
}
main.tf
View file @
135145e2
...
@@ -35,14 +35,15 @@ resource "aws_instance" "this" {
...
@@ -35,14 +35,15 @@ resource "aws_instance" "this" {
ebs_optimized
=
var
.
ebs_optimized
ebs_optimized
=
var
.
ebs_optimized
dynamic
"capacity_reservation_specification"
{
dynamic
"capacity_reservation_specification"
{
for_each
=
var
.
capacity_reservation_specification
!
=
null
?
[
var
.
capacity_reservation_specification
]
:
[]
for_each
=
length
(
var
.
capacity_reservation_specification
)
>
0
?
[
var
.
capacity_reservation_specification
]
:
[]
content
{
content
{
capacity_reservation_preference
=
lookup
(
capacity_reservation_specification
.
value
,
"capacity_reservation_preference"
,
null
)
capacity_reservation_preference
=
try
(
capacity_reservation_specification
.
value
.
capacity_reservation_preference
,
null
)
dynamic
"capacity_reservation_target"
{
dynamic
"capacity_reservation_target"
{
for_each
=
lookup
(
capacity_reservation_specification
.
value
,
"capacity_reservation_target"
,
[]
)
for_each
=
try
(
[
capacity_reservation_specification
.
value
.
capacity_reservation_target
]
,
[]
)
content
{
content
{
capacity_reservation_id
=
lookup
(
capacity_reservation_specification
.
value
.
capacity_reservation_target
,
"capacity_reservation_id"
,
null
)
capacity_reservation_id
=
try
(
capacity_reservation_target
.
value
.
capacity_reservation_id
,
null
)
capacity_reservation_resource_group_arn
=
try
(
capacity_reservation_target
.
value
.
capacity_reservation_resource_group_arn
,
null
)
}
}
}
}
}
}
...
...
Jose Ernesto Suarez
@ernesto
mentioned in commit
668ac71d
·
Apr 07, 2023
mentioned in commit
668ac71d
mentioned in commit 668ac71dba23f804018ecbc8feee4c12a88cf7b2
Toggle commit list
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