2

I'm currently creating an AWS API Gateway with terraform by using an open api spec from a json file.

resource "aws_api_gateway_rest_api" "my_test_gateway" {
  name        = "test_gateway"
  description = "test gateway"
  body        = "${file("assets/test_openapi_spc.json")}"
}

I need to map the api resources that are created by said openAPI spec to AWS Step Functions. How can i reference a API Gateway resource created by the openAPI spec to be able to create a new aws_api_gateway_integration? Normally you would do something like this and describe the resources in terraform

resource "aws_api_gateway_integration" "test" {
  resource_id = "${aws_api_gateway_resource.my_resource.id}"
}

In my case, however, i don't have a resource id defined in my terraform scripts because they get created by the openAPI spec.

Is there some way of extracting all the resources of an api gateway that were created as terraform data source so that i can reference them? Not sure if i'm missing something major here.

1 Answer 1

2

seems the best way to do this is with swagger extensions https://swagger.io/docs/specification/openapi-extensions/

The integration part of the API resource can reside in your swagger spec.

Just like mentioned in the aws API Gateway extensions to swagger https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions.html

So if you want to map a resource to a step function for example, you can do:

      x-amazon-apigateway-integration:
    credentials: "arn:aws:iam::my_account:role/ApiGWToStepFunction"
    responses:
      default:
        statusCode: "201"
    uri: "arn:aws:apigateway:my_zone:states:action/StartExecution"
    passthroughBehavior: "when_no_templates"
    httpMethod: "POST"
    type: "aws"

I'm not finished yet, but i believe that instead of arn:aws:apigateway:my_zone:states:action/StartExecution it should be arn:aws:apigateway:my_zone:states:your_step_function_name

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.