-
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.
backend api setup works, auto generate api configuration
- Loading branch information
1 parent
accc605
commit 052fcbd
Showing
13 changed files
with
627 additions
and
115 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,37 @@ | ||
resource "aws_api_gateway_rest_api" "api" { | ||
name = "schafkopf-api" | ||
|
||
endpoint_configuration { | ||
types = ["REGIONAL"] | ||
} | ||
resource "aws_apigatewayv2_api" "schafkopf_api" { | ||
name = "schafkopf_api" | ||
protocol_type = "HTTP" | ||
} | ||
|
||
|
||
resource "aws_api_gateway_domain_name" "api" { | ||
domain_name = local.api_sub_domain | ||
regional_certificate_arn = aws_acm_certificate.certs.arn | ||
endpoint_configuration { | ||
types = ["REGIONAL"] | ||
} | ||
resource "aws_apigatewayv2_integration" "schafkopf_api" { | ||
api_id = aws_apigatewayv2_api.schafkopf_api.id | ||
integration_type = "AWS_PROXY" | ||
integration_uri = aws_lambda_function.api.invoke_arn | ||
} | ||
/* | ||
resource "aws_api_gateway_base_path_mapping" "api" { | ||
domain_name = aws_api_gateway_domain_name.api.domain_name | ||
stage_name = aws_api_gateway_stage.api.stage_name | ||
api_id = aws_api_gateway_rest_api.api.id | ||
}*/ | ||
|
||
|
||
resource "aws_api_gateway_rest_api_policy" "api_policy" { | ||
rest_api_id = aws_api_gateway_rest_api.api.id | ||
|
||
policy = jsonencode({ | ||
Version = "2012-10-17", | ||
Statement = [ | ||
{ | ||
Effect = "Allow", | ||
Principal = "*", # Change this to specific principals in production | ||
Action = "execute-api:Invoke", | ||
Resource = "${aws_api_gateway_rest_api.api.execution_arn}/*" # Allows access to all resources and methods | ||
} | ||
] | ||
}) | ||
resource "aws_apigatewayv2_route" "schafkopf_api" { | ||
api_id = aws_apigatewayv2_api.schafkopf_api.id | ||
route_key = "$default" # Catch-all route | ||
target = "integrations/${aws_apigatewayv2_integration.schafkopf_api.id}" | ||
} | ||
|
||
|
||
/*resource "aws_api_gateway_deployment" "api" { | ||
rest_api_id = aws_api_gateway_rest_api.api.id | ||
triggers = { | ||
# NOTE: The configuration below will satisfy ordering considerations, | ||
# but not pick up all future REST API changes. More advanced patterns | ||
# are possible, such as using the filesha1() function against the | ||
# Terraform configuration file(s) or removing the .id references to | ||
# calculate a hash against whole resources. Be aware that using whole | ||
# resources will show a difference after the initial implementation. | ||
# It will stabilize to only change when resources change afterwards. | ||
redeployment = sha1(jsonencode([ | ||
aws_api_gateway_resource.api.id, | ||
aws_api_gateway_method.api.id, | ||
aws_api_gateway_integration.api.id, | ||
aws_api_gateway_rest_api.api.id | ||
])) | ||
} | ||
depends_on = [ | ||
aws_api_gateway_integration.api, | ||
] | ||
} | ||
resource "aws_api_gateway_stage" "api" { | ||
deployment_id = aws_api_gateway_deployment.api.id | ||
rest_api_id = aws_api_gateway_rest_api.api.id | ||
stage_name = "v1" | ||
}*/ | ||
|
||
resource "aws_api_gateway_resource" "api" { | ||
rest_api_id = aws_api_gateway_rest_api.api.id | ||
parent_id = aws_api_gateway_rest_api.api.root_resource_id | ||
path_part = "{proxy+}" | ||
resource "aws_apigatewayv2_stage" "default_stage" { | ||
api_id = aws_apigatewayv2_api.schafkopf_api.id | ||
name = "$default" | ||
auto_deploy = true | ||
} | ||
|
||
resource "aws_api_gateway_method" "api" { | ||
rest_api_id = aws_api_gateway_rest_api.api.id | ||
resource_id = aws_api_gateway_resource.api.id | ||
http_method = "ANY" | ||
authorization = "NONE" | ||
|
||
request_parameters = { | ||
"method.request.path.proxy" = true | ||
resource "aws_apigatewayv2_domain_name" "custom_domain" { | ||
domain_name = local.api_sub_domain | ||
domain_name_configuration { | ||
certificate_arn = aws_acm_certificate_validation.cert-validation.certificate_arn | ||
endpoint_type = "REGIONAL" | ||
security_policy = "TLS_1_2" | ||
} | ||
} | ||
/* | ||
resource "aws_api_gateway_integration" "api" { | ||
rest_api_id = aws_api_gateway_rest_api.api.id | ||
resource_id = aws_api_gateway_resource.api.id | ||
http_method = aws_api_gateway_method.api.http_method | ||
integration_http_method = "POST" | ||
type = "AWS_PROXY" | ||
uri = aws_lambda_function.api.invoke_arn | ||
} | ||
*/ | ||
|
||
resource "aws_apigatewayv2_api_mapping" "custom_domain_mapping" { | ||
api_id = aws_apigatewayv2_api.schafkopf_api.id | ||
domain_name = aws_apigatewayv2_domain_name.custom_domain.domain_name | ||
stage = aws_apigatewayv2_stage.default_stage.name | ||
} |
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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
resource "aws_route53_record" "api" { | ||
zone_id = data.aws_route53_zone.domain.id | ||
name = aws_api_gateway_domain_name.api.domain_name | ||
resource "aws_route53_record" "custom_domain_record" { | ||
zone_id = data.aws_route53_zone.domain.zone_id | ||
name = local.api_sub_domain | ||
type = "A" | ||
|
||
alias { | ||
name = aws_api_gateway_domain_name.api.domain_name | ||
zone_id = aws_api_gateway_domain_name.api.regional_zone_id | ||
name = aws_apigatewayv2_domain_name.custom_domain.domain_name_configuration[0].target_domain_name | ||
zone_id = aws_apigatewayv2_domain_name.custom_domain.domain_name_configuration[0].hosted_zone_id | ||
evaluate_target_health = false | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
const baseURL = process.env.REACT_APP_API_URL || 'http://localhost:8000'; |
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
Oops, something went wrong.