main.tf 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. data "aws_availability_zones" "available" {
  2. state = "available"
  3. }
  4. module "vpc" {
  5. source = "terraform-aws-modules/vpc/aws"
  6. version = "~> v2.0"
  7. name = "${var.name}"
  8. cidr = "${var.cidr}"
  9. azs = slice(data.aws_availability_zones.available.names,0,3)
  10. private_subnets = [
  11. "${cidrsubnet(var.cidr,3,0)}",
  12. "${cidrsubnet(var.cidr,3,1)}",
  13. "${cidrsubnet(var.cidr,3,2)}",
  14. ]
  15. # Potentially, we could route all accounts through the transit gateway to
  16. # save costs and provide one point of exit to the Internet. But at this time,
  17. # I'm keeping it consistent with our legacy accounts.
  18. #
  19. # If we decide to do that, we should consider either dropping to a /23 per customer,
  20. # or a /24 for each subnet (seems wasteful).
  21. #public_subnets = [ ]
  22. public_subnets = [
  23. "${cidrsubnet(var.cidr,3,4)}",
  24. "${cidrsubnet(var.cidr,3,5)}",
  25. "${cidrsubnet(var.cidr,3,6)}",
  26. ]
  27. enable_nat_gateway = true
  28. enable_dns_hostnames = true
  29. enable_ec2_endpoint = true
  30. ec2_endpoint_private_dns_enabled = true
  31. ec2_endpoint_security_group_ids = [ "${module.aws_endpoints_sg.this_security_group_id}" ]
  32. dhcp_options_domain_name = var.dns_info["private"]["zone"]
  33. tags = merge(var.standard_tags, var.tags)
  34. nat_eip_tags = {
  35. "eip_type" = "natgw"
  36. Name = var.name
  37. }
  38. }
  39. resource "aws_flow_log" "flowlogs" {
  40. iam_role_arn = "arn:${var.aws_partition}:iam::${var.aws_account_id}:role/aws_services/flowlogs"
  41. log_destination = "arn:${var.aws_partition}:logs:${var.aws_region}:${var.aws_account_id}:log-group:vpc_flow_logs"
  42. traffic_type = "REJECT" # ALL is very noisy, and CIS only requires rejects.
  43. vpc_id = module.vpc.vpc_id
  44. tags = merge(var.standard_tags, var.tags)
  45. }