-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: link the API gateway resource parent to either rest api or another gateway resource #5697
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch for making the resource names unique |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
provider "aws" { | ||
} | ||
|
||
resource "random_uuid" "unique_id" { | ||
keepers = { | ||
my_key = "my_key" | ||
} | ||
} | ||
|
||
resource "aws_iam_role" "iam_for_lambda" { | ||
name = "iam_for_lambda" | ||
name = "iam_for_lambda_${random_uuid.unique_id.result}" | ||
|
||
assume_role_policy = <<EOF | ||
{ | ||
|
@@ -22,13 +28,14 @@ EOF | |
} | ||
|
||
resource "aws_s3_bucket" "lambda_code_bucket" { | ||
bucket = "lambda_code_bucket" | ||
bucket = "lambda-code-bucket-${random_uuid.unique_id.result}" | ||
} | ||
|
||
resource "aws_s3_object" "s3_lambda_code" { | ||
bucket = "lambda_code_bucket" | ||
bucket = "lambda-code-bucket-${random_uuid.unique_id.result}" | ||
key = "s3_lambda_code_key" | ||
source = "HelloWorldFunction.zip" | ||
depends_on = [aws_s3_bucket.lambda_code_bucket] | ||
} | ||
|
||
resource "aws_lambda_layer_version" "MyAwesomeLayer" { | ||
|
@@ -38,25 +45,26 @@ resource "aws_lambda_layer_version" "MyAwesomeLayer" { | |
} | ||
|
||
resource "aws_lambda_function" "HelloWorldFunction" { | ||
s3_bucket = "lambda_code_bucket" | ||
s3_bucket = "lambda-code-bucket-${random_uuid.unique_id.result}" | ||
s3_key = "s3_lambda_code_key" | ||
handler = "app.lambda_handler" | ||
runtime = "python3.8" | ||
function_name = "HelloWorldFunction" | ||
function_name = "HelloWorldFunction-${random_uuid.unique_id.result}" | ||
timeout = 500 | ||
role = aws_iam_role.iam_for_lambda.arn | ||
layers = [aws_lambda_layer_version.MyAwesomeLayer.arn] | ||
depends_on = [aws_s3_object.s3_lambda_code] | ||
} | ||
|
||
resource "aws_lambda_function" "HelloWorldFunction2" { | ||
s3_bucket = "lambda_code_bucket" | ||
s3_bucket = "lambda-code-bucket-${random_uuid.unique_id.result}" | ||
s3_key = "s3_lambda_code_key" | ||
handler = "app.lambda_handler" | ||
runtime = "python3.8" | ||
function_name = "HelloWorldFunction2" | ||
function_name = "HelloWorldFunction2-${random_uuid.unique_id.result}" | ||
timeout = 500 | ||
role = aws_iam_role.iam_for_lambda.arn | ||
layers = ["arn:aws:lambda:us-east-1:178733185316:layer:01383708b0:1"] | ||
depends_on = [aws_s3_object.s3_lambda_code] | ||
} | ||
|
||
resource "aws_api_gateway_rest_api" "MyDemoAPI" { | ||
|
@@ -85,23 +93,35 @@ resource "aws_api_gateway_method" "PostMethod" { | |
} | ||
|
||
resource "aws_api_gateway_stage" "MyDemoStage" { | ||
stage_name = "prod" | ||
stage_name = "prod-${random_uuid.unique_id.result}" | ||
rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id | ||
deployment_id = aws_api_gateway_deployment.MyDemoDeployment.id | ||
} | ||
|
||
resource "aws_api_gateway_deployment" "MyDemoDeployment" { | ||
rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id | ||
stage_name = "prod" | ||
triggers = { | ||
redeployment = sha1(jsonencode([ | ||
aws_api_gateway_resource.MyDemoResource.id, | ||
aws_api_gateway_method.GetMethod.http_method, | ||
aws_api_gateway_integration.MyDemoIntegration.id, | ||
])) | ||
} | ||
|
||
lifecycle { | ||
create_before_destroy = true | ||
} | ||
Comment on lines
+103
to
+113
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious what this configuration is for. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this part might be not needed, i was trying to fix some failures for |
||
} | ||
|
||
resource "aws_api_gateway_integration" "MyDemoIntegration" { | ||
rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id | ||
resource_id = aws_api_gateway_resource.MyDemoResource.id | ||
http_method = aws_api_gateway_method.GetMethod.http_method | ||
integration_http_method = "POST" | ||
type = "AWS_PROXY" | ||
content_handling = "CONVERT_TO_TEXT" | ||
uri = aws_lambda_function.HelloWorldFunction.invoke_arn | ||
depends_on = [aws_api_gateway_method.GetMethod] | ||
} | ||
|
||
resource "aws_api_gateway_integration" "MyDemoIntegrationMock" { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The onus is then on us to know in which cases there could be multiple destinations, correct? I'm assuming there's similar case with V2 APIs for nested resources that we missed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I am going to review all links we have to make sure we did not miss anything else