in providers/aws/api_gateway.go [199:294]
func (g *APIGatewayGenerator) loadResourceMethods(svc *apigateway.Client, restAPIID *string, resource types.Resource) error {
for httpMethod, method := range resource.ResourceMethods {
methodID := *restAPIID + "/" + *resource.Id + "/" + httpMethod
authorizationType := "NONE"
if method.AuthorizationType != nil {
authorizationType = *method.AuthorizationType
}
g.Resources = append(g.Resources, terraformutils.NewResource(
methodID,
methodID,
"aws_api_gateway_method",
"aws",
map[string]string{
"rest_api_id": *restAPIID,
"resource_id": *resource.Id,
"http_method": httpMethod,
"authorization": authorizationType,
},
apiGatewayAllowEmptyValues,
map[string]interface{}{},
))
methodDetails, err := svc.GetMethod(context.TODO(), &apigateway.GetMethodInput{
HttpMethod: &httpMethod,
ResourceId: resource.Id,
RestApiId: restAPIID,
})
if err != nil {
return err
}
if methodDetails.MethodIntegration != nil {
typeString := string(methodDetails.MethodIntegration.Type)
g.Resources = append(g.Resources, terraformutils.NewResource(
methodID,
methodID,
"aws_api_gateway_integration",
"aws",
map[string]string{
"rest_api_id": *restAPIID,
"resource_id": *resource.Id,
"http_method": httpMethod,
"type": typeString,
},
apiGatewayAllowEmptyValues,
map[string]interface{}{},
))
integrationDetails, err := svc.GetIntegration(context.TODO(), &apigateway.GetIntegrationInput{
HttpMethod: &httpMethod,
ResourceId: resource.Id,
RestApiId: restAPIID,
})
if err != nil {
return err
}
for responseCode := range integrationDetails.IntegrationResponses {
integrationResponseID := *restAPIID + "/" + *resource.Id + "/" + httpMethod + "/" + responseCode
g.Resources = append(g.Resources, terraformutils.NewResource(
integrationResponseID,
integrationResponseID,
"aws_api_gateway_integration_response",
"aws",
map[string]string{
"rest_api_id": *restAPIID,
"resource_id": *resource.Id,
"http_method": httpMethod,
"status_code": responseCode,
},
apiGatewayAllowEmptyValues,
map[string]interface{}{},
))
}
}
for responseCode := range methodDetails.MethodResponses {
responseID := *restAPIID + "/" + *resource.Id + "/" + httpMethod + "/" + responseCode
g.Resources = append(g.Resources, terraformutils.NewResource(
responseID,
responseID,
"aws_api_gateway_method_response",
"aws",
map[string]string{
"rest_api_id": *restAPIID,
"resource_id": *resource.Id,
"http_method": httpMethod,
"status_code": responseCode,
},
apiGatewayAllowEmptyValues,
map[string]interface{}{},
))
}
}
return nil
}