terraform {
  required_version = ">= 0.15.0"
  required_providers {
    aws = {
      "configuration_aliases" = [aws.files]
      "source"                = "hashicorp/aws"
      "version"               = ">= 4.0.0"
    }
  }
}

provider "aws" {
  region = "ap-northeast-2"
}

provider "aws" {
  alias  = "files"
  region = "ap-northeast-2"
}

output "vpc_datasaker_id" {
  value = aws_vpc.vpc-datasaker.id
}

output "vpc_datasaker_cidr_block" {
  value = aws_vpc.vpc-datasaker.cidr_block
}



resource "aws_vpc" "vpc-datasaker" {
  assign_generated_ipv6_cidr_block = true
  cidr_block                       = "172.21.0.0/16"
  enable_dns_hostnames             = true
  enable_dns_support               = true
  tags = {
    "Name" = "vpc-datasaker"
  }
}

resource "aws_vpc_dhcp_options" "vpc-dhcp-datasaker" {
  domain_name         = "ap-northeast-2.compute.internal"
  domain_name_servers = ["AmazonProvidedDNS"]
  tags = {
    "Name" = "vpc-dhcp-datasaker"
  }
}

resource "aws_vpc_dhcp_options_association" "vpc-dhcp-asso-datasaker" {
  dhcp_options_id = aws_vpc_dhcp_options.vpc-dhcp-datasaker.id
  vpc_id          = aws_vpc.vpc-datasaker.id
}

resource "aws_internet_gateway" "igw-datasaker" {
  tags = {
    "Name" = "igw-datasaker"
  }
  vpc_id = aws_vpc.vpc-datasaker.id
}


resource "aws_key_pair" "kp-bastion-datasaker" {
  key_name   = "kp-bastion-datasaker"
  public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDv9Bk/20f0xHLQN1Mnub0VwsbRw7ggubeUZ+pUVaX9BD7uUud/ITktmTArbabLJLGgWx64la6+6VuQHauzX/cpMp4dVxoaySQDGPsB+V0WnXaq0pWop5BoJaPO75lpk/Kp7NFtn9x3315Rqmis1Df1UrQehMkqunnr2jWkil6iueAckztpsnqxlb8S+uVYiM7C4HsVx8XdOT3WtfUv+hzDlejy11nzi5T4HMT70O107N4g5CrEapluc7M3NfxCFhz5Gxu8P0dfJKLs9fFT4E8DRfGly5/cDcKbiJHSAZYRN6UwKr3z7LAw8aIW8JWflXn1fMZ92qdiT04kN8ZdVzyMpUiWMXJQPrfI2EHT/OHAympzKrXnT98oIqJANE4Eq72OG9Hrb6Tauk8Bde5/v3P9d7m5Zi9tx+01PZ1JQR+1dkJeV3Am6mjKWrxIowKPol2chnARoU7y1rEZGGi+09bD5hUq7KW6z61DUIlCMYF0Oq0IMs/voQP8zqpDmvSPNJc= hsgahm@ws-ubuntu"
  tags = {
    "Name" = "kp-bastion-datasaker"
  }
}


resource "aws_route_table" "rt-datasaker-pub" {
  tags = {
    "Name" = "rt-datasaker-pub"
  }
  vpc_id = aws_vpc.vpc-datasaker.id
}


resource "aws_route" "r-0-0-0-0--0" {
  destination_cidr_block = "0.0.0.0/0"
  gateway_id = aws_internet_gateway.igw-datasaker.id
  route_table_id = aws_route_table.rt-datasaker-pub.id
}

resource "aws_route" "r-__--0" {
  destination_ipv6_cidr_block = "::/0"
  gateway_id = aws_internet_gateway.igw-datasaker.id
  route_table_id = aws_route_table.rt-datasaker-pub.id
}




