Skip to content

Commit 23ec7ec

Browse files
authored
Merge pull request #4 from diggerhq/fix/backend-acls-again
Use terraform that actually works
2 parents 3455728 + 943b3b9 commit 23ec7ec

File tree

2 files changed

+43
-20
lines changed

2 files changed

+43
-20
lines changed

backend/main.tf

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,60 @@ terraform {
22
required_providers {
33
aws = {
44
source = "hashicorp/aws"
5-
version = "5.23.1"
5+
version = "5.24.0"
66
}
77
}
88
}
99

1010
provider "aws" {
11-
region = "us-east-1" # Replace with your desired AWS region
11+
region = "us-east-1"
1212
}
1313

14-
resource "random_string" "bucket_prefix" {
15-
length = 8
16-
special = false
14+
variable "bucket_id" {
15+
type = string
16+
default = "digger-s3backend-quickstart-aws"
1717
}
1818

19-
resource "aws_s3_bucket" "default" {
20-
bucket = "${random_string.bucket_prefix.result}-bucket-tfstate"
19+
variable "dynamo_lock_table_id" {
20+
type = string
21+
default = "digger-locktable-quickstart-aws"
2122
}
2223

23-
resource "aws_s3_bucket_versioning" "versioning_example" {
24-
bucket = aws_s3_bucket.default.id
24+
resource "aws_s3_bucket" "example" {
25+
bucket = var.bucket_id
26+
}
27+
28+
resource "aws_s3_bucket_versioning" "example" {
29+
bucket = aws_s3_bucket.example.id
2530
versioning_configuration {
2631
status = "Enabled"
2732
}
2833
}
2934

30-
resource "aws_s3_bucket_acl" "example" {
31-
bucket = aws_s3_bucket.default.id
32-
acl = "private"
33-
}
35+
resource "aws_s3_bucket_public_access_block" "example" {
36+
bucket = aws_s3_bucket.example.id
3437

38+
block_public_acls = true
39+
block_public_policy = true
40+
ignore_public_acls = true
41+
restrict_public_buckets = true
42+
}
3543

3644
resource "aws_dynamodb_table" "DiggerDynamoDBLockTable" {
37-
name = "DiggerDynamoDBLockTable"
45+
name = var.dynamo_lock_table_id
3846
billing_mode = "PAY_PER_REQUEST"
3947
stream_enabled = true
4048
stream_view_type = "NEW_AND_OLD_IMAGES"
49+
hash_key = "PK"
50+
range_key = "SK"
51+
52+
attribute {
53+
name = "PK"
54+
type = "S"
55+
}
56+
57+
attribute {
58+
name = "SK"
59+
type = "S"
60+
}
4161
}

prod/main.tf

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@ terraform {
22
required_providers {
33
aws = {
44
source = "hashicorp/aws"
5-
version = "3.0.0" # Use an appropriate version
5+
version = "5.24.0"
66
}
77
}
88
backend "s3" {
9-
bucket = "8046b8f4c208f5bb-bucket-tfstate"
9+
bucket = "digger-s3backend-quickstart-aws" # Change if a different S3 bucket name was used for the backend
10+
/* Un-comment to use DynamoDB state locking
11+
dynamodb_table = "digger-locktable-quickstart-aws" # Change if a different DynamoDB table name was used for backend
12+
*/
1013
key = "terraform/state"
1114
region = "us-east-1"
1215
}
13-
1416
}
1517

1618
provider "aws" {
@@ -27,7 +29,7 @@ resource "aws_vpc" "vpc_network" {
2729
resource "aws_subnet" "vpc_subnet" {
2830
vpc_id = aws_vpc.vpc_network.id
2931
cidr_block = "10.0.1.0/24"
30-
availability_zone = "us-east-2a"
32+
availability_zone = "us-east-1a"
3133
map_public_ip_on_launch = true
3234

3335
tags = {
@@ -36,6 +38,7 @@ resource "aws_subnet" "vpc_subnet" {
3638
}
3739

3840
resource "aws_security_group" "security_group" {
41+
vpc_id = aws_vpc.vpc_network.id
3942
name_prefix = "terraform-"
4043
ingress {
4144
from_port = 80
@@ -46,10 +49,10 @@ resource "aws_security_group" "security_group" {
4649
}
4750

4851
resource "aws_instance" "vm_instance" {
49-
ami = "ami-0b17ac7207aae009f" #Debian 11 (bullsey AMI provided by the Debian Project https://wiki.debian.org/Cloud/AmazonEC2Image/Bullseye)
52+
ami = "ami-05c13eab67c5d8861" # us-east-1 Amazon Linux 2023 AMI 2023.2.20231030.1 x86_64 HVM kernel-6.1
5053
instance_type = "t2.micro"
5154
subnet_id = aws_subnet.vpc_subnet.id
52-
security_groups = [aws_security_group.security_group.name]
55+
security_groups = [aws_security_group.security_group.id]
5356
tags = {
5457
Name = "terraform-instance"
5558
}

0 commit comments

Comments
 (0)