Giter Site home page Giter Site logo

aws-terraform's Introduction

AWS Terraform & Terratest

Tests

Use Cases

Prerequisites

  • Make sure to have Go 1.17 installed on your computer

  • Set your AWS credentials as environmental variables

      export AWS_ACCESS_KEY_ID="anaccesskey"
      export AWS_SECRET_ACCESS_KEY="asecretkey"
    

NOTE:: More information here AWS Terraform provider

EC2 Instance & S3 Bucket

  • Go to the EC2 Instance & S3 Bucket folder

      cd ec2-s3
    
  • Initialize Terraform and the AWS provider

      terraform init
    
  • Setup the EC2 Intances, Network and S3 Bucket configuration in the file ec2-s3/variables.auto.tfvars. Here an example:

networks = [
  {
    network = "172.16.0.0/16"
    subnets = [
      {
        cidr = "172.16.1.0/24"
        az   = "us-east-2a"
      }
    ]
  }
]

instances = [
  {
    name   = "VM1"
    ami    = "ami-089c6f2e3866f0f14"
    type   = "t2.micro"
    subnet = "172.16.1.0/24"
    ips    = ["172.16.1.10"]
    tags = {
      Name  = "Flugel"
      Owner = "InfraTeam"
    }
  }
]

storage = [
  {
    name = "my-aws-bucket"
    acl  = "private"
    tags = {
      Name  = "Flugel"
      Owner = "InfraTeam"
    }
  }
]

NOTE:: See the ec2-s3/variables.tf file to check the supported schema

  • Execute Terraform

      terraform apply -auto-approve
    
  • Destroy Terraform Resources (Optional)

      terraform destroy -auto-approve
    

ALB and EC2 Instances

  • Go to the ALB and EC2 Instances folder

      cd alb-ec2
    
  • Initialize Terraform and the AWS provider

      terraform init
    
  • Setup the EC2 Intances and Networks configuration in the file alb-ec2/variables.auto.tfvars. Here an example:

alb = {
  servers = [
    {
      name   = "VM1"
      subnet = "172.16.0.0/24"
      ami    = "ami-089c6f2e3866f0f14"
      type   = "t2.micro"
    },
    {
      name   = "VM2"
      subnet = "172.16.1.0/24"
      ami    = "ami-089c6f2e3866f0f14"
      type   = "t2.micro"
    }
  ]
  network = "172.16.0.0/16"
  subnets = [
    {
      cidr = "172.16.0.0/24"
      az   = "us-east-2a"
    },
    {
      cidr = "172.16.1.0/24"
      az   = "us-east-2b"
    }
  ]
}

NOTE:: See the alb-ec2/variables.tf file to check the supported schema

  • Execute Terraform

      terraform apply -auto-approve
    
  • Destroy Terraform Resources (Optional)

      terraform destroy -auto-approve
    

Terratest

  • Go to the terratest folder and download the Go dependencies

      cd terratest
      go get -v -d
    
  • Execute the test file terraform_test.go

      go test -v
    

aws-terraform's People

Contributors

jgomezve avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.