Skip to content

Commit

Permalink
Merge pull request #2 from ExitoLab/feature/terraform-label
Browse files Browse the repository at this point in the history
refactor: Added makefile and standard label
  • Loading branch information
ExitoLab authored Mar 17, 2021
2 parents c86ddf9 + 142ae7e commit 53d87ca
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 26 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
*.terraform
*.terraform.*
*.pem
*.tfvars
*.tfplan
*.tfstate
*.tfstate.backup
*.lock.info
.terraform
.DS_Store
.terraform.lock.hcl
*.terraform.lock.hcl
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.PHONY: all
all: terraform-fmt terraform-init terraform-validate

SHELL := /bin/bash -l

#format the terraform code
terraform-fmt:
terraform fmt ${TERRAFORM_LAYER}

terraform-init:
cd ${TERRAFORM_LAYER} && \
terraform init -input=false

terraform-validate:
cd ${TERRAFORM_LAYER} && \
terraform validate --vars-file=vars/dev.tfvars
9 changes: 9 additions & 0 deletions ec2-instance/labels.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module "common_labels" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=0.24.1"

tags = {
"business_unit" = "Technology",
"region" = "eu-west-1",
"department" = "Technology"
}
}
3 changes: 3 additions & 0 deletions ec2-instance/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
locals {
tags = module.common_labels.tags
}
7 changes: 4 additions & 3 deletions ec2-instance/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
resource "aws_key_pair" "ssh_key" {
key_name = "ssh_key"
public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC8NyvLUwuxWKC1BHOfCi+3YNupLZiOCL1RfRiP1ZSF2GnZdvdKsSkKwE4JCwe47y6QE3BL7LKouvy0P84VkqulVl6x1mSBmhTMg3c2Rngd8A2kQ3zNtTJCRWSfk12yo5ySKynteaKz0xj/AEm5XkMaOml9wagiLg30W0JLBOAqxVsspgRjASnajdCizperQ/CdSoSf3XGpCymlgXvFnBMJN9DNrgCBg16bJ0h1xKF+7iyxgJ1Ygw2C+4FEnVMKnmwmuA28qbxaBmmrRP+5jre/fSDchhtvSHkn8IhiRArICIWhgNF26sVyIOQAkGmvtcwmDX/pXqzIEYuq6vqOIne5nHJORFP2FFyvOpjynt9bj3fzBTwyK+mKXFZqBINmW+RdObs0puyEKLP28harC+xzIfkdKIpGWtKV++DtK1LBTdlxP9kcQhf13PvC2+BSh1+6n7FvTsYY6xhli+7KhAEz0afsPZuGcWvoqSYhrKsDAl7sfNrQgrdxuLgfYOWYAos= toksy@Iges-MacBook-Pro.local"
tags = local.tags
}

# vpc
Expand Down Expand Up @@ -40,9 +41,9 @@ resource "aws_route_table_association" "route_subnet_1" {

# ec2-instance
resource "aws_instance" "app_server" {
ami = data.aws_ami.aws-linux.id
instance_type = var.instance_type
subnet_id = aws_subnet.subnet_1.id
ami = data.aws_ami.aws-linux.id
instance_type = var.instance_type
subnet_id = aws_subnet.subnet_1.id
vpc_security_group_ids = [aws_security_group.sg-instance.id]
key_name = var.ssh_key_name

Expand Down
6 changes: 5 additions & 1 deletion ec2-instance/providers.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
provider "aws" {
region = var.region
region = var.region
}

terraform {
Expand All @@ -14,5 +14,9 @@ terraform {
region = "us-east-1"
encrypt = true
dynamodb_table = "terraform_practice_lock"

skip_metadata_api_check = true
skip_region_validation = true
skip_credentials_validation = true
}
}
28 changes: 14 additions & 14 deletions ec2-instance/security_group.tf
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
# SECURITY_GROUP
resource "aws_security_group" "sg-instance" {
name = "instance_sg"
name = "instance_sg"
vpc_id = aws_vpc.vpc_1.id

ingress {
from_port = 80
to_port = 80
protocol = "tcp"
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

ingress {
from_port = 443
to_port = 443
protocol = "tcp"
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

ingress {
from_port = 22
to_port = 22
protocol = "tcp"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

egress {
from_port = 0
to_port = 0
protocol = "-1"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
12 changes: 6 additions & 6 deletions ec2-instance/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ variable "region" {
}

variable "vpc_cidr" {
type = string
default = "172.16.0.0/16"
type = string
default = "172.16.0.0/16"
}

variable "subnet_cidr_1" {
Expand All @@ -21,16 +21,16 @@ variable "subnet_cidr_1" {

variable "instance_type" {
description = "The instance type"
type = string
default = "t2.micro"
type = string
default = "t2.micro"
}

variable "private_key_path" {
description = "Private key"
type = string
type = string
}

variable "ssh_key_name" {
description = "ssh key name"
type = string
type = string
}
File renamed without changes.

0 comments on commit 53d87ca

Please sign in to comment.