-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackend.tf
48 lines (37 loc) · 1019 Bytes
/
backend.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# challenge/terraform
# backend.tf
// Note: Initially, comment out the backend block (local state)
// since Terraform will create the S3 bucket. After the first run,
// switch to S3.
variable "terraform_bucket" {
type = string
default = "challenge-keyrock-rhdguk"
}
// consider attaching policy and define the policy
// object creating o who has access to it
module "s3_bucket" {
source = "terraform-aws-modules/s3-bucket/aws"
version = "~> 4.0"
bucket = var.terraform_bucket
versioning = {
status = "Enabled"
}
server_side_encryption_configuration = {
rule = {
apply_server_side_encryption_by_default = {
sse_algorithm = "AES256"
}
}
}
}
// 2nd step migrate state to bucket with removing the below comments and running:
// terraform init -migrate-state
// As variables not allowed here so the bucket name
// is hard coded
terraform {
backend "s3" {
bucket = "challenge-keyrock-rhdguk"
key = "terraform/state"
region = "us-east-1"
}
}