Skip to content

Commit 7a3fdac

Browse files
03-basics: Fix deprecation warnings and postgres version error (sidpalas#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.
1 parent 4012eec commit 7a3fdac

File tree

2 files changed

+38
-23
lines changed

2 files changed

+38
-23
lines changed

03-basics/aws-backend/main.tf

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,20 @@ provider "aws" {
2727
resource "aws_s3_bucket" "terraform_state" {
2828
bucket = "devops-directive-tf-state" # REPLACE WITH YOUR BUCKET NAME
2929
force_destroy = true
30-
versioning {
31-
enabled = true
30+
}
31+
32+
resource "aws_s3_bucket_versioning" "terraform_bucket_versioning" {
33+
bucket = aws_s3_bucket.terraform_state.id
34+
versioning_configuration {
35+
status = "Enabled"
3236
}
37+
}
3338

34-
server_side_encryption_configuration {
35-
rule {
36-
apply_server_side_encryption_by_default {
37-
sse_algorithm = "AES256"
38-
}
39+
resource "aws_s3_bucket_server_side_encryption_configuration" "terraform_state_crypto_conf" {
40+
bucket = aws_s3_bucket.terraform_state.bucket
41+
rule {
42+
apply_server_side_encryption_by_default {
43+
sse_algorithm = "AES256"
3944
}
4045
}
4146
}

03-basics/web-app/main.tf

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,20 @@ resource "aws_instance" "instance_2" {
4646
resource "aws_s3_bucket" "bucket" {
4747
bucket = "devops-directive-web-app-data"
4848
force_destroy = true
49-
versioning {
50-
enabled = true
49+
}
50+
51+
resource "aws_s3_bucket_versioning" "bucket_versioning" {
52+
bucket = aws_s3_bucket.bucket.id
53+
versioning_configuration {
54+
status = "Enabled"
5155
}
56+
}
5257

53-
server_side_encryption_configuration {
54-
rule {
55-
apply_server_side_encryption_by_default {
56-
sse_algorithm = "AES256"
57-
}
58+
resource "aws_s3_bucket_server_side_encryption_configuration" "bucket_crypto_conf" {
59+
bucket = aws_s3_bucket.bucket.bucket
60+
rule {
61+
apply_server_side_encryption_by_default {
62+
sse_algorithm = "AES256"
5863
}
5964
}
6065
}
@@ -198,13 +203,18 @@ resource "aws_route53_record" "root" {
198203
}
199204

200205
resource "aws_db_instance" "db_instance" {
201-
allocated_storage = 20
202-
storage_type = "standard"
203-
engine = "postgres"
204-
engine_version = "12.5"
205-
instance_class = "db.t2.micro"
206-
name = "mydb"
207-
username = "foo"
208-
password = "foobarbaz"
209-
skip_final_snapshot = true
206+
allocated_storage = 20
207+
# This allows any minor version within the major engine_version
208+
# defined below, but will also result in allowing AWS to auto
209+
# upgrade the minor version of your DB. This may be too risky
210+
# in a real production environment.
211+
auto_minor_version_upgrade = true
212+
storage_type = "standard"
213+
engine = "postgres"
214+
engine_version = "12"
215+
instance_class = "db.t2.micro"
216+
name = "mydb"
217+
username = "foo"
218+
password = "foobarbaz"
219+
skip_final_snapshot = true
210220
}

0 commit comments

Comments
 (0)