Skip to content

Instantly share code, notes, and snippets.

@nivleshc
Created March 30, 2024 02:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nivleshc/61c3ded4cb13cb07e76edc899be67289 to your computer and use it in GitHub Desktop.
Save nivleshc/61c3ded4cb13cb07e76edc899be67289 to your computer and use it in GitHub Desktop.
Contents of grafana/iam.tf from the visualise-network-traffic repository.
# create an IAM role for the Grafana ec2 instance.
resource "aws_iam_role" "grafana_role" {
name = format("%s-role", var.grafana_server_details["tags"]["Name"])
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
EOF
}
# give the Grafana IAM role permissions to read the CloudWatch Logs
resource "aws_iam_role_policy_attachment" "cloudwatch_readonly_attachment" {
role = aws_iam_role.grafana_role.name
policy_arn = "arn:aws:iam::aws:policy/CloudWatchReadOnlyAccess"
}
# create an IAM instance profile which will be attached to the Grafana ec2 instance
resource "aws_iam_instance_profile" "grafana_profile" {
name = format("%s-instance-profile", var.grafana_server_details["tags"]["Name"])
role = aws_iam_role.grafana_role.name
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment