mirror of
https://github.com/sidpalas/devops-directive-terraform-course.git
synced 2025-12-13 14:21:14 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9949d314f3 | ||
|
|
7a3fdaca72 | ||
|
|
4012eec6cd | ||
|
|
75922067d8 |
7
.github/workflows/terraform.yml
vendored
7
.github/workflows/terraform.yml
vendored
@@ -1,9 +1,10 @@
|
||||
name: "Terraform"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
# Uncomment to enable staging deploy from main
|
||||
# push:
|
||||
# branches:
|
||||
# - main
|
||||
release:
|
||||
types: [published]
|
||||
pull_request:
|
||||
|
||||
@@ -27,15 +27,20 @@ provider "aws" {
|
||||
resource "aws_s3_bucket" "terraform_state" {
|
||||
bucket = "devops-directive-tf-state" # REPLACE WITH YOUR BUCKET NAME
|
||||
force_destroy = true
|
||||
versioning {
|
||||
enabled = true
|
||||
}
|
||||
}
|
||||
|
||||
server_side_encryption_configuration {
|
||||
rule {
|
||||
apply_server_side_encryption_by_default {
|
||||
sse_algorithm = "AES256"
|
||||
}
|
||||
resource "aws_s3_bucket_versioning" "terraform_bucket_versioning" {
|
||||
bucket = aws_s3_bucket.terraform_state.id
|
||||
versioning_configuration {
|
||||
status = "Enabled"
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_s3_bucket_server_side_encryption_configuration" "terraform_state_crypto_conf" {
|
||||
bucket = aws_s3_bucket.terraform_state.bucket
|
||||
rule {
|
||||
apply_server_side_encryption_by_default {
|
||||
sse_algorithm = "AES256"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,17 +44,22 @@ resource "aws_instance" "instance_2" {
|
||||
}
|
||||
|
||||
resource "aws_s3_bucket" "bucket" {
|
||||
bucket = "devops-directive-web-app-data"
|
||||
bucket_prefix = "devops-directive-web-app-data"
|
||||
force_destroy = true
|
||||
versioning {
|
||||
enabled = true
|
||||
}
|
||||
}
|
||||
|
||||
server_side_encryption_configuration {
|
||||
rule {
|
||||
apply_server_side_encryption_by_default {
|
||||
sse_algorithm = "AES256"
|
||||
}
|
||||
resource "aws_s3_bucket_versioning" "bucket_versioning" {
|
||||
bucket = aws_s3_bucket.bucket.id
|
||||
versioning_configuration {
|
||||
status = "Enabled"
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_s3_bucket_server_side_encryption_configuration" "bucket_crypto_conf" {
|
||||
bucket = aws_s3_bucket.bucket.bucket
|
||||
rule {
|
||||
apply_server_side_encryption_by_default {
|
||||
sse_algorithm = "AES256"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -198,13 +203,18 @@ resource "aws_route53_record" "root" {
|
||||
}
|
||||
|
||||
resource "aws_db_instance" "db_instance" {
|
||||
allocated_storage = 20
|
||||
storage_type = "standard"
|
||||
engine = "postgres"
|
||||
engine_version = "12.5"
|
||||
instance_class = "db.t2.micro"
|
||||
name = "mydb"
|
||||
username = "foo"
|
||||
password = "foobarbaz"
|
||||
skip_final_snapshot = true
|
||||
allocated_storage = 20
|
||||
# This allows any minor version within the major engine_version
|
||||
# defined below, but will also result in allowing AWS to auto
|
||||
# upgrade the minor version of your DB. This may be too risky
|
||||
# in a real production environment.
|
||||
auto_minor_version_upgrade = true
|
||||
storage_type = "standard"
|
||||
engine = "postgres"
|
||||
engine_version = "12"
|
||||
instance_class = "db.t2.micro"
|
||||
name = "mydb"
|
||||
username = "foo"
|
||||
password = "foobarbaz"
|
||||
skip_final_snapshot = true
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ resource "aws_db_instance" "db_instance" {
|
||||
allocated_storage = 20
|
||||
storage_type = "gp2"
|
||||
engine = "postgres"
|
||||
engine_version = "12.4"
|
||||
engine_version = "12"
|
||||
instance_class = "db.t2.micro"
|
||||
name = "mydb"
|
||||
username = var.db_user
|
||||
|
||||
@@ -45,17 +45,22 @@ resource "aws_instance" "instance_2" {
|
||||
}
|
||||
|
||||
resource "aws_s3_bucket" "bucket" {
|
||||
bucket = var.bucket_name
|
||||
bucket_prefix = var.bucket_prefix
|
||||
force_destroy = true
|
||||
versioning {
|
||||
enabled = true
|
||||
}
|
||||
}
|
||||
|
||||
server_side_encryption_configuration {
|
||||
rule {
|
||||
apply_server_side_encryption_by_default {
|
||||
sse_algorithm = "AES256"
|
||||
}
|
||||
resource "aws_s3_bucket_versioning" "bucket_versioning" {
|
||||
bucket = aws_s3_bucket.bucket.id
|
||||
versioning_configuration {
|
||||
status = "Enabled"
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_s3_bucket_server_side_encryption_configuration" "bucket_crypto_conf" {
|
||||
bucket = aws_s3_bucket.bucket.bucket
|
||||
rule {
|
||||
apply_server_side_encryption_by_default {
|
||||
sse_algorithm = "AES256"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -202,7 +207,7 @@ resource "aws_db_instance" "db_instance" {
|
||||
allocated_storage = 20
|
||||
storage_type = "standard"
|
||||
engine = "postgres"
|
||||
engine_version = "12.5"
|
||||
engine_version = "12"
|
||||
instance_class = "db.t2.micro"
|
||||
name = var.db_name
|
||||
username = var.db_user
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
bucket_name = "devops-directive-web-app-data"
|
||||
domain = "devopsdeployed.com"
|
||||
db_name = "mydb"
|
||||
db_user = "foo"
|
||||
bucket_prefix = "devops-directive-web-app-data"
|
||||
domain = "devopsdeployed.com"
|
||||
db_name = "mydb"
|
||||
db_user = "foo"
|
||||
# db_pass = "foobarbaz"
|
||||
|
||||
@@ -22,8 +22,8 @@ variable "instance_type" {
|
||||
|
||||
# S3 Variables
|
||||
|
||||
variable "bucket_name" {
|
||||
description = "name of s3 bucket for app data"
|
||||
variable "bucket_prefix" {
|
||||
description = "prefix of s3 bucket for app data"
|
||||
type = string
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ resource "aws_db_instance" "db_instance" {
|
||||
allocated_storage = 20
|
||||
storage_type = "standard"
|
||||
engine = "postgres"
|
||||
engine_version = "12.5"
|
||||
engine_version = "12"
|
||||
instance_class = "db.t2.micro"
|
||||
name = var.db_name
|
||||
username = var.db_user
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
resource "aws_s3_bucket" "bucket" {
|
||||
bucket = var.bucket_name
|
||||
bucket_prefix = var.bucket_prefix
|
||||
force_destroy = true
|
||||
versioning {
|
||||
enabled = true
|
||||
}
|
||||
}
|
||||
|
||||
server_side_encryption_configuration {
|
||||
rule {
|
||||
apply_server_side_encryption_by_default {
|
||||
sse_algorithm = "AES256"
|
||||
}
|
||||
resource "aws_s3_bucket_versioning" "bucket_versioning" {
|
||||
bucket = aws_s3_bucket.bucket.id
|
||||
versioning_configuration {
|
||||
status = "Enabled"
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_s3_bucket_server_side_encryption_configuration" "bucket_crypto_conf" {
|
||||
bucket = aws_s3_bucket.bucket.bucket
|
||||
rule {
|
||||
apply_server_side_encryption_by_default {
|
||||
sse_algorithm = "AES256"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@ variable "instance_type" {
|
||||
|
||||
# S3 Variables
|
||||
|
||||
variable "bucket_name" {
|
||||
description = "name of s3 bucket for app data"
|
||||
variable "bucket_prefix" {
|
||||
description = "prefix of s3 bucket for app data"
|
||||
type = string
|
||||
}
|
||||
|
||||
|
||||
@@ -37,11 +37,11 @@ module "web_app_1" {
|
||||
source = "../web-app-module"
|
||||
|
||||
# Input Variables
|
||||
bucket_name = "web-app-1-devops-directive-web-app-data"
|
||||
bucket_prefix = "web-app-1-data"
|
||||
domain = "devopsdeployed.com"
|
||||
app_name = "web-app-1"
|
||||
environment_name = "production"
|
||||
instance_type = "t2.small"
|
||||
instance_type = "t2.micro"
|
||||
create_dns_zone = true
|
||||
db_name = "webapp1db"
|
||||
db_user = "foo"
|
||||
@@ -52,11 +52,11 @@ module "web_app_2" {
|
||||
source = "../web-app-module"
|
||||
|
||||
# Input Variables
|
||||
bucket_name = "web-app-2-devops-directive-web-app-data"
|
||||
bucket_prefix = "web-app-2-data"
|
||||
domain = "anotherdevopsdeployed.com"
|
||||
app_name = "web-app-2"
|
||||
environment_name = "production"
|
||||
instance_type = "t2.small"
|
||||
instance_type = "t2.micro"
|
||||
create_dns_zone = true
|
||||
db_name = "webapp2db"
|
||||
db_user = "bar"
|
||||
|
||||
@@ -35,10 +35,10 @@ module "web_app" {
|
||||
source = "../../../06-organization-and-modules/web-app-module"
|
||||
|
||||
# Input Variables
|
||||
bucket_name = "devops-directive-web-app-data-${local.environment_name}"
|
||||
bucket_prefix = "web-app-data-${local.environment_name}"
|
||||
domain = "devopsdeployed.com"
|
||||
environment_name = local.environment_name
|
||||
instance_type = "t2.small"
|
||||
instance_type = "t2.micro"
|
||||
create_dns_zone = false
|
||||
db_name = "${local.environment_name}mydb"
|
||||
db_user = "foo"
|
||||
|
||||
@@ -35,7 +35,7 @@ module "web_app" {
|
||||
source = "../../../06-organization-and-modules/web-app-module"
|
||||
|
||||
# Input Variables
|
||||
bucket_name = "devops-directive-web-app-data-${local.environment_name}"
|
||||
bucket_prefix = "web-app-data-${local.environment_name}"
|
||||
domain = "devopsdeployed.com"
|
||||
environment_name = local.environment_name
|
||||
instance_type = "t2.micro"
|
||||
|
||||
@@ -35,10 +35,10 @@ module "web_app" {
|
||||
source = "../../06-organization-and-modules/web-app-module"
|
||||
|
||||
# Input Variables
|
||||
bucket_name = "devops-directive-web-app-data-${local.environment_name}"
|
||||
bucket_prefix = "web-app-data-${local.environment_name}"
|
||||
domain = "devopsdeployed.com"
|
||||
environment_name = local.environment_name
|
||||
instance_type = "t2.small"
|
||||
instance_type = "t2.micro"
|
||||
create_dns_zone = terraform.workspace == "production" ? true : false
|
||||
db_name = "${local.environment_name}mydb"
|
||||
db_user = "foo"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
How to run this test?
|
||||
|
||||
Build, then run...
|
||||
|
||||
`go test -v timeout 10m`
|
||||
|
||||
download dependencies, then run the tests...
|
||||
```
|
||||
go mod download
|
||||
go test -v --timeout 10m
|
||||
```
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
# DevOps Directive Terraform Course
|
||||
|
||||
This is the companion repo to the complete Terraform course from DevOps Directive (https://www.youtube.com/c/DevOpsDirective)
|
||||
This is the companion repo to: [Complete Terraform Course - From BEGINNER to PRO! (Learn Infrastructure as Code)](https://www.youtube.com/watch?v=7xngnjfIlK4)
|
||||
|
||||
*Note:* The videos for the course have not been released yet... stay tuned!
|
||||
[](https://www.youtube.com/watch?v=7xngnjfIlK4)
|
||||
|
||||
## 01 - Evolution of Cloud + Infrastructure as Code
|
||||
|
||||
@@ -42,4 +42,4 @@ Explains different types of testing (manual + automated) for Terraform modules a
|
||||
|
||||
## 09 - Developer Workflows + CI/CD
|
||||
|
||||
Covers how teams can work together with Terraform and how to set up CI/CD pipelines to keep infrastructure environments up to date.
|
||||
Covers how teams can work together with Terraform and how to set up CI/CD pipelines to keep infrastructure environments up to date.
|
||||
|
||||
Reference in New Issue
Block a user