Sign inSign up

jmshum/aws-terraform-tools

By jmshum

•Updated over 2 years ago

Amazon linux 2 with AWS CLI / ECS CLI tools and Terraform

Image
0

10K+

jmshum/aws-terraform-tools repository overview

⁠Amazon linux 2 with AWS CLI / ECS CLI tools and Terraform

This image is based on Amazon linux 2⁠ and also has the AWS CLI⁠ tools, ECS CLI⁠ tools, python3 / pip3 and Terraform⁠ installed.

⁠Usage

This image is designed to be run in interactive mode with a bash shell. This will allow you to configure the AWS CLI to connect to your AWS account and use Terraform as an environment orchastration tool.
⁠Running the Docker image
docker container run --rm -it jmshum/aws-terraform-tools bash

Verify the AWS CLI tool.

 aws --version

Verify the ECS CLI tool.

 ecs-cli --version

Run the following command after the container is running to configure the AWS CLI tool.

 aws configure

⁠Example Usage

⁠AWS EC2 instance list
$ aws ec2 describe-instances
⁠Terraform
$ terraform fmt
$ terraform validate
$ terraform init
$ terraform plan
$ terraform apply

(main.tf example)

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 3.71"
    }
  }

  required_version = ">= 0.14.9"
}

provider "aws" {
  profile = "default"
  region  = "us-east-1"
}

resource "aws_security_group" "nginx" {
  name        = "Public Access for Nginx"
  description = "Public Access for Nginx"

  ingress {
    description = "Web Access Port 80"
    from_port   = 80
    to_port     = 80
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }

  ingress {
    description = "Web Access Port 443"
    from_port   = 443
    to_port     = 443
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }

  egress {
    from_port   = 0
    to_port     = 0
    protocol    = "-1"
    cidr_blocks = ["0.0.0.0/0"]
  }
}

resource "aws_instance" "app_server" {
  ami                    = "ami-0a1eddae0b7f0a79f" #Amazonlinux 2 Kernel 5.10 64-bit ARM
  instance_type          = "t4g.nano"
  vpc_security_group_ids = [aws_security_group.nginx.id]

  tags = {
    Name = "Terraform-Example-Instance"
  }

  user_data = <<-EOF
    #!/usr/bin/bash
    sudo yum update -y
    sudo amazon-linux-extras install docker
    sudo yum install docker -y
    sudo service docker start
    sudo systemctl enable docker
    sudo usermod -a -G docker ec2-user
    docker container run --rm --name nginx -d -p80:80 nginx
  EOF

}

Tag summary

Content type

Image

Digest

sha256:b2e8e4752…

Size

323.8 MB

Last updated

over 2 years ago

docker pull jmshum/aws-terraform-tools