-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from K8sKween/init-001-vm
Init module MVP
- Loading branch information
Showing
13 changed files
with
697 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
resource "aws_api_gateway_rest_api" "route53_api" { | ||
name = "Route53FlashpointAPI" | ||
description = "API for Route53Flashpoint DNS Management" | ||
tags = var.common_tags | ||
} | ||
|
||
resource "aws_api_gateway_deployment" "route53_api_deployment" { | ||
depends_on = [ | ||
aws_api_gateway_integration.create_record_lambda_integration, | ||
aws_api_gateway_integration.delete_record_lambda_integration, | ||
aws_api_gateway_integration.reports_lambda_integration, | ||
] | ||
|
||
rest_api_id = aws_api_gateway_rest_api.route53_api.id | ||
stage_name = "v1" | ||
#Forces a redeployment of the API Gateway when the Lambda functions are updated | ||
triggers = { | ||
redeployment = sha1(join("", tolist([ | ||
aws_api_gateway_integration.create_record_lambda_integration.id, | ||
aws_api_gateway_integration.delete_record_lambda_integration.id, | ||
aws_api_gateway_integration.reports_lambda_integration.id, | ||
var.force_deploy | ||
]))) | ||
} | ||
} | ||
|
||
resource "aws_api_gateway_resource" "dns_record_resource" { | ||
rest_api_id = aws_api_gateway_rest_api.route53_api.id | ||
parent_id = aws_api_gateway_rest_api.route53_api.root_resource_id | ||
path_part = "route53dnsrecord" | ||
} | ||
|
||
resource "aws_api_gateway_resource" "reports_resource" { | ||
rest_api_id = aws_api_gateway_rest_api.route53_api.id | ||
parent_id = aws_api_gateway_rest_api.route53_api.root_resource_id | ||
path_part = "reports" | ||
} | ||
|
||
##Create Route53 Records Endpoint | ||
|
||
resource "aws_api_gateway_method" "create_dns_record_post" { | ||
rest_api_id = aws_api_gateway_rest_api.route53_api.id | ||
resource_id = aws_api_gateway_resource.dns_record_resource.id | ||
http_method = "POST" | ||
authorization = "AWS_IAM" | ||
} | ||
|
||
resource "aws_api_gateway_integration" "create_record_lambda_integration" { | ||
rest_api_id = aws_api_gateway_rest_api.route53_api.id | ||
resource_id = aws_api_gateway_resource.dns_record_resource.id | ||
http_method = aws_api_gateway_method.create_dns_record_post.http_method | ||
|
||
integration_http_method = "POST" | ||
type = "AWS_PROXY" | ||
uri = aws_lambda_function.create_record_lambda.invoke_arn | ||
|
||
credentials = aws_iam_role.api_gateway_lambda_role.arn | ||
} | ||
|
||
resource "aws_api_gateway_method_response" "create_response_200" { | ||
rest_api_id = aws_api_gateway_rest_api.route53_api.id | ||
resource_id = aws_api_gateway_resource.dns_record_resource.id | ||
http_method = aws_api_gateway_method.create_dns_record_post.http_method | ||
status_code = "200" | ||
|
||
response_models = { | ||
"application/json" = "Empty" | ||
} | ||
} | ||
|
||
|
||
##Delete Route53 Records Endpoint | ||
|
||
resource "aws_api_gateway_method" "delete_dns_record_delete" { | ||
rest_api_id = aws_api_gateway_rest_api.route53_api.id | ||
resource_id = aws_api_gateway_resource.dns_record_resource.id | ||
http_method = "DELETE" | ||
authorization = "AWS_IAM" | ||
} | ||
|
||
resource "aws_api_gateway_integration" "delete_record_lambda_integration" { | ||
rest_api_id = aws_api_gateway_rest_api.route53_api.id | ||
resource_id = aws_api_gateway_resource.dns_record_resource.id | ||
http_method = aws_api_gateway_method.delete_dns_record_delete.http_method | ||
|
||
integration_http_method = "POST" | ||
type = "AWS_PROXY" | ||
uri = aws_lambda_function.delete_expired_records_lambda.invoke_arn | ||
|
||
credentials = aws_iam_role.api_gateway_lambda_role.arn | ||
} | ||
|
||
resource "aws_api_gateway_method_response" "delete_response_200" { | ||
rest_api_id = aws_api_gateway_rest_api.route53_api.id | ||
resource_id = aws_api_gateway_resource.dns_record_resource.id | ||
http_method = aws_api_gateway_method.delete_dns_record_delete.http_method | ||
status_code = "200" | ||
|
||
response_models = { | ||
"application/json" = "Empty" | ||
} | ||
} | ||
|
||
|
||
##Reports Endpoint | ||
|
||
resource "aws_api_gateway_method" "reports_post" { | ||
rest_api_id = aws_api_gateway_rest_api.route53_api.id | ||
resource_id = aws_api_gateway_resource.reports_resource.id | ||
http_method = "POST" | ||
authorization = "AWS_IAM" | ||
} | ||
|
||
resource "aws_api_gateway_integration" "reports_lambda_integration" { | ||
rest_api_id = aws_api_gateway_rest_api.route53_api.id | ||
resource_id = aws_api_gateway_resource.reports_resource.id | ||
http_method = aws_api_gateway_method.reports_post.http_method | ||
|
||
integration_http_method = "POST" | ||
type = "AWS_PROXY" | ||
uri = aws_lambda_function.records_report_lambda.invoke_arn | ||
|
||
credentials = aws_iam_role.api_gateway_lambda_role.arn | ||
} | ||
|
||
resource "aws_api_gateway_method_response" "reports_response_200" { | ||
rest_api_id = aws_api_gateway_rest_api.route53_api.id | ||
resource_id = aws_api_gateway_resource.reports_resource.id | ||
http_method = aws_api_gateway_method.reports_post.http_method | ||
status_code = "200" | ||
|
||
response_models = { | ||
"application/json" = "Empty" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
resource "aws_iam_role" "api_gateway_lambda_role" { | ||
name = "api_gateway_lambda_role" | ||
tags = var.common_tags | ||
assume_role_policy = jsonencode({ | ||
Version = "2012-10-17", | ||
Statement = [ | ||
{ | ||
Action = "sts:AssumeRole", | ||
Effect = "Allow", | ||
Principal = { | ||
Service = "apigateway.amazonaws.com" | ||
}, | ||
}, | ||
], | ||
}) | ||
} | ||
|
||
resource "aws_iam_role_policy" "api_gateway_lambda_policy" { | ||
name = "api_gateway_lambda_policy" | ||
role = aws_iam_role.api_gateway_lambda_role.id | ||
|
||
policy = jsonencode({ | ||
Version = "2012-10-17", | ||
Statement = [ | ||
{ | ||
Action = [ | ||
"lambda:InvokeFunction" | ||
], | ||
Effect = "Allow", | ||
Resource = [aws_lambda_function.create_record_lambda.arn, aws_lambda_function.delete_expired_records_lambda.arn, aws_lambda_function.records_report_lambda.arn] | ||
}, | ||
], | ||
}) | ||
} |
Oops, something went wrong.