mirror of
https://github.com/farcasclaudiu/terraform-course.git
synced 2026-06-28 23:02:12 +03:00
@@ -1,14 +1,16 @@
|
||||
variable "ENV" {}
|
||||
variable "ENV" {
|
||||
}
|
||||
|
||||
variable "INSTANCE_TYPE" {
|
||||
default = "t2.micro"
|
||||
}
|
||||
|
||||
variable "PUBLIC_SUBNETS" {
|
||||
type = "list"
|
||||
type = list
|
||||
}
|
||||
|
||||
variable "VPC_ID" {}
|
||||
variable "VPC_ID" {
|
||||
}
|
||||
|
||||
variable "PATH_TO_PUBLIC_KEY" {
|
||||
default = "mykey.pub"
|
||||
@@ -31,26 +33,26 @@ data "aws_ami" "ubuntu" {
|
||||
}
|
||||
|
||||
resource "aws_instance" "instance" {
|
||||
ami = "${data.aws_ami.ubuntu.id}"
|
||||
instance_type = "${var.INSTANCE_TYPE}"
|
||||
ami = data.aws_ami.ubuntu.id
|
||||
instance_type = var.INSTANCE_TYPE
|
||||
|
||||
# the VPC subnet
|
||||
subnet_id = "${var.PUBLIC_SUBNETS[0]}"
|
||||
subnet_id = element(var.PUBLIC_SUBNETS, 0)
|
||||
|
||||
# the security group
|
||||
vpc_security_group_ids = ["${aws_security_group.allow-ssh.id}"]
|
||||
vpc_security_group_ids = [aws_security_group.allow-ssh.id]
|
||||
|
||||
# the public SSH key
|
||||
key_name = "${aws_key_pair.mykeypair.key_name}"
|
||||
key_name = aws_key_pair.mykeypair.key_name
|
||||
|
||||
tags {
|
||||
tags = {
|
||||
Name = "instance-${var.ENV}"
|
||||
Environmnent = "${var.ENV}"
|
||||
Environmnent = var.ENV
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_security_group" "allow-ssh" {
|
||||
vpc_id = "${var.VPC_ID}"
|
||||
vpc_id = var.VPC_ID
|
||||
name = "allow-ssh-${var.ENV}"
|
||||
description = "security group that allows ssh and all egress traffic"
|
||||
|
||||
@@ -68,13 +70,14 @@ resource "aws_security_group" "allow-ssh" {
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
}
|
||||
|
||||
tags {
|
||||
tags = {
|
||||
Name = "allow-ssh"
|
||||
Environmnent = "${var.ENV}"
|
||||
Environmnent = var.ENV
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_key_pair" "mykeypair" {
|
||||
key_name = "mykeypair-${var.ENV}"
|
||||
public_key = "${file("${path.root}/${var.PATH_TO_PUBLIC_KEY}")}"
|
||||
public_key = file("${path.root}/${var.PATH_TO_PUBLIC_KEY}")
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
terraform {
|
||||
required_version = ">= 0.12"
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
terraform {
|
||||
required_version = ">= 0.12"
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
variable "ENV" {}
|
||||
variable "AWS_REGION" {}
|
||||
variable "ENV" {
|
||||
}
|
||||
|
||||
variable "AWS_REGION" {
|
||||
}
|
||||
|
||||
module "main-vpc" {
|
||||
source = "terraform-aws-modules/vpc/aws"
|
||||
@@ -16,21 +19,22 @@ module "main-vpc" {
|
||||
|
||||
tags = {
|
||||
Terraform = "true"
|
||||
Environment = "${var.ENV}"
|
||||
Environment = var.ENV
|
||||
}
|
||||
}
|
||||
|
||||
output "vpc_id" {
|
||||
description = "The ID of the VPC"
|
||||
value = "${module.main-vpc.vpc_id}"
|
||||
value = module.main-vpc.vpc_id
|
||||
}
|
||||
|
||||
output "private_subnets" {
|
||||
description = "List of IDs of private subnets"
|
||||
value = ["${module.main-vpc.private_subnets}"]
|
||||
value = module.main-vpc.private_subnets
|
||||
}
|
||||
|
||||
output "public_subnets" {
|
||||
description = "List of IDs of public subnets"
|
||||
value = ["${module.main-vpc.public_subnets}"]
|
||||
value = module.main-vpc.public_subnets
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user