vpc.tf 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. ###########
  2. # Create a VPC with an Internet gateway for everybody to play in
  3. resource "aws_vpc" "vpc_primary" {
  4. cidr_block = "10.45.0.0/16"
  5. enable_dns_support = true
  6. enable_dns_hostnames = true
  7. tags = {
  8. Name = "Splunk Standalone"
  9. Project = "Splunk"
  10. Environment = "Production"
  11. }
  12. }
  13. resource "aws_internet_gateway" "gw_primary" {
  14. vpc_id = "${aws_vpc.vpc_primary.id}"
  15. tags = {
  16. Name = "Primary Gateway"
  17. }
  18. }
  19. ###########
  20. # Create 3 Subnets, one in each AZ.
  21. # Note that most servers will be spread between 1 and 2, but we need
  22. # 3 AZs for a quorum for the SearchHead Cluster.
  23. data "aws_availability_zones" "available" {}
  24. resource "aws_subnet" "splunk_subnet_0" {
  25. vpc_id = "${aws_vpc.vpc_primary.id}"
  26. cidr_block = "10.45.0.0/24"
  27. availability_zone = "${data.aws_availability_zones.available.names[0]}"
  28. map_public_ip_on_launch = true
  29. tags = {
  30. Name = "Splunk Subnet 0"
  31. }
  32. }
  33. resource "aws_subnet" "splunk_subnet_1" {
  34. vpc_id = "${aws_vpc.vpc_primary.id}"
  35. cidr_block = "10.45.1.0/24"
  36. availability_zone = "${data.aws_availability_zones.available.names[1]}"
  37. map_public_ip_on_launch = true
  38. tags = {
  39. Name = "Splunk Subnet 1"
  40. }
  41. }
  42. resource "aws_subnet" "splunk_subnet_2" {
  43. vpc_id = "${aws_vpc.vpc_primary.id}"
  44. cidr_block = "10.45.2.0/24"
  45. availability_zone = "${data.aws_availability_zones.available.names[2]}"
  46. map_public_ip_on_launch = true
  47. tags = {
  48. Name = "Splunk Subnet 2"
  49. }
  50. }
  51. ###########
  52. # Create a route table
  53. resource "aws_route_table" "r" {
  54. vpc_id = "${aws_vpc.vpc_primary.id}"
  55. route {
  56. cidr_block = "0.0.0.0/0"
  57. gateway_id = "${aws_internet_gateway.gw_primary.id}"
  58. }
  59. tags = {
  60. Name = "Primary Route Table"
  61. }
  62. }
  63. ###########
  64. # Create an S3 endpoint
  65. resource "aws_vpc_endpoint" "s3" {
  66. vpc_id = "${aws_vpc.vpc_primary.id}"
  67. service_name = "com.amazonaws.us-east-2.s3"
  68. }
  69. resource "aws_vpc_endpoint_route_table_association" "s3_routing" {
  70. route_table_id = "${aws_route_table.r.id}"
  71. vpc_endpoint_id = "${aws_vpc_endpoint.s3.id}"
  72. }
  73. # Associate with VPC
  74. resource "aws_main_route_table_association" "rt_public_a" {
  75. vpc_id = "${aws_vpc.vpc_primary.id}"
  76. route_table_id = "${aws_route_table.r.id}"
  77. }