This day has come - you are deploying Grafana! Of course, to deploy grafana you will need a virtual machine, you will do evetyhing with terraform, and we will build on top of what you did in the previous task 🤓.
Before completing any task in the module, make sure that you followed all the steps described in the Environment Setup topic, in particular:
-
Make sure you have an AWS account.
-
Install AWS CLI.
-
Install PowerShell Core.
-
Install Terraform.
-
Log in to AWS CLI on your computer by running the command:
aws configure
In this task, you will deploy a EC2 instance, and install Grafana on it.
To complete this task:
-
Edit
terraform.tfvars
- fill out tfvars file with the outputs from the previous modules and your own configuration variables. You should use those variables as parameters for the resources in this task. This task requires only two variables -subnet_id
andsecurity_group_id
, you can get if as terraform module output in the previous task. -
Edit
main.tf
— add resources, required for this task:-
uncommend the aws_ami resource and it's configuration, and use it to get the AMI id for your EC2 instance deployment
-
use resource aws_key_pair to create a SSH key pair resource for your EC2 instance.
- For the resource, you have to provide a RSA SSH public key (if you don't have one - generate it).
- If you want to get a bonus - use file function to load the public key file content from your .ssh folder instead of hardcoding it in the terraform.
-
use resource aws_instance to deploy an EC2 instance and install Grafana on it!
- Use datasource you uncommented to get the AMI id
- Use 't2.micro' instance type
- Enable association of public IP address
- Deploy VM to the subnet you deployed in the previous task
- Use security group you created in the previous task (for that, use parameter
vpc_security_group_ids
) - Use key pair you are deploying in this module
- Create a
Name
tag with valuemate-aws-grafana-lab
- Install Grafana on the VM using cloud init (parameter is called
user_data
). You can find a bash script for installing Grafana in the fileinstall-grafana.sh
in this repo. Use either file function or multiline string to load the script content to the terraform resource parameter.
-
-
After adding the code to the
main.tf
, review the fileoutputs.tf
and make sure, that all output variables are valid and can output relevant values, as described in the output variable descriptions. -
Run the following commands to generate a Terraform execution plan in JSON format:
terraform init terraform plan -out=tfplan terraform show -json tfplan > tfplan.json
-
Run an automated test to check yourself:
pwsh ./tests/test-tf-plan.ps1
If any test fails - please check your task code and repeat step 4 to generage a new tfplan.json file.
-
Deploy infrastructure using the following command:
terraform apply
Make sure to collect module outputs - we will use those values in the next tasks.
-
Wait for 5 minutes after the deployment, and try to open that grafana URL from the terraform module output. When loging in for the first time, you will be prompted to change the admin password. Save the new password somewhere - you will need it for the next task.
-
Commit file
tfplan.json
and submit your solution for review.