Skip to content

Instantly share code, notes, and snippets.

View Dan-Santarossa's full-sized avatar

Sandan Dan-Santarossa

  • Level Up In Tech
  • Toronto
View GitHub Profile
# Local .terraform directories
**/.terraform/*
# .tfstate files
*.tfstate
*.tfstate.*
# Crash log files
crash.log
###---root(terraformec2)/outputs.tf---
output "public_ip_addr" {
value = module.ec2-instance.public_ip_addr
}
output "ec2_name" {
value = module.ec2-instance.ec2_name
}
###---/ec2/outputs.tf---
output "ec2_name" {
value = aws_instance.app_server[*].tags_all.Name
}
output "public_ip_addr" {
value = aws_instance.app_server[*].public_ip
}
###---root(terraformec2)/ec2.tf---
module "ec2-instance" { #calls the ec2-instance module
source = "./ec2" #file path to files in /ec2
}
###---/terraformec2/ec2/variables.tf---
variable "ami_id" {
type = string
default = "ami-0cea098ed2ac54925" # ami id
}
variable "ec2_instance_type" {
type = string
default = "t2.micro" # free tier instance type
###---/terraformec2/ec2/providers.tf---
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.27"
}
}
###---/terraformec2/ec2/main.tf---
resource "aws_instance" "app_server" {
ami = var.ami_id
instance_type = var.ec2_instance_type
tags = {
Name = "ExampleAppServerInstance"
}
}
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.27"
}
}
required_version = ">= 0.14.9"
}
resource "aws_ecs_cluster" "ecs-cluster" {
name = "ecs-cluster-project"
}
resource "aws_ecs_cluster_capacity_providers" "ecs-cap-provider" {
cluster_name = aws_ecs_cluster.ecs-cluster.id
capacity_providers = ["FARGATE"]
default_capacity_provider_strategy {
base = 1
resource "aws_subnet" "private_ecs_subnet1" {
vpc_id = aws_vpc.ecs_tf_vpc.id
cidr_block = "10.0.1.0/24"
availability_zone = "us-east-1a"
map_public_ip_on_launch = false
tags = {
"Name" = "private_ecs_subnet1"
}
}