2021-01-30 11:07:34 +00:00
|
|
|
terraform {
|
|
|
|
backend "s3" {
|
2021-11-12 11:47:43 +00:00
|
|
|
bucket = "sondehub-terraform"
|
|
|
|
key = "sondehub-main"
|
|
|
|
region = "us-east-1"
|
2021-01-30 11:07:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
provider "aws" {
|
2021-11-12 11:47:43 +00:00
|
|
|
region = "us-east-1"
|
2021-01-30 11:07:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
locals {
|
2021-02-01 06:08:59 +00:00
|
|
|
domain_name = "v2.sondehub.org"
|
2021-01-30 11:07:34 +00:00
|
|
|
}
|
|
|
|
data "aws_caller_identity" "current" {}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-10-08 23:32:22 +00:00
|
|
|
resource "aws_iam_role" "basic_lambda_role" {
|
2021-02-01 06:08:59 +00:00
|
|
|
path = "/service-role/"
|
|
|
|
name = "sonde-api-to-iot-core-role-z9zes3f5"
|
|
|
|
assume_role_policy = <<EOF
|
|
|
|
{
|
|
|
|
"Version": "2012-10-17",
|
|
|
|
"Statement": [{
|
|
|
|
"Effect": "Allow",
|
|
|
|
"Principal": {
|
|
|
|
"Service": "lambda.amazonaws.com"
|
|
|
|
},
|
|
|
|
"Action": "sts:AssumeRole"
|
2021-11-12 10:08:18 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"Effect": "Allow",
|
|
|
|
"Principal": {
|
|
|
|
"Service": "edgelambda.amazonaws.com"
|
|
|
|
},
|
|
|
|
"Action": "sts:AssumeRole"
|
2021-02-01 06:08:59 +00:00
|
|
|
}]
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
max_session_duration = 3600
|
|
|
|
}
|
|
|
|
|
2021-05-20 08:43:50 +00:00
|
|
|
|
|
|
|
|
2021-01-30 11:07:34 +00:00
|
|
|
|
2021-10-08 23:32:22 +00:00
|
|
|
resource "aws_iam_role_policy" "basic_lambda_role" {
|
2021-02-01 06:08:59 +00:00
|
|
|
policy = <<EOF
|
2021-01-30 11:07:34 +00:00
|
|
|
{
|
|
|
|
"Version": "2012-10-17",
|
|
|
|
"Statement": [
|
2021-04-28 11:32:22 +00:00
|
|
|
{
|
|
|
|
"Effect": "Allow",
|
|
|
|
"Action": "s3:*",
|
|
|
|
"Resource": "*"
|
2021-05-23 13:14:15 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"Effect": "Allow",
|
|
|
|
"Action": "sns:*",
|
|
|
|
"Resource": "*"
|
2021-02-15 05:23:51 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"Effect": "Allow",
|
|
|
|
"Action": "logs:CreateLogGroup",
|
|
|
|
"Resource": "arn:aws:logs:us-east-1:${data.aws_caller_identity.current.account_id}:*"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Effect": "Allow",
|
|
|
|
"Action": [
|
|
|
|
"logs:CreateLogStream",
|
|
|
|
"logs:PutLogEvents"
|
|
|
|
],
|
|
|
|
"Resource": [
|
|
|
|
"arn:aws:logs:us-east-1:${data.aws_caller_identity.current.account_id}:log-group:/aws/lambda/*"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
EOF
|
2021-10-08 23:32:22 +00:00
|
|
|
role = aws_iam_role.basic_lambda_role.name
|
2021-02-15 05:23:51 +00:00
|
|
|
}
|
|
|
|
|
2021-10-08 23:32:22 +00:00
|
|
|
|
|
|
|
|
2021-01-30 11:07:34 +00:00
|
|
|
resource "aws_route53_zone" "Route53HostedZone" {
|
2021-02-01 06:08:59 +00:00
|
|
|
name = "${local.domain_name}."
|
2021-01-30 11:07:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_route53_record" "cert_validation" {
|
|
|
|
for_each = {
|
|
|
|
for dvo in aws_acm_certificate.CertificateManagerCertificate.domain_validation_options : dvo.domain_name => {
|
|
|
|
name = dvo.resource_record_name
|
|
|
|
record = dvo.resource_record_value
|
|
|
|
type = dvo.resource_record_type
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
allow_overwrite = true
|
|
|
|
name = each.value.name
|
|
|
|
records = [each.value.record]
|
|
|
|
ttl = 60
|
|
|
|
type = each.value.type
|
|
|
|
zone_id = aws_route53_zone.Route53HostedZone.zone_id
|
|
|
|
}
|
|
|
|
resource "aws_acm_certificate_validation" "CertificateManagerCertificate" {
|
|
|
|
certificate_arn = aws_acm_certificate.CertificateManagerCertificate.arn
|
|
|
|
validation_record_fqdns = [for record in aws_route53_record.cert_validation : record.fqdn]
|
|
|
|
}
|
|
|
|
resource "aws_acm_certificate" "CertificateManagerCertificate" {
|
2021-02-01 06:08:59 +00:00
|
|
|
domain_name = local.domain_name
|
|
|
|
subject_alternative_names = [
|
|
|
|
"*.${local.domain_name}"
|
|
|
|
]
|
|
|
|
validation_method = "DNS"
|
2021-10-09 01:57:32 +00:00
|
|
|
}
|
2021-11-12 10:08:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
resource "aws_acm_certificate" "CertificateManagerCertificate_root" {
|
|
|
|
domain_name = local.domain_name
|
|
|
|
subject_alternative_names = [
|
|
|
|
"*.${local.domain_name}",
|
|
|
|
"sondehub.org",
|
|
|
|
"*.sondehub.org"
|
|
|
|
]
|
|
|
|
validation_method = "DNS"
|
2021-11-12 11:47:43 +00:00
|
|
|
}
|