Skip to content

A brief way to provision a EC2 instance on AWS Cloud using some Terraform best practices like variables. https://aws.amazon.com/pt/ec2/

License

Notifications You must be signed in to change notification settings

Terraform-Tutorials/terraform-aws-ec2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Terraform AWS EC2

This project is a way to provision a basic EC2 with variables on AWS using Terraform CLI. According to Terraform documentation, it's a good practice create several ".tf" files to organize your project, when invoking any command that loads the Terraform configuration, Terraform loads all configuration files within the directory specified in alphabetical order.

Credentials on AWS

Use this article to get your credentials have crated at AWS.

Usage

  • First of all, check if your code is correct:
$ terraform fmt
  • Prepare your working directory for other commands:
$ terraform init
  • Show changes required by the current configuration:
$ terraform plan
  • Create or update infrastructure:
$ terraform apply
  • Destroy previously-created infrastructure:
$ terraform destroy

Basic Examples

  • A basic example for provider .tf:
terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 3.0"
    }
  }
}

provider "aws" {
  region = var.region
}

resource "aws_instance" "tutorials" {
  ami           = var.ami
  instance_type = var.instance_type
}
  • A basix example for variables .tf:
variable "region" {
  description = "define what region"
  default     = "us-east-1"
}

variable "ami" {
  description = "define what AMI"
  default     = "ami-09e67e426f25ce0d7"
}

variable "instance_type" {
  description = "value"
  default     = "t2.micro"
}    

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT