diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..78afb03 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,33 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu +{ + "name": "terrafrom-dev-test", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "image": "mcr.microsoft.com/devcontainers/base:jammy", + + // Features to add to the dev container. More info: https://containers.dev/features. + "features": { + "ghcr.io/devcontainers/features/terraform:1": {}, + "ghcr.io/dhoeric/features/tfsec:1":{}, + }, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "echo 'use tfsec and tflint for better results'", + + // Configure tool-specific properties. + "customizations": { + "vscode": { + "extensions": [ + "hashicorp.terraform", + "gitlens.gitlens" + ] + } + } + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} + + diff --git a/main.tf b/main.tf index 510ad3f..10bac59 100644 --- a/main.tf +++ b/main.tf @@ -1,5 +1,5 @@ provider "aws" { - region = local.region + region = local.region } locals { @@ -9,13 +9,11 @@ locals { ### create a key pair module "key_pair" { - source = "terraform-aws-modules/key-pair/aws" - + source = "terraform-aws-modules/key-pair/aws" key_name = "${local.name}-test-key" create_private_key = true } - ### create a vpc module "vpc" { source = "terraform-aws-modules/vpc/aws" @@ -45,25 +43,23 @@ module "vpc" { module "web_server_sg" { source = "terraform-aws-modules/security-group/aws//modules/http-80" name = "${local.name}-web-server-sg" - description = "Security group for web server of ${local.name}" + description = "Security group for web server of ${local.name}" vpc_id = module.vpc.vpc_id ingress_cidr_blocks = ["0.0.0.0/0"] ingress_rules = ["http-80-tcp", "https-443-tcp", "ssh-tcp"] } - - ### create an ec2 instance module "ec2_instance" { source = "terraform-aws-modules/ec2-instance/aws" - name = "${local.name}-web-server" + name = "${local.name}-web-server" instance_type = "t2.micro" key_name = module.key_pair.key_pair_name monitoring = true - vpc_security_group_ids = [ module.web_server_sg.security_group_id ] + vpc_security_group_ids = [module.web_server_sg.security_group_id] subnet_id = module.vpc.public_subnets[0] - user_data = file("userdata.sh") + user_data = file("userdata.sh") tags = { Terraform = "true"