Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
# 1. Deploy an S3 storage bucket
# 1. Deploy an S3 storage bucket
resource "aws_s3_bucket" "my_grafana_backups" {
bucket = "my-grafana-backups-data"

# 2. Confugure bucket policy to allow grafana iam role to use storage
tags = {
Name = "My bucket"
Environment = "Dev"
}
}
# 2. Confugure bucket policy to allow grafana iam role to use storage
resource "aws_s3_bucket_policy" "grafana-access" {
bucket = aws_s3_bucket.my_grafana_backups.id
policy = data.aws_iam_policy_document.example.json
}
data "aws_iam_policy_document" "example" {
statement {
principals {
type = "AWS"
identifiers = [var.grafana_iam_role_arn]
}

actions = ["s3:ListBucket"]
resources = ["arn:aws:s3:::${aws_s3_bucket.my_grafana_backups.bucket}"]
}
statement {
principals {
type = "AWS"
identifiers = [var.grafana_iam_role_arn]
}

actions = ["s3:GetObject","s3:PutObject"]
resources = ["arn:aws:s3:::${aws_s3_bucket.my_grafana_backups.bucket}/*"]
}
}
2 changes: 1 addition & 1 deletion outputs.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
output "bucket_name" {
value = aws_s3_bucket.grafana_backups.bucket
value = aws_s3_bucket.my_grafana_backups.bucket
sensitive = false
}
2 changes: 1 addition & 1 deletion terraform.tfvars
Original file line number Diff line number Diff line change
@@ -1 +1 @@
grafana_iam_role_arn = ""
grafana_iam_role_arn = "arn:aws:iam::891146181442:role/grafana_role"
Loading