Add dynamic resources naming and tfvars example

This commit is contained in:
mr-vercetti
2022-08-26 15:16:02 +02:00
parent ffdb539b4d
commit 86fa35e0a5
11 changed files with 59 additions and 47 deletions

View File

@ -1,5 +1,5 @@
resource "aws_security_group" "this" {
name = "bastion-host-sg"
name = "${var.PROJECT_NAME}-bastion-host-sg"
vpc_id = var.VPC_ID
@ -20,18 +20,18 @@ resource "aws_security_group" "this" {
}
resource "aws_network_interface" "this" {
subnet_id = var.SUBNET_ID
subnet_id = var.SUBNET_ID
security_groups = [aws_security_group.this.id]
tags = {
Name = "bastion-host-nic"
Name = "${var.PROJECT_NAME}-bastion-host-nic"
}
}
resource "aws_instance" "this" {
ami = var.EC2_AMI
instance_type = var.EC2_TYPE
key_name = var.EC2_KEY_NAME
key_name = var.EC2_KEY_NAME
network_interface {
network_interface_id = aws_network_interface.this.id
@ -39,6 +39,6 @@ resource "aws_instance" "this" {
}
tags = {
Name = var.EC2_INSTANCE_NAME
Name = "${var.PROJECT_NAME}-bastion-host"
}
}

View File

@ -1,7 +1,3 @@
output "bastion_host_name" {
value = aws_instance.this.id
}
output "bastion_host_private_ip" {
value = aws_instance.this.private_ip
}

View File

@ -1,3 +1,7 @@
variable "PROJECT_NAME" {
type = string
}
variable "VPC_ID" {
type = string
}
@ -11,14 +15,10 @@ variable "EC2_AMI" {
}
variable "EC2_TYPE" {
type = string
type = string
default = "t2.micro"
}
variable "EC2_INSTANCE_NAME" {
type = string
}
variable "EC2_KEY_NAME" {
type = string
}