Add aws_api_gateway_method_response resource

main
William Beuil 2021-10-22 18:17:41 +02:00
parent 20f82df070
commit 6f75e08bdb
No known key found for this signature in database
GPG Key ID: BED2072C5C2BF537
18 changed files with 172239 additions and 11 deletions

View File

@ -164,6 +164,7 @@ func TestTerraformStateReader_AWS_Resources(t *testing.T) {
{name: "Api Gateway base path mapping", dirName: "api_gateway_base_path_mapping", wantErr: false},
{name: "Api Gateway method", dirName: "api_gateway_method", wantErr: false},
{name: "Api Gateway model", dirName: "api_gateway_model", wantErr: false},
{name: "Api Gateway method response", dirName: "api_gateway_method_response", wantErr: false},
{name: "AppAutoScaling Targets", dirName: "aws_appautoscaling_target", wantErr: false},
{name: "network acl", dirName: "aws_network_acl", wantErr: false},
{name: "network acl rule", dirName: "aws_network_acl_rule", wantErr: false},

View File

@ -0,0 +1,13 @@
[
{
"Id": "agmr-vryjzimtj1-oy4dqf-GET-200",
"Type": "aws_api_gateway_method_response",
"Attrs": {
"http_method": "GET",
"id": "agmr-vryjzimtj1-oy4dqf-GET-200",
"resource_id": "oy4dqf",
"rest_api_id": "vryjzimtj1",
"status_code": "200"
}
}
]

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,36 @@
{
"version": 4,
"terraform_version": "1.0.9",
"serial": 294,
"lineage": "85f5bee6-139e-8db2-ae5d-82aa82f62611",
"outputs": {},
"resources": [
{
"mode": "managed",
"type": "aws_api_gateway_method_response",
"name": "response_200",
"provider": "provider[\"registry.terraform.io/hashicorp/aws\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"http_method": "GET",
"id": "agmr-vryjzimtj1-oy4dqf-GET-200",
"resource_id": "oy4dqf",
"response_models": null,
"response_parameters": null,
"rest_api_id": "vryjzimtj1",
"status_code": "200"
},
"sensitive_attributes": [],
"private": "bnVsbA==",
"dependencies": [
"aws_api_gateway_method.foo",
"aws_api_gateway_resource.foo",
"aws_api_gateway_rest_api.foo"
]
}
]
}
]
}

View File

@ -72,8 +72,11 @@ func (m *AwsApiGatewayRestApiExpander) handleBodyV3(apiId string, doc *openapi3.
for path, pathItem := range doc.Paths {
if res := m.createApiGatewayResource(apiId, path, results, remoteResources); res != nil {
ops := pathItem.Operations()
for method := range ops {
m.createApiGatewayMethod(apiId, res.ResourceId(), method, results)
for httpMethod, method := range ops {
m.createApiGatewayMethod(apiId, res.ResourceId(), httpMethod, results)
for statusCode := range method.Responses {
m.createApiGatewayMethodResponse(apiId, res.ResourceId(), httpMethod, statusCode, results)
}
}
}
}
@ -84,8 +87,11 @@ func (m *AwsApiGatewayRestApiExpander) handleBodyV2(apiId string, doc *openapi2.
for path, pathItem := range doc.Paths {
if res := m.createApiGatewayResource(apiId, path, results, remoteResources); res != nil {
ops := pathItem.Operations()
for method := range ops {
m.createApiGatewayMethod(apiId, res.ResourceId(), method, results)
for httpMethod, method := range ops {
m.createApiGatewayMethod(apiId, res.ResourceId(), httpMethod, results)
for statusCode := range method.Responses {
m.createApiGatewayMethodResponse(apiId, res.ResourceId(), httpMethod, statusCode, results)
}
}
}
}
@ -120,10 +126,20 @@ func foundMatchingResource(apiId, path string, remoteResources *[]*resource.Reso
}
// Create aws_api_gateway_method resource
func (m *AwsApiGatewayRestApiExpander) createApiGatewayMethod(apiId, resourceId, method string, results *[]*resource.Resource) {
func (m *AwsApiGatewayRestApiExpander) createApiGatewayMethod(apiId, resourceId, httpMethod string, results *[]*resource.Resource) {
newResource := m.resourceFactory.CreateAbstractResource(
aws.AwsApiGatewayMethodResourceType,
strings.Join([]string{"agm", apiId, resourceId, method}, "-"),
strings.Join([]string{"agm", apiId, resourceId, httpMethod}, "-"),
map[string]interface{}{},
)
*results = append(*results, newResource)
}
// Create aws_api_gateway_method_response resource
func (m *AwsApiGatewayRestApiExpander) createApiGatewayMethodResponse(apiId, resourceId, httpMethod, statusCode string, results *[]*resource.Resource) {
newResource := m.resourceFactory.CreateAbstractResource(
aws.AwsApiGatewayMethodResponseResourceType,
strings.Join([]string{"agmr", apiId, resourceId, httpMethod, statusCode}, "-"),
map[string]interface{}{},
)
*results = append(*results, newResource)

View File

@ -75,13 +75,23 @@ func TestAwsApiGatewayRestApiExpander_Execute(t *testing.T) {
Type: aws.AwsApiGatewayMethodResourceType,
Attrs: &resource.Attributes{},
})
factory.On(
"CreateAbstractResource",
aws.AwsApiGatewayMethodResponseResourceType,
"agmr-foo-bar-GET-200",
map[string]interface{}{},
).Once().Return(&resource.Resource{
Id: "agmr-foo-bar-GET-200",
Type: aws.AwsApiGatewayMethodResponseResourceType,
Attrs: &resource.Attributes{},
})
},
resourcesFromState: []*resource.Resource{
{
Id: "foo",
Type: aws.AwsApiGatewayRestApiResourceType,
Attrs: &resource.Attributes{
"body": "{\"info\":{\"title\":\"example\",\"version\":\"1.0\"},\"openapi\":\"3.0.1\",\"paths\":{\"/path1\":{\"get\":{\"x-amazon-apigateway-integration\":{\"httpMethod\":\"GET\",\"payloadFormatVersion\":\"1.0\",\"type\":\"HTTP_PROXY\",\"uri\":\"https://ip-ranges.amazonaws.com/ip-ranges.json\"}}},\"/path1/path2\":{\"get\":{\"x-amazon-apigateway-integration\":{\"httpMethod\":\"GET\",\"payloadFormatVersion\":\"1.0\",\"type\":\"HTTP_PROXY\",\"uri\":\"https://ip-ranges.amazonaws.com/ip-ranges.json\"}}}}}",
"body": "{\"info\":{\"title\":\"example\",\"version\":\"1.0\"},\"openapi\":\"3.0.1\",\"paths\":{\"/path1\":{\"get\":{\"parameters\":[{\"in\":\"query\",\"name\":\"type\",\"schema\":{\"type\":\"string\"}},{\"in\":\"query\",\"name\":\"page\",\"schema\":{\"type\":\"string\"}}],\"responses\":{\"200\":{\"content\":{\"application/json\":{\"schema\":{\"$ref\":\"#/components/schemas/Pets\"}}},\"description\":\"200 response\",\"headers\":{\"Access-Control-Allow-Origin\":{\"schema\":{\"type\":\"string\"}}}}},\"x-amazon-apigateway-integration\":{\"httpMethod\":\"GET\",\"payloadFormatVersion\":\"1.0\",\"type\":\"HTTP_PROXY\",\"uri\":\"https://ip-ranges.amazonaws.com/ip-ranges.json\"}}},\"/path1/path2\":{\"get\":{\"x-amazon-apigateway-integration\":{\"httpMethod\":\"GET\",\"payloadFormatVersion\":\"1.0\",\"type\":\"HTTP_PROXY\",\"uri\":\"https://ip-ranges.amazonaws.com/ip-ranges.json\"}}}}}",
},
},
},
@ -112,13 +122,18 @@ func TestAwsApiGatewayRestApiExpander_Execute(t *testing.T) {
Type: aws.AwsApiGatewayMethodResourceType,
Attrs: &resource.Attributes{},
},
{
Id: "agmr-foo-bar-GET-200",
Type: aws.AwsApiGatewayMethodResponseResourceType,
Attrs: &resource.Attributes{},
},
},
expected: []*resource.Resource{
{
Id: "foo",
Type: aws.AwsApiGatewayRestApiResourceType,
Attrs: &resource.Attributes{
"body": "{\"info\":{\"title\":\"example\",\"version\":\"1.0\"},\"openapi\":\"3.0.1\",\"paths\":{\"/path1\":{\"get\":{\"x-amazon-apigateway-integration\":{\"httpMethod\":\"GET\",\"payloadFormatVersion\":\"1.0\",\"type\":\"HTTP_PROXY\",\"uri\":\"https://ip-ranges.amazonaws.com/ip-ranges.json\"}}},\"/path1/path2\":{\"get\":{\"x-amazon-apigateway-integration\":{\"httpMethod\":\"GET\",\"payloadFormatVersion\":\"1.0\",\"type\":\"HTTP_PROXY\",\"uri\":\"https://ip-ranges.amazonaws.com/ip-ranges.json\"}}}}}",
"body": "{\"info\":{\"title\":\"example\",\"version\":\"1.0\"},\"openapi\":\"3.0.1\",\"paths\":{\"/path1\":{\"get\":{\"parameters\":[{\"in\":\"query\",\"name\":\"type\",\"schema\":{\"type\":\"string\"}},{\"in\":\"query\",\"name\":\"page\",\"schema\":{\"type\":\"string\"}}],\"responses\":{\"200\":{\"content\":{\"application/json\":{\"schema\":{\"$ref\":\"#/components/schemas/Pets\"}}},\"description\":\"200 response\",\"headers\":{\"Access-Control-Allow-Origin\":{\"schema\":{\"type\":\"string\"}}}}},\"x-amazon-apigateway-integration\":{\"httpMethod\":\"GET\",\"payloadFormatVersion\":\"1.0\",\"type\":\"HTTP_PROXY\",\"uri\":\"https://ip-ranges.amazonaws.com/ip-ranges.json\"}}},\"/path1/path2\":{\"get\":{\"x-amazon-apigateway-integration\":{\"httpMethod\":\"GET\",\"payloadFormatVersion\":\"1.0\",\"type\":\"HTTP_PROXY\",\"uri\":\"https://ip-ranges.amazonaws.com/ip-ranges.json\"}}}}}",
},
},
{
@ -147,6 +162,11 @@ func TestAwsApiGatewayRestApiExpander_Execute(t *testing.T) {
Type: aws.AwsApiGatewayMethodResourceType,
Attrs: &resource.Attributes{},
},
{
Id: "agmr-foo-bar-GET-200",
Type: aws.AwsApiGatewayMethodResponseResourceType,
Attrs: &resource.Attributes{},
},
},
},
{
@ -178,6 +198,16 @@ func TestAwsApiGatewayRestApiExpander_Execute(t *testing.T) {
Type: aws.AwsApiGatewayMethodResourceType,
Attrs: &resource.Attributes{},
})
factory.On(
"CreateAbstractResource",
aws.AwsApiGatewayMethodResponseResourceType,
"agmr-foo-bar-GET-200",
map[string]interface{}{},
).Once().Return(&resource.Resource{
Id: "agmr-foo-bar-GET-200",
Type: aws.AwsApiGatewayMethodResponseResourceType,
Attrs: &resource.Attributes{},
})
},
resourcesFromState: []*resource.Resource{
{
@ -202,6 +232,11 @@ func TestAwsApiGatewayRestApiExpander_Execute(t *testing.T) {
Type: aws.AwsApiGatewayMethodResourceType,
Attrs: &resource.Attributes{},
},
{
Id: "agmr-foo-bar-GET-200",
Type: aws.AwsApiGatewayMethodResponseResourceType,
Attrs: &resource.Attributes{},
},
},
expected: []*resource.Resource{
{
@ -224,6 +259,11 @@ func TestAwsApiGatewayRestApiExpander_Execute(t *testing.T) {
Type: aws.AwsApiGatewayMethodResourceType,
Attrs: &resource.Attributes{},
},
{
Id: "agmr-foo-bar-GET-200",
Type: aws.AwsApiGatewayMethodResponseResourceType,
Attrs: &resource.Attributes{},
},
},
},
{

View File

@ -1205,3 +1205,118 @@ func TestApiGatewayModel(t *testing.T) {
})
}
}
func TestApiGatewayMethodResponse(t *testing.T) {
dummyError := errors.New("this is an error")
apis := []*apigateway.RestApi{
{Id: awssdk.String("vryjzimtj1")},
}
tests := []struct {
test string
mocks func(*repository.MockApiGatewayRepository, *mocks.AlerterInterface)
assertExpected func(t *testing.T, got []*resource.Resource)
wantErr error
}{
{
test: "no api gateway method responses",
mocks: func(repo *repository.MockApiGatewayRepository, alerter *mocks.AlerterInterface) {
repo.On("ListAllRestApis").Return(apis, nil)
repo.On("ListAllRestApiResources", *apis[0].Id).Return([]*apigateway.Resource{
{Id: awssdk.String("hl7ksq"), Path: awssdk.String("/foo"), ResourceMethods: map[string]*apigateway.Method{
"GET": {},
}},
}, nil)
},
assertExpected: func(t *testing.T, got []*resource.Resource) {
assert.Len(t, got, 0)
},
},
{
test: "multiple api gateway method responses",
mocks: func(repo *repository.MockApiGatewayRepository, alerter *mocks.AlerterInterface) {
repo.On("ListAllRestApis").Return(apis, nil)
repo.On("ListAllRestApiResources", *apis[0].Id).Return([]*apigateway.Resource{
{Id: awssdk.String("hl7ksq"), Path: awssdk.String("/foo"), ResourceMethods: map[string]*apigateway.Method{
"GET": {MethodResponses: map[string]*apigateway.MethodResponse{
"200": {},
"404": {},
"503": {},
}},
}},
}, nil)
},
assertExpected: func(t *testing.T, got []*resource.Resource) {
assert.Len(t, got, 3)
// We need to sort the slice of resources to have consistent test results because at
// the creation we iterate over a map[string]*apigateway.MethodResponse.
sort.Slice(got, func(i, j int) bool {
return got[i].ResourceId() < got[j].ResourceId()
})
assert.Equal(t, got[0].ResourceId(), "agmr-vryjzimtj1-hl7ksq-GET-200")
assert.Equal(t, got[0].ResourceType(), resourceaws.AwsApiGatewayMethodResponseResourceType)
assert.Equal(t, got[1].ResourceId(), "agmr-vryjzimtj1-hl7ksq-GET-404")
assert.Equal(t, got[1].ResourceType(), resourceaws.AwsApiGatewayMethodResponseResourceType)
assert.Equal(t, got[2].ResourceId(), "agmr-vryjzimtj1-hl7ksq-GET-503")
assert.Equal(t, got[2].ResourceType(), resourceaws.AwsApiGatewayMethodResponseResourceType)
},
},
{
test: "cannot list rest apis",
mocks: func(repo *repository.MockApiGatewayRepository, alerter *mocks.AlerterInterface) {
repo.On("ListAllRestApis").Return(nil, dummyError)
alerter.On("SendAlert", resourceaws.AwsApiGatewayMethodResponseResourceType, alerts.NewRemoteAccessDeniedAlert(common.RemoteAWSTerraform, remoteerr.NewResourceListingErrorWithType(dummyError, resourceaws.AwsApiGatewayMethodResponseResourceType, resourceaws.AwsApiGatewayRestApiResourceType), alerts.EnumerationPhase)).Return()
},
wantErr: remoteerr.NewResourceListingErrorWithType(dummyError, resourceaws.AwsApiGatewayMethodResponseResourceType, resourceaws.AwsApiGatewayRestApiResourceType),
},
{
test: "cannot list api gateway resources",
mocks: func(repo *repository.MockApiGatewayRepository, alerter *mocks.AlerterInterface) {
repo.On("ListAllRestApis").Return(apis, nil)
repo.On("ListAllRestApiResources", *apis[0].Id).Return(nil, dummyError)
alerter.On("SendAlert", resourceaws.AwsApiGatewayMethodResponseResourceType, alerts.NewRemoteAccessDeniedAlert(common.RemoteAWSTerraform, remoteerr.NewResourceListingErrorWithType(dummyError, resourceaws.AwsApiGatewayMethodResponseResourceType, resourceaws.AwsApiGatewayResourceResourceType), alerts.EnumerationPhase)).Return()
},
wantErr: remoteerr.NewResourceListingErrorWithType(dummyError, resourceaws.AwsApiGatewayMethodResponseResourceType, resourceaws.AwsApiGatewayResourceResourceType),
},
}
providerVersion := "3.19.0"
schemaRepository := testresource.InitFakeSchemaRepository("aws", providerVersion)
resourceaws.InitResourcesMetadata(schemaRepository)
factory := terraform.NewTerraformResourceFactory(schemaRepository)
for _, c := range tests {
t.Run(c.test, func(tt *testing.T) {
scanOptions := ScannerOptions{}
remoteLibrary := common.NewRemoteLibrary()
// Initialize mocks
alerter := &mocks.AlerterInterface{}
fakeRepo := &repository.MockApiGatewayRepository{}
c.mocks(fakeRepo, alerter)
var repo repository.ApiGatewayRepository = fakeRepo
remoteLibrary.AddEnumerator(aws.NewApiGatewayMethodResponseEnumerator(repo, factory))
testFilter := &filter.MockFilter{}
testFilter.On("IsTypeIgnored", mock.Anything).Return(false)
s := NewScanner(remoteLibrary, alerter, scanOptions, testFilter)
got, err := s.Resources()
assert.Equal(tt, err, c.wantErr)
if err != nil {
return
}
c.assertExpected(tt, got)
alerter.AssertExpectations(tt)
fakeRepo.AssertExpectations(tt)
testFilter.AssertExpectations(tt)
})
}
}

View File

@ -0,0 +1,61 @@
package aws
import (
"strings"
"github.com/cloudskiff/driftctl/pkg/remote/aws/repository"
remoteerror "github.com/cloudskiff/driftctl/pkg/remote/error"
"github.com/cloudskiff/driftctl/pkg/resource"
"github.com/cloudskiff/driftctl/pkg/resource/aws"
)
type ApiGatewayMethodResponseEnumerator struct {
repository repository.ApiGatewayRepository
factory resource.ResourceFactory
}
func NewApiGatewayMethodResponseEnumerator(repo repository.ApiGatewayRepository, factory resource.ResourceFactory) *ApiGatewayMethodResponseEnumerator {
return &ApiGatewayMethodResponseEnumerator{
repository: repo,
factory: factory,
}
}
func (e *ApiGatewayMethodResponseEnumerator) SupportedType() resource.ResourceType {
return aws.AwsApiGatewayMethodResponseResourceType
}
func (e *ApiGatewayMethodResponseEnumerator) Enumerate() ([]*resource.Resource, error) {
apis, err := e.repository.ListAllRestApis()
if err != nil {
return nil, remoteerror.NewResourceListingErrorWithType(err, string(e.SupportedType()), aws.AwsApiGatewayRestApiResourceType)
}
results := make([]*resource.Resource, 0)
for _, api := range apis {
a := api
resources, err := e.repository.ListAllRestApiResources(*a.Id)
if err != nil {
return nil, remoteerror.NewResourceListingErrorWithType(err, string(e.SupportedType()), aws.AwsApiGatewayResourceResourceType)
}
for _, resource := range resources {
r := resource
for httpMethod, method := range r.ResourceMethods {
for statusCode := range method.MethodResponses {
results = append(
results,
e.factory.CreateAbstractResource(
string(e.SupportedType()),
strings.Join([]string{"agmr", *a.Id, *r.Id, httpMethod, statusCode}, "-"),
map[string]interface{}{},
),
)
}
}
}
}
return results, err
}

View File

@ -195,6 +195,7 @@ func Init(version string, alerter *alerter.Alerter,
remoteLibrary.AddEnumerator(NewApiGatewayBasePathMappingEnumerator(apigatewayRepository, factory))
remoteLibrary.AddEnumerator(NewApiGatewayMethodEnumerator(apigatewayRepository, factory))
remoteLibrary.AddEnumerator(NewApiGatewayModelEnumerator(apigatewayRepository, factory))
remoteLibrary.AddEnumerator(NewApiGatewayMethodResponseEnumerator(apigatewayRepository, factory))
remoteLibrary.AddEnumerator(NewAppAutoscalingTargetEnumerator(appAutoScalingRepository, factory))
remoteLibrary.AddDetailsFetcher(aws.AwsAppAutoscalingTargetResourceType, common.NewGenericDetailsFetcher(aws.AwsAppAutoscalingTargetResourceType, provider, deserializer))

View File

@ -3,6 +3,7 @@ package repository
import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/apigateway"
"github.com/aws/aws-sdk-go/service/apigateway/apigatewayiface"
@ -141,6 +142,7 @@ func (r *apigatewayRepository) ListAllRestApiResources(apiId string) ([]*apigate
var resources []*apigateway.Resource
input := &apigateway.GetResourcesInput{
RestApiId: &apiId,
Embed: []*string{aws.String("methods")},
}
err := r.client.GetResourcesPages(input, func(res *apigateway.GetResourcesOutput, lastPage bool) bool {
resources = append(resources, res.Items...)

View File

@ -367,6 +367,7 @@ func Test_apigatewayRepository_ListAllRestApiResources(t *testing.T) {
client.On("GetResourcesPages",
&apigateway.GetResourcesInput{
RestApiId: aws.String("restapi1"),
Embed: []*string{aws.String("methods")},
},
mock.MatchedBy(func(callback func(res *apigateway.GetResourcesOutput, lastPage bool) bool) bool {
callback(&apigateway.GetResourcesOutput{

View File

@ -0,0 +1,3 @@
package aws
const AwsApiGatewayMethodResponseResourceType = "aws_api_gateway_method_response"

View File

@ -0,0 +1,30 @@
package aws_test
import (
"testing"
"github.com/cloudskiff/driftctl/test"
"github.com/cloudskiff/driftctl/test/acceptance"
)
func TestAcc_Aws_ApiGatewayMethodResponse(t *testing.T) {
acceptance.Run(t, acceptance.AccTestCase{
TerraformVersion: "0.15.5",
Paths: []string{"./testdata/acc/aws_api_gateway_method_response"},
Args: []string{"scan"},
Checks: []acceptance.AccCheck{
{
Env: map[string]string{
"AWS_REGION": "us-east-1",
},
Check: func(result *test.ScanResult, stdout string, err error) {
if err != nil {
t.Fatal(err)
}
result.AssertInfrastructureIsInSync()
result.AssertManagedCount(3)
},
},
},
})
}

View File

@ -19,6 +19,7 @@ func TestAWS_Metadata_Flags(t *testing.T) {
AwsApiGatewayDeploymentResourceType: {},
AwsApiGatewayDomainNameResourceType: {},
AwsApiGatewayMethodResourceType: {},
AwsApiGatewayMethodResponseResourceType: {},
AwsApiGatewayModelResourceType: {},
AwsApiGatewayRequestValidatorResourceType: {},
AwsApiGatewayResourceResourceType: {},

View File

@ -0,0 +1,2 @@
*
!aws_api_gateway_method_response

View File

@ -0,0 +1,20 @@
# This file is maintained automatically by "terraform init".
# Manual edits may be lost in future updates.
provider "registry.terraform.io/hashicorp/aws" {
version = "3.19.0"
constraints = "3.19.0"
hashes = [
"h1:xur9tF49NgsovNnmwmBR8RdpN8Fcg1TD4CKQPJD6n1A=",
"zh:185a5259153eb9ee4699d4be43b3d509386b473683392034319beee97d470c3b",
"zh:2d9a0a01f93e8d16539d835c02b8b6e1927b7685f4076e96cb07f7dd6944bc6c",
"zh:703f6da36b1b5f3497baa38fccaa7765fb8a2b6440344e4c97172516b49437dd",
"zh:770855565462abadbbddd98cb357d2f1a8f30f68a358cb37cbd5c072cb15b377",
"zh:8008db43149fe4345301f81e15e6d9ddb47aa5e7a31648f9b290af96ad86e92a",
"zh:8cdd27d375da6dcb7687f1fed126b7c04efce1671066802ee876dbbc9c66ec79",
"zh:be22ae185005690d1a017c1b909e0d80ab567e239b4f06ecacdba85080667c1c",
"zh:d2d02e72dbd80f607636cd6237a6c862897caabc635c7b50c0cb243d11246723",
"zh:d8f125b66a1eda2555c0f9bbdf12036a5f8d073499a22ca9e4812b68067fea31",
"zh:f5a98024c64d5d2973ff15b093725a074c0cb4afde07ef32c542e69f17ac90bc",
]
}

View File

@ -0,0 +1,127 @@
provider "aws" {
region = "us-east-1"
}
terraform {
required_providers {
aws = "3.19.0"
}
}
resource "aws_api_gateway_rest_api" "foo" {
name = "foo"
description = "This is foo API"
}
resource "aws_api_gateway_rest_api" "bar" {
name = "bar"
description = "This is bar API"
body = jsonencode({
openapi = "3.0.1"
info = {
title = "example"
version = "1.0"
}
paths = {
"/path1" = {
get = {
"parameters" : [
{
"name" : "type",
"in" : "query",
"schema" : {
"type" : "string"
}
},
{
"name" : "page",
"in" : "query",
"schema" : {
"type" : "string"
}
}
],
"responses" : {
"200" : {
"description" : "200 response",
"headers" : {
"Access-Control-Allow-Origin" : {
"schema" : {
"type" : "string"
}
}
},
"content" : {
"application/json" : {
"schema" : {
"$ref" : "#/components/schemas/Pets"
}
}
}
}
},
x-amazon-apigateway-integration = {
httpMethod = "GET"
payloadFormatVersion = "1.0"
type = "HTTP_PROXY"
uri = "https://ip-ranges.amazonaws.com/ip-ranges.json"
}
}
}
}
})
}
resource "aws_api_gateway_rest_api" "baz" {
name = "baz"
description = "This is baz API"
body = jsonencode({
swagger = "2.0"
info = {
title = "test"
version = "2017-04-20T04:08:08Z"
}
schemes = ["https"]
paths = {
"/test" = {
get = {
responses = {
"200" = {
description = "OK"
}
}
x-amazon-apigateway-integration = {
httpMethod = "GET"
type = "HTTP"
responses = {
default = {
statusCode = 200
}
}
uri = "https://aws.amazon.com/"
}
}
}
}
})
}
resource "aws_api_gateway_resource" "foo" {
rest_api_id = aws_api_gateway_rest_api.foo.id
parent_id = aws_api_gateway_rest_api.foo.root_resource_id
path_part = "foo"
}
resource "aws_api_gateway_method" "foo" {
rest_api_id = aws_api_gateway_rest_api.foo.id
resource_id = aws_api_gateway_resource.foo.id
http_method = "GET"
authorization = "NONE"
}
resource "aws_api_gateway_method_response" "response_200" {
rest_api_id = aws_api_gateway_rest_api.foo.id
resource_id = aws_api_gateway_resource.foo.id
http_method = aws_api_gateway_method.foo.http_method
status_code = "200"
}

View File

@ -104,7 +104,6 @@ var supportedTypes = map[string]ResourceTypeMeta{
"aws_api_gateway_rest_api": {children: []ResourceType{
"aws_api_gateway_resource",
"aws_api_gateway_rest_api_policy",
"aws_api_gateway_method",
}},
"aws_api_gateway_account": {},
"aws_api_gateway_api_key": {},
@ -121,8 +120,11 @@ var supportedTypes = map[string]ResourceTypeMeta{
"aws_api_gateway_request_validator": {},
"aws_api_gateway_rest_api_policy": {},
"aws_api_gateway_base_path_mapping": {},
"aws_api_gateway_method": {},
"aws_api_gateway_model": {},
"aws_api_gateway_method": {children: []ResourceType{
"aws_api_gateway_method_response",
}},
"aws_api_gateway_method_response": {},
"aws_appautoscaling_target": {},
"aws_rds_cluster_instance": {children: []ResourceType{
"aws_db_instance",