Skip to content

Commit

Permalink
terraform config
Browse files Browse the repository at this point in the history
  • Loading branch information
vggonzal committed Nov 1, 2023
1 parent daa93f3 commit 75c8749
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 41 deletions.
28 changes: 14 additions & 14 deletions terraform/api-specification-templates/hydrocron_aws_api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,17 @@ paths:
items:
type: string
x-openapi-router-controller: hydrocron_api.controllers.timeseries
x-amazon-apigateway-policy:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal: '*'
Action: 'execute-api:Invoke'
Resource: '*'
- Effect: Deny
Principal: '*'
Action: 'execute-api:Invoke'
Resource: '*'
Condition:
StringNotEquals:
'aws:SourceVpc': ${vpc_id}
x-amazon-apigateway-policy:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal: '*'
Action: 'execute-api:Invoke'
Resource: '*'
- Effect: Deny
Principal: '*'
Action: 'execute-api:Invoke'
Resource: '*'
Condition:
StringNotEquals:
'aws:SourceVpc': ${vpc_id}
22 changes: 11 additions & 11 deletions terraform/hydrocron-lambda-iam.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# IAM roles

resource "aws_iam_instance_profile" "hydrocron-service-profile-test" {
name = aws_iam_role.hydrocron-service-role-test.name
role = aws_iam_role.hydrocron-service-role-test.name
resource "aws_iam_instance_profile" "hydrocron-service-profile" {
name = aws_iam_role.hydrocron-service-role.name
role = aws_iam_role.hydrocron-service-role.name
}

resource "aws_iam_policy" "hydrocron-service-policy-test" {
name = "${local.ec2_resources_name}-service-policy-test"
resource "aws_iam_policy" "hydrocron-service-policy" {
name = "${local.ec2_resources_name}-service-policy"
path = "/"
policy = <<POLICY
{
Expand Down Expand Up @@ -83,8 +83,8 @@ resource "aws_iam_policy" "hydrocron-service-policy-test" {
POLICY
}

resource "aws_iam_role" "hydrocron-service-role-test" {
name = "${local.ec2_resources_name}-service-role-test"
resource "aws_iam_role" "hydrocron-service-role" {
name = "${local.ec2_resources_name}-service-role"

permissions_boundary = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:policy/NGAPShRoleBoundary"
assume_role_policy = <<EOF
Expand All @@ -104,8 +104,8 @@ resource "aws_iam_role" "hydrocron-service-role-test" {
EOF
}

resource "aws_iam_policy_attachment" "hydrocron-service-attach-test" {
name = "${local.ec2_resources_name}-attachment-test"
roles = [aws_iam_role.hydrocron-service-role-test.id]
policy_arn = aws_iam_policy.hydrocron-service-policy-test.arn
resource "aws_iam_policy_attachment" "hydrocron-service-attach" {
name = "${local.ec2_resources_name}-attachment"
roles = [aws_iam_role.hydrocron-service-role.id]
policy_arn = aws_iam_policy.hydrocron-service-policy.arn
}
30 changes: 15 additions & 15 deletions terraform/hydrocron-main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ data "aws_ssm_parameter" "hydrocron-db-sg" {
}


resource "aws_api_gateway_deployment" "hydrocron-api-gateway-deployment-test" {
rest_api_id = aws_api_gateway_rest_api.hydrocron-api-gateway-test.id
resource "aws_api_gateway_deployment" "hydrocron-api-gateway-deployment" {
rest_api_id = aws_api_gateway_rest_api.hydrocron-api-gateway.id
stage_name = "default"
depends_on = [aws_api_gateway_rest_api.hydrocron-api-gateway-test]
depends_on = [aws_api_gateway_rest_api.hydrocron-api-gateway]
triggers = {
redeployment = sha1(jsonencode([
aws_api_gateway_rest_api.hydrocron-api-gateway-test.body
aws_api_gateway_rest_api.hydrocron-api-gateway.body
]))
}
}
Expand Down Expand Up @@ -91,7 +91,7 @@ resource "aws_lambda_function" "hydrocron_lambda_timeseries" {
command = ["hydrocron_api.controllers.timeseries.lambda_handler"]
}
function_name = "${local.lambda_resources_name}-hydrocron_lambda_timeseries"
role = aws_iam_role.hydrocron-service-role-test.arn
role = aws_iam_role.hydrocron-service-role.arn
timeout = 5
runtime = "python3.8"

Expand All @@ -114,21 +114,21 @@ resource "aws_lambda_function" "hydrocron_lambda_timeseries" {



resource "aws_lambda_permission" "allow_hydrocron-timeseries-test" {
resource "aws_lambda_permission" "allow_hydrocron-timeseries" {
statement_id = "AllowAPIGatewayInvoke"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.hydrocron_lambda_timeseries.function_name
principal = "apigateway.amazonaws.com"

# The "/*/*/*" portion grants access from any method on any resource
# within the API Gateway REST API.
source_arn = "${aws_api_gateway_rest_api.hydrocron-api-gateway-test.execution_arn}/*/*/*"
source_arn = "${aws_api_gateway_rest_api.hydrocron-api-gateway.execution_arn}/*/*/*"
}


# API Gateway
resource "aws_api_gateway_rest_api" "hydrocron-api-gateway-test" {
name = "${local.ec2_resources_name}-api-gateway-test"
resource "aws_api_gateway_rest_api" "hydrocron-api-gateway" {
name = "${local.ec2_resources_name}-api-gateway"
description = "API to access Hydrocron - test"
body = templatefile(
"${path.module}/api-specification-templates/hydrocron_aws_api.yml",
Expand All @@ -147,18 +147,18 @@ resource "aws_api_gateway_rest_api" "hydrocron-api-gateway-test" {
}
}

resource "aws_cloudwatch_log_group" "hydrocron-api-gateway-logs-test" {
name = "API-Gateway-Execution-Logs_${aws_api_gateway_rest_api.hydrocron-api-gateway-test.id}/${aws_api_gateway_deployment.hydrocron-api-gateway-deployment-test.stage_name}"
resource "aws_cloudwatch_log_group" "hydrocron-api-gateway-logs" {
name = "API-Gateway-Execution-Logs_${aws_api_gateway_rest_api.hydrocron-api-gateway.id}/${aws_api_gateway_deployment.hydrocron-api-gateway-deployment.stage_name}"
retention_in_days = 60
}

output "url" {
value = "${aws_api_gateway_deployment.hydrocron-api-gateway-deployment-test.invoke_url}/api"
value = "${aws_api_gateway_deployment.hydrocron-api-gateway-deployment.invoke_url}/api"
}

resource "aws_ssm_parameter" "hydrocron-api-url-test" {
name = "hydrocron-api-url-test"
resource "aws_ssm_parameter" "hydrocron-api-url" {
name = "hydrocron-api-url"
type = "String"
value = aws_api_gateway_deployment.hydrocron-api-gateway-deployment-test.invoke_url
value = aws_api_gateway_deployment.hydrocron-api-gateway-deployment.invoke_url
overwrite = true
}
2 changes: 1 addition & 1 deletion terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ variable "docker_tag" {
}

variable "service_name" {
default = "hydrocron-api-test"
default = "hydrocron-api"
type = string
}

Expand Down

0 comments on commit 75c8749

Please sign in to comment.