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
38 changes: 28 additions & 10 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ data "aws_ami" "this" {
owners = ["amazon"]

filter {
name = "name"
name = "name"
values = ["amzn2-ami-hvm-*-gp2"]
}

Expand Down Expand Up @@ -37,8 +37,8 @@ resource "aws_instance" "this" {
instance_type = "t2.micro"

associate_public_ip_address = true
subnet_id = var.subnet_id
vpc_security_group_ids = [var.security_group_id]
subnet_id = var.subnet_id
vpc_security_group_ids = [var.security_group_id]

key_name = aws_key_pair.this.key_name

Expand All @@ -47,17 +47,35 @@ resource "aws_instance" "this" {
}

user_data = file("./install-grafana.sh")

# Added IAM Instance Profile
iam_instance_profile = aws_iam_instance_profile.this.name
}

# 1 - create policy

resource "aws_iam_policy" "this" {
name = "grafana-iam-policy"
description = "Policy for Grafana to read CloudWatch metrics and logs"
policy = file("grafana-policy.json")
}

##############################################
######## Write your code here -> #############
##############################################
# 2 - create role

# 1 - create policy
resource "aws_iam_role" "grafana" {
name = "grafana"
assume_role_policy = file("grafana-role-asume-policy.json")
}

# 2 - create role
# 3 - create policy to role attachment

# 3 - create policy to role attachment
resource "aws_iam_role_policy_attachment" "this" {
role = aws_iam_role.grafana.name
policy_arn = aws_iam_policy.this.arn
}
# 4 - create instance profile

# 4 - create instance profile
resource "aws_iam_instance_profile" "this" {
name = "grafana-iam-instance-profile"
role = aws_iam_role.grafana.name
}
12 changes: 6 additions & 6 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
output "instance_public_ip" {
value = aws_instance.this.public_ip
sensitive = false
value = aws_instance.this.public_ip
sensitive = false
}

output "grafana_url" {
value = "http://${aws_instance.this.public_ip}:3000/"
sensitive = false
value = "http://${aws_instance.this.public_ip}:3000/"
sensitive = false
}

output "grafana_iam_role_arn" {
value = aws_iam_role.grafana.arn
sensitive = false
value = aws_iam_role.grafana.arn
sensitive = false
}
4 changes: 2 additions & 2 deletions terraform.tfvars
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
subnet_id = ""
security_group_id = ""
subnet_id = "subnet-03914deb60122a473"
security_group_id = "sg-0eeb20d7fd2eca733"
1 change: 1 addition & 0 deletions tfplan.json

Large diffs are not rendered by default.

Empty file added tfplan.jsonterraform
Empty file.
8 changes: 4 additions & 4 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
variable "subnet_id" {
type = string
description = "ID of the VPC subnet, you deployed in the previous task."
type = string
description = "ID of the VPC subnet, you deployed in the previous task."
}

variable "security_group_id" {
type = string
description = "ID of the security group, you deployed in the previous task."
type = string
description = "ID of the security group, you deployed in the previous task."
}