-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update ec2 resource names inline with issue #89. #91
Open
JoeCSykes
wants to merge
6
commits into
main
Choose a base branch
from
update_ec2_resource_names
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+37
−25
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
364c60d
Update ec2 resource names inline with issue #89.
JoeCSykes eb2f448
terraform-docs: automated action
github-actions[bot] 602e7ac
Added data "aws_region" "current" {}
chrisbloe 6d101d2
terraform-docs: automated action
github-actions[bot] 44e1977
Update dependabot terraform entries
github-actions[bot] 6afbce0
Added aws_region_short
chrisbloe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,12 +13,12 @@ terraform { | |
} | ||
} | ||
|
||
resource "aws_iam_instance_profile" "instance_profile" { | ||
resource "aws_iam_instance_profile" "this" { | ||
name = "${var.project_name}-ec2-monitoring-and-setup" | ||
role = aws_iam_role.instance_role.name | ||
role = aws_iam_role.this.name | ||
} | ||
|
||
resource "aws_iam_role" "instance_role" { | ||
resource "aws_iam_role" "this" { | ||
name = "${var.project_name}-ec2-monitoring-and-setup" | ||
assume_role_policy = <<-EOF | ||
{ | ||
|
@@ -36,30 +36,30 @@ resource "aws_iam_role" "instance_role" { | |
EOF | ||
} | ||
|
||
resource "aws_iam_role_policy_attachment" "instance_role" { | ||
resource "aws_iam_role_policy_attachment" "this" { | ||
for_each = toset([ | ||
"arn:aws:iam::aws:policy/service-role/AmazonEC2RoleforSSM", | ||
"arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy" | ||
]) | ||
role = aws_iam_role.instance_role.name | ||
role = aws_iam_role.this.name | ||
policy_arn = each.value | ||
} | ||
|
||
resource "tls_private_key" "private_key" { | ||
resource "tls_private_key" "this" { | ||
count = var.custom_key_name == "" ? 1 : 0 | ||
algorithm = "RSA" | ||
rsa_bits = 4096 | ||
} | ||
|
||
resource "aws_key_pair" "key_pair" { | ||
resource "aws_key_pair" "this" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again see previous comment |
||
count = var.custom_key_name == "" ? 1 : 0 | ||
key_name = "${var.project_name}-key-pair" | ||
public_key = tls_private_key.private_key[0].public_key_openssh | ||
public_key = tls_private_key.this[0].public_key_openssh | ||
} | ||
|
||
resource "aws_instance" "ec2" { | ||
resource "aws_instance" "this" { | ||
instance_type = var.ec2_instance_type | ||
key_name = var.custom_key_name == "" ? aws_key_pair.key_pair[0].key_name : var.custom_key_name | ||
key_name = var.custom_key_name == "" ? aws_key_pair.this[0].key_name : var.custom_key_name | ||
ami = var.ami_id | ||
metadata_options { | ||
http_endpoint = "enabled" | ||
|
@@ -74,7 +74,7 @@ resource "aws_instance" "ec2" { | |
vpc_security_group_ids = var.vpc_security_group_ids | ||
associate_public_ip_address = var.associate_public_ip_address | ||
|
||
iam_instance_profile = aws_iam_instance_profile.instance_profile.name | ||
iam_instance_profile = aws_iam_instance_profile.this.name | ||
|
||
user_data = var.user_data | ||
user_data_replace_on_change = var.user_data_replace_on_change | ||
|
@@ -85,10 +85,10 @@ resource "aws_instance" "ec2" { | |
} | ||
} | ||
|
||
resource "aws_eip" "public_elastic_ip" { | ||
resource "aws_eip" "this" { | ||
count = var.needs_elastic_ip == true ? 1 : 0 | ||
|
||
instance = aws_instance.ec2.id | ||
instance = aws_instance.this.id | ||
domain = "vpc" | ||
|
||
tags = { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
output "instance_public_ip_address" { | ||
value = aws_eip.public_elastic_ip[0].public_ip | ||
value = aws_eip.this[0].public_ip | ||
description = "This outputs the public IP associated with the EC2 instance. Note that this output will be the same as the elastic IP if `needs_elastic_ip` is set to `true`. This output is of type `string`." | ||
} | ||
|
||
output "instance_id" { | ||
value = aws_instance.ec2.id | ||
value = aws_instance.this.id | ||
description = "This outputs the unique ID of the EC2 instance." | ||
} | ||
|
||
output "private_key" { | ||
value = tls_private_key.private_key[0].private_key_pem | ||
value = tls_private_key.this[0].private_key_pem | ||
description = "This outputs the self-generated private key - This will not be populated if you provide your own key" | ||
sensitive = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
data "aws_availability_zones" "available" { | ||
state = "available" | ||
} | ||
|
||
data "aws_region" "current" {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would name this on the lines of
self_generated
orself_managed
This could be misinterpreted as always being the key which in some scenarios it won't be (e.g. You provide your own key)