Skip to content

Latest commit

 

History

History
76 lines (49 loc) · 4.62 KB

File metadata and controls

76 lines (49 loc) · 4.62 KB

AWS Essentials: Deploy a virtual machine

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 🤓.

Prerequirements

Before completing any task in the module, make sure that you followed all the steps described in the Environment Setup topic, in particular:

  1. Make sure you have an AWS account.

  2. Install AWS CLI.

  3. Install PowerShell Core.

  4. Install Terraform.

  5. Log in to AWS CLI on your computer by running the command:

    aws configure
    

Task Requirements

In this task, you will deploy a EC2 instance, and install Grafana on it.

To complete this task:

  1. 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 and security_group_id, you can get if as terraform module output in the previous task.

  2. 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 value mate-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 file install-grafana.sh in this repo. Use either file function or multiline string to load the script content to the terraform resource parameter.
  3. After adding the code to the main.tf, review the file outputs.tf and make sure, that all output variables are valid and can output relevant values, as described in the output variable descriptions.

  4. 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
    
  5. 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.

  1. Deploy infrastructure using the following command:

    terraform apply
    

    Make sure to collect module outputs - we will use those values in the next tasks.

  2. 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.

  3. Commit file tfplan.json and submit your solution for review.