4 Commits
v1.0.0 ... main

Author SHA1 Message Date
sidpalas
9949d314f3 Updates from bitrot livestream (#16)
- Remove minor version pin for postgres versions (i.e. 12.5 -> 12)
- Update s3 config to use separate versioning and encryption terraform resources
- Use bucket_prefix instead of bucket for bucket naming to avoid name conflicts

Stream: https://youtu.be/KWwKPYuOGBw
2023-01-13 12:43:41 -05:00
Lachlan Mulcahy
7a3fdaca72 03-basics: Fix deprecation warnings and postgres version error (#12)
This change updates the s3 bucket resource syntax to use the newer
resource types for specifying versioning and encryption configs.
We also enable auto_minor_version_upgrade for the RDS instance and
switch to only asking for major version 12.

This will just use the default/latest RDS PostgreSQL v12 minor
version. Upside, the specific engine_version provided here will take
longer before it becomes invalid. Minor downside, we are saying its
OK for this RDS instance to undergo minor version upgrades, which
while fine for a toy example like this, is often not great in prod.
2022-09-06 19:53:38 -04:00
sidpalas
4012eec6cd Update README with link and thumbnail 2022-02-16 12:53:11 -08:00
sid palas
75922067d8 disable staging deploy 2022-02-13 12:23:58 -08:00
16 changed files with 101 additions and 74 deletions

View File

@@ -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:

View File

@@ -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"
}
}
}

View File

@@ -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
}

View File

@@ -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

View File

@@ -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

View File

@@ -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"

View File

@@ -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
}

View File

@@ -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

View File

@@ -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"
}
}
}

View File

@@ -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
}

View File

@@ -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"

View File

@@ -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"

View File

@@ -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"

View File

@@ -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"

View File

@@ -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
```

View File

@@ -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!
[![thumbnail](https://user-images.githubusercontent.com/1320389/154354937-98533608-2f42-44c1-8110-87f7e3f45085.jpeg)](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.