main.tf 6.51 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
// Configure remote state
terraform {
  backend "s3" {}
}

// Use credentials from environment or shared credentials file
provider "aws" {
  region  = "us-east-1"
  version = "~> 1.41"
}

12 13
// Policies
resource "aws_iam_policy" "snowplow_collector_policy" {
Cameron McFarland's avatar
Cameron McFarland committed
14
  description = "Policy the allows the collector to access other AWS services such as Kinesis."
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
  name        = "snowplow-collector-policy"
  path        = "/"
  policy      = <<EOF
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "",
            "Effect": "Allow",
            "Action": [
                "cloudwatch:PutMetricData"
            ],
            "Resource": [
                "*"
            ]
        },
        {
            "Sid": "",
            "Effect": "Allow",
            "Action": [
                "kinesis:*"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}
EOF
}

resource "aws_iam_policy" "snowplow_enricher_policy" {
Cameron McFarland's avatar
Cameron McFarland committed
47
description = ""
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
name        = "snowplow-enricher-policy"
path        = "/"
policy      = <<EOF
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "",
            "Effect": "Allow",
            "Action": [
                "cloudwatch:PutMetricData"
            ],
            "Resource": [
                "*"
            ]
        },
        {
            "Sid": "",
            "Effect": "Allow",
            "Action": [
                "dynamodb:*"
            ],
            "Resource": [
                "arn:aws:dynamodb:us-east-1:855262394183:table/SnowplowEnrich-gitlab-us-east-1"
            ]
        },
        {
            "Sid": "",
            "Effect": "Allow",
            "Action": [
                "kinesis:*"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}
EOF
}

resource "aws_iam_policy" "snowplow_s3loader_policy" {
Cameron McFarland's avatar
Cameron McFarland committed
90
description = "Policy to provide AWS access to snowplow s3loader instances such as S3, DynamoDB, and Kinesis."
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
name        = "snowplow-s3loader-policy"
path        = "/"
policy      = <<EOF
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "",
            "Effect": "Allow",
            "Action": [
                "cloudwatch:PutMetricData"
            ],
            "Resource": [
                "*"
            ]
        },
        {
            "Sid": "",
            "Effect": "Allow",
            "Action": [
                "s3:*"
            ],
            "Resource": [
                "arn:aws:s3:::gitlab-com-snowplow-test-one/*"
            ]
        },
        {
            "Sid": "",
            "Effect": "Allow",
            "Action": [
                "dynamodb:*"
            ],
            "Resource": [
                "arn:aws:dynamodb:us-east-1:855262394183:table/SnowplowS3Loader-gitlab-us-east-1"
            ]
        },
        {
            "Sid": "",
            "Effect": "Allow",
            "Action": [
                "kinesis:*"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}
EOF
}

142 143 144 145 146 147 148 149 150 151
// VPC
resource "aws_vpc" "snowplow_vpc" {
  cidr_block       = "10.32.0.0/16"
  tags = {
    Name = "SnowPlow VPC"
    environment = "SnowPlow"
  }
}

// Subnet
152
resource "aws_subnet" "snowplow_subnet_1" {
153
  vpc_id     = "${aws_vpc.snowplow_vpc.id}"
154 155 156 157 158 159 160
  cidr_block = "10.32.2.0/24"
  availability_zone = "us-east-1a"
  tags = {
    Name = "SnowPlow Subnet 1"
    environment = "SnowPlow"
  }
}
161

162 163 164 165
resource "aws_subnet" "snowplow_subnet_2" {
  vpc_id     = "${aws_vpc.snowplow_vpc.id}"
  cidr_block = "10.32.1.0/24"
  availability_zone = "us-east-1e"
166
  tags = {
167
    Name = "SnowPlow Subnet 2"
168 169 170 171
    environment = "SnowPlow"
  }
}

172 173 174 175
resource "aws_subnet" "snowplow_subnet_3" {
  vpc_id     = "${aws_vpc.snowplow_vpc.id}"
  cidr_block = "10.32.0.0/24"
  availability_zone = "us-east-1b"
176
  tags = {
177
    Name = "SnowPlow Subnet 3"
178 179 180 181
    environment = "SnowPlow"
  }
}

182 183 184 185
// Internet Gateway
resource "aws_internet_gateway" "snowplow_gw" {
  vpc_id = "${aws_vpc.snowplow_vpc.id}"

186
  tags = {
187
    Name = "SnowPlow Gateway"
188 189 190 191
    environment = "SnowPlow"
  }
}

192 193 194 195
// Routing Tables
resource "aws_route_table" "snowplow_route_table" {
  vpc_id = "${aws_vpc.snowplow_vpc.id}"

196
  tags = {
197
    Name = "SnowPlow Routing Table"
198 199 200
    environment = "SnowPlow"
  }
}
201

Cameron McFarland's avatar
Cameron McFarland committed
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
resource "aws_main_route_table_association" "snowplow_main_route_table_association" {
  vpc_id         = "${aws_vpc.snowplow_vpc.id}"
  route_table_id = "${aws_route_table.snowplow_route_table.id}"
}

resource "aws_route" "snowplow_route" {
  route_table_id = "${aws_route_table.snowplow_route_table.id}"
  destination_cidr_block = "0.0.0.0/0"
  gateway_id = "${aws_internet_gateway.snowplow_gw.id}"
}

resource "aws_route_table_association" "snowplow_route_table_association_1" {
  route_table_id = "${aws_route_table.snowplow_route_table.id}"
  subnet_id      = "${aws_subnet.snowplow_subnet_1.id}"
}

resource "aws_route_table_association" "snowplow_route_table_association_2" {
  route_table_id = "${aws_route_table.snowplow_route_table.id}"
  subnet_id      = "${aws_subnet.snowplow_subnet_2.id}"
}

resource "aws_route_table_association" "snowplow_route_table_association_3" {
  route_table_id = "${aws_route_table.snowplow_route_table.id}"
  subnet_id      = "${aws_subnet.snowplow_subnet_3.id}"
}

228
// Kinesis Streams
229 230
resource "aws_kinesis_stream" "snowplow_raw_good" {
  name             = "snowplow-raw-good"
231 232
  shard_count      = 1
  retention_period = 48
233 234 235 236
  shard_level_metrics = [
    "IncomingBytes",
    "OutgoingBytes",
  ]
237

238 239 240 241 242 243 244 245 246
  tags = {
    environment = "SnowPlow"
  }
}

resource "aws_kinesis_stream" "snowplow_raw_bad" {
  name             = "snowplow-raw-bad"
  shard_count      = 1
  retention_period = 48
247 248 249 250 251 252 253 254 255 256
  shard_level_metrics = [
    "IncomingBytes",
    "OutgoingBytes",
  ]

  tags = {
    environment = "SnowPlow"
  }
}

257 258
resource "aws_kinesis_stream" "snowplow_enriched_bad" {
  name             = "snowplow-enriched-bad"
259 260
  shard_count      = 1
  retention_period = 48
261 262 263 264
  shard_level_metrics = [
    "IncomingBytes",
    "OutgoingBytes",
  ]
265

266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
  tags = {
    environment = "SnowPlow"
  }
}

resource "aws_kinesis_stream" "snowplow_enriched_good" {
  name             = "snowplow-enriched-good"
  shard_count      = 1
  retention_period = 48
  shard_level_metrics = [
    "IncomingBytes",
    "OutgoingBytes",
  ]

  tags = {
    environment = "SnowPlow"
  }
}

resource "aws_kinesis_stream" "snowplow_s3loader_bad" {
  name             = "snowplow-s3loader-bad"
  shard_count      = 1
  retention_period = 48
289 290 291 292 293 294 295 296 297
  shard_level_metrics = [
    "IncomingBytes",
    "OutgoingBytes",
  ]

  tags = {
    environment = "SnowPlow"
  }
}