Add aws_api_gateway_method resource

main
William Beuil 2021-10-18 16:17:46 +02:00
parent 7dbbb0420e
commit d518d921e5
No known key found for this signature in database
GPG Key ID: BED2072C5C2BF537
17 changed files with 172361 additions and 10 deletions

View File

@ -162,6 +162,7 @@ func TestTerraformStateReader_AWS_Resources(t *testing.T) {
{name: "Api Gateway request validator", dirName: "api_gateway_request_validator", wantErr: false},
{name: "Api Gateway rest api policy", dirName: "api_gateway_rest_api_policy", wantErr: false},
{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: "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,16 @@
[
{
"Id": "agm-vryjzimtj1-hl7ksq-GET",
"Type": "aws_api_gateway_method",
"Attrs": {
"api_key_required": false,
"authorization": "NONE",
"authorizer_id": "",
"http_method": "GET",
"id": "agm-vryjzimtj1-hl7ksq-GET",
"request_validator_id": "",
"resource_id": "hl7ksq",
"rest_api_id": "vryjzimtj1"
}
}
]

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,40 @@
{
"version": 4,
"terraform_version": "1.0.9",
"serial": 269,
"lineage": "85f5bee6-139e-8db2-ae5d-82aa82f62611",
"outputs": {},
"resources": [
{
"mode": "managed",
"type": "aws_api_gateway_method",
"name": "foo",
"provider": "provider[\"registry.terraform.io/hashicorp/aws\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"api_key_required": false,
"authorization": "NONE",
"authorization_scopes": [],
"authorizer_id": "",
"http_method": "GET",
"id": "agm-vryjzimtj1-hl7ksq-GET",
"operation_name": "",
"request_models": {},
"request_parameters": {},
"request_validator_id": "",
"resource_id": "hl7ksq",
"rest_api_id": "vryjzimtj1"
},
"sensitive_attributes": [],
"private": "bnVsbA==",
"dependencies": [
"aws_api_gateway_resource.foo",
"aws_api_gateway_rest_api.foo"
]
}
]
}
]
}

View File

@ -2,6 +2,7 @@ package middlewares
import (
"encoding/json"
"strings"
"github.com/cloudskiff/driftctl/pkg/resource"
"github.com/cloudskiff/driftctl/pkg/resource/aws"
@ -68,28 +69,40 @@ func (m *AwsApiGatewayRestApiExpander) handleBody(api *resource.Resource, result
}
func (m *AwsApiGatewayRestApiExpander) handleBodyV3(apiId string, doc *openapi3.T, results, remoteResources *[]*resource.Resource) error {
for path := range doc.Paths {
m.createApiGatewayResource(apiId, path, results, remoteResources)
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)
}
}
}
return nil
}
func (m *AwsApiGatewayRestApiExpander) handleBodyV2(apiId string, doc *openapi2.T, results, remoteResources *[]*resource.Resource) error {
for path := range doc.Paths {
m.createApiGatewayResource(apiId, path, results, remoteResources)
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)
}
}
}
return nil
}
// Create aws_api_gateway_resource resource
func (m *AwsApiGatewayRestApiExpander) createApiGatewayResource(apiId, path string, results, remoteResources *[]*resource.Resource) {
func (m *AwsApiGatewayRestApiExpander) createApiGatewayResource(apiId, path string, results, remoteResources *[]*resource.Resource) *resource.Resource {
if res := foundMatchingResource(apiId, path, remoteResources); res != nil {
newResource := m.resourceFactory.CreateAbstractResource(aws.AwsApiGatewayResourceResourceType, res.ResourceId(), map[string]interface{}{
"rest_api_id": *res.Attributes().GetString("rest_api_id"),
"path": path,
})
*results = append(*results, newResource)
return newResource
}
return nil
}
// Returns the aws_api_gateway_resource resource that matches the path attribute
@ -105,3 +118,13 @@ func foundMatchingResource(apiId, path string, remoteResources *[]*resource.Reso
}
return nil
}
// Create aws_api_gateway_method resource
func (m *AwsApiGatewayRestApiExpander) createApiGatewayMethod(apiId, resourceId, method string, results *[]*resource.Resource) {
newResource := m.resourceFactory.CreateAbstractResource(
aws.AwsApiGatewayMethodResourceType,
strings.Join([]string{"agm", apiId, resourceId, method}, "-"),
map[string]interface{}{},
)
*results = append(*results, newResource)
}

View File

@ -55,6 +55,26 @@ func TestAwsApiGatewayRestApiExpander_Execute(t *testing.T) {
"path": "/path1/path2",
},
})
factory.On(
"CreateAbstractResource",
aws.AwsApiGatewayMethodResourceType,
"agm-foo-bar-GET",
map[string]interface{}{},
).Once().Return(&resource.Resource{
Id: "agm-foo-bar-GET",
Type: aws.AwsApiGatewayMethodResourceType,
Attrs: &resource.Attributes{},
})
factory.On(
"CreateAbstractResource",
aws.AwsApiGatewayMethodResourceType,
"agm-foo-baz-GET",
map[string]interface{}{},
).Once().Return(&resource.Resource{
Id: "agm-foo-baz-GET",
Type: aws.AwsApiGatewayMethodResourceType,
Attrs: &resource.Attributes{},
})
},
resourcesFromState: []*resource.Resource{
{
@ -82,6 +102,16 @@ func TestAwsApiGatewayRestApiExpander_Execute(t *testing.T) {
"path": "/path1/path2",
},
},
{
Id: "agm-foo-bar-GET",
Type: aws.AwsApiGatewayMethodResourceType,
Attrs: &resource.Attributes{},
},
{
Id: "agm-foo-baz-GET",
Type: aws.AwsApiGatewayMethodResourceType,
Attrs: &resource.Attributes{},
},
},
expected: []*resource.Resource{
{
@ -107,6 +137,16 @@ func TestAwsApiGatewayRestApiExpander_Execute(t *testing.T) {
"path": "/path1/path2",
},
},
{
Id: "agm-foo-bar-GET",
Type: aws.AwsApiGatewayMethodResourceType,
Attrs: &resource.Attributes{},
},
{
Id: "agm-foo-baz-GET",
Type: aws.AwsApiGatewayMethodResourceType,
Attrs: &resource.Attributes{},
},
},
},
{
@ -128,6 +168,16 @@ func TestAwsApiGatewayRestApiExpander_Execute(t *testing.T) {
"path": "/test",
},
})
factory.On(
"CreateAbstractResource",
aws.AwsApiGatewayMethodResourceType,
"agm-foo-bar-GET",
map[string]interface{}{},
).Once().Return(&resource.Resource{
Id: "agm-foo-bar-GET",
Type: aws.AwsApiGatewayMethodResourceType,
Attrs: &resource.Attributes{},
})
},
resourcesFromState: []*resource.Resource{
{
@ -147,6 +197,11 @@ func TestAwsApiGatewayRestApiExpander_Execute(t *testing.T) {
"path": "/test",
},
},
{
Id: "agm-foo-bar-GET",
Type: aws.AwsApiGatewayMethodResourceType,
Attrs: &resource.Attributes{},
},
},
expected: []*resource.Resource{
{
@ -164,6 +219,11 @@ func TestAwsApiGatewayRestApiExpander_Execute(t *testing.T) {
"path": "/test",
},
},
{
Id: "agm-foo-bar-GET",
Type: aws.AwsApiGatewayMethodResourceType,
Attrs: &resource.Attributes{},
},
},
},
{
@ -211,6 +271,50 @@ func TestAwsApiGatewayRestApiExpander_Execute(t *testing.T) {
},
},
},
{
name: "unknown resource in body (e.g. missing resources)",
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\"}}}}}",
},
},
},
remoteResources: []*resource.Resource{
{
Id: "bar",
Type: aws.AwsApiGatewayRestApiResourceType,
Attrs: &resource.Attributes{},
},
{
Id: "bar-path1",
Type: aws.AwsApiGatewayResourceResourceType,
Attrs: &resource.Attributes{
"rest_api_id": "bar",
"path": "/path1",
},
},
{
Id: "bar-path1-path2",
Type: aws.AwsApiGatewayResourceResourceType,
Attrs: &resource.Attributes{
"rest_api_id": "bar",
"path": "/path1/path2",
},
},
},
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\"}}}}}",
},
},
},
},
{
name: "create resources with same path but not the same rest api id",
mocks: func(factory *terraform.MockResourceFactory) {
@ -278,6 +382,46 @@ func TestAwsApiGatewayRestApiExpander_Execute(t *testing.T) {
"path": "/path1/path2",
},
})
factory.On(
"CreateAbstractResource",
aws.AwsApiGatewayMethodResourceType,
"agm-foo-foo-path1-GET",
map[string]interface{}{},
).Once().Return(&resource.Resource{
Id: "agm-foo-foo-path1-GET",
Type: aws.AwsApiGatewayMethodResourceType,
Attrs: &resource.Attributes{},
})
factory.On(
"CreateAbstractResource",
aws.AwsApiGatewayMethodResourceType,
"agm-foo-foo-path1-path2-GET",
map[string]interface{}{},
).Once().Return(&resource.Resource{
Id: "agm-foo-foo-path1-path2-GET",
Type: aws.AwsApiGatewayMethodResourceType,
Attrs: &resource.Attributes{},
})
factory.On(
"CreateAbstractResource",
aws.AwsApiGatewayMethodResourceType,
"agm-bar-bar-path1-GET",
map[string]interface{}{},
).Once().Return(&resource.Resource{
Id: "agm-bar-bar-path1-GET",
Type: aws.AwsApiGatewayMethodResourceType,
Attrs: &resource.Attributes{},
})
factory.On(
"CreateAbstractResource",
aws.AwsApiGatewayMethodResourceType,
"agm-bar-bar-path1-path2-GET",
map[string]interface{}{},
).Once().Return(&resource.Resource{
Id: "agm-bar-bar-path1-path2-GET",
Type: aws.AwsApiGatewayMethodResourceType,
Attrs: &resource.Attributes{},
})
},
resourcesFromState: []*resource.Resource{
{
@ -328,6 +472,26 @@ func TestAwsApiGatewayRestApiExpander_Execute(t *testing.T) {
"path": "/path1/path2",
},
},
{
Id: "agm-foo-foo-path1-GET",
Type: aws.AwsApiGatewayMethodResourceType,
Attrs: &resource.Attributes{},
},
{
Id: "agm-foo-foo-path1-path2-GET",
Type: aws.AwsApiGatewayMethodResourceType,
Attrs: &resource.Attributes{},
},
{
Id: "agm-bar-bar-path1-GET",
Type: aws.AwsApiGatewayMethodResourceType,
Attrs: &resource.Attributes{},
},
{
Id: "agm-bar-bar-path1-path2-GET",
Type: aws.AwsApiGatewayMethodResourceType,
Attrs: &resource.Attributes{},
},
},
expected: []*resource.Resource{
{
@ -376,6 +540,26 @@ func TestAwsApiGatewayRestApiExpander_Execute(t *testing.T) {
"path": "/path1/path2",
},
},
{
Id: "agm-foo-foo-path1-GET",
Type: aws.AwsApiGatewayMethodResourceType,
Attrs: &resource.Attributes{},
},
{
Id: "agm-foo-foo-path1-path2-GET",
Type: aws.AwsApiGatewayMethodResourceType,
Attrs: &resource.Attributes{},
},
{
Id: "agm-bar-bar-path1-GET",
Type: aws.AwsApiGatewayMethodResourceType,
Attrs: &resource.Attributes{},
},
{
Id: "agm-bar-bar-path1-path2-GET",
Type: aws.AwsApiGatewayMethodResourceType,
Attrs: &resource.Attributes{},
},
},
},
}

View File

@ -1,6 +1,7 @@
package remote
import (
"sort"
"testing"
awssdk "github.com/aws/aws-sdk-go/aws"
@ -996,3 +997,114 @@ func TestApiGatewayBasePathMapping(t *testing.T) {
})
}
}
func TestApiGatewayMethod(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 methods",
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")},
}, nil)
},
assertExpected: func(t *testing.T, got []*resource.Resource) {
assert.Len(t, got, 0)
},
},
{
test: "multiple api gateway methods",
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": {},
"POST": {},
"DELETE": {},
}},
}, 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.Method.
sort.Slice(got, func(i, j int) bool {
return got[i].ResourceId() < got[j].ResourceId()
})
assert.Equal(t, got[0].ResourceId(), "agm-vryjzimtj1-hl7ksq-DELETE")
assert.Equal(t, got[0].ResourceType(), resourceaws.AwsApiGatewayMethodResourceType)
assert.Equal(t, got[1].ResourceId(), "agm-vryjzimtj1-hl7ksq-GET")
assert.Equal(t, got[1].ResourceType(), resourceaws.AwsApiGatewayMethodResourceType)
assert.Equal(t, got[2].ResourceId(), "agm-vryjzimtj1-hl7ksq-POST")
assert.Equal(t, got[2].ResourceType(), resourceaws.AwsApiGatewayMethodResourceType)
},
},
{
test: "cannot list rest apis",
mocks: func(repo *repository.MockApiGatewayRepository, alerter *mocks.AlerterInterface) {
repo.On("ListAllRestApis").Return(nil, dummyError)
alerter.On("SendAlert", resourceaws.AwsApiGatewayMethodResourceType, alerts.NewRemoteAccessDeniedAlert(common.RemoteAWSTerraform, remoteerr.NewResourceListingErrorWithType(dummyError, resourceaws.AwsApiGatewayMethodResourceType, resourceaws.AwsApiGatewayRestApiResourceType), alerts.EnumerationPhase)).Return()
},
wantErr: remoteerr.NewResourceListingErrorWithType(dummyError, resourceaws.AwsApiGatewayMethodResourceType, 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.AwsApiGatewayMethodResourceType, alerts.NewRemoteAccessDeniedAlert(common.RemoteAWSTerraform, remoteerr.NewResourceListingErrorWithType(dummyError, resourceaws.AwsApiGatewayMethodResourceType, resourceaws.AwsApiGatewayResourceResourceType), alerts.EnumerationPhase)).Return()
},
wantErr: remoteerr.NewResourceListingErrorWithType(dummyError, resourceaws.AwsApiGatewayMethodResourceType, 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.NewApiGatewayMethodEnumerator(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,59 @@
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 ApiGatewayMethodEnumerator struct {
repository repository.ApiGatewayRepository
factory resource.ResourceFactory
}
func NewApiGatewayMethodEnumerator(repo repository.ApiGatewayRepository, factory resource.ResourceFactory) *ApiGatewayMethodEnumerator {
return &ApiGatewayMethodEnumerator{
repository: repo,
factory: factory,
}
}
func (e *ApiGatewayMethodEnumerator) SupportedType() resource.ResourceType {
return aws.AwsApiGatewayMethodResourceType
}
func (e *ApiGatewayMethodEnumerator) 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 method := range r.ResourceMethods {
results = append(
results,
e.factory.CreateAbstractResource(
string(e.SupportedType()),
strings.Join([]string{"agm", *a.Id, *r.Id, method}, "-"),
map[string]interface{}{},
),
)
}
}
}
return results, err
}

View File

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

View File

@ -131,7 +131,9 @@ func (r *apigatewayRepository) ListAllRestApiStages(apiId string) ([]*apigateway
func (r *apigatewayRepository) ListAllRestApiResources(apiId string) ([]*apigateway.Resource, error) {
cacheKey := fmt.Sprintf("apigatewayListAllRestApiResources_api_%s", apiId)
if v := r.cache.Get(cacheKey); v != nil {
v := r.cache.GetAndLock(cacheKey)
defer r.cache.Unlock(cacheKey)
if v != nil {
return v.([]*apigateway.Resource), nil
}

View File

@ -375,7 +375,8 @@ func Test_apigatewayRepository_ListAllRestApiResources(t *testing.T) {
return true
})).Return(nil).Once()
store.On("Get", "apigatewayListAllRestApiResources_api_restapi1").Return(nil).Times(1)
store.On("GetAndLock", "apigatewayListAllRestApiResources_api_restapi1").Return(nil).Times(1)
store.On("Unlock", "apigatewayListAllRestApiResources_api_restapi1").Times(1)
store.On("Put", "apigatewayListAllRestApiResources_api_restapi1", apiResources).Return(false).Times(1)
},
want: apiResources,
@ -383,7 +384,8 @@ func Test_apigatewayRepository_ListAllRestApiResources(t *testing.T) {
{
name: "should hit cache",
mocks: func(client *awstest.MockFakeApiGateway, store *cache.MockCache) {
store.On("Get", "apigatewayListAllRestApiResources_api_restapi1").Return(apiResources).Times(1)
store.On("GetAndLock", "apigatewayListAllRestApiResources_api_restapi1").Return(apiResources).Times(1)
store.On("Unlock", "apigatewayListAllRestApiResources_api_restapi1").Times(1)
},
want: apiResources,
},

View File

@ -0,0 +1,3 @@
package aws
const AwsApiGatewayMethodResourceType = "aws_api_gateway_method"

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_ApiGatewayMethod(t *testing.T) {
acceptance.Run(t, acceptance.AccTestCase{
TerraformVersion: "0.15.5",
Paths: []string{"./testdata/acc/aws_api_gateway_method"},
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(4)
},
},
},
})
}

View File

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

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,95 @@
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 = {
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"
}
}
}
}
})
}
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"
}

View File

@ -104,6 +104,7 @@ 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": {},
@ -111,13 +112,16 @@ var supportedTypes = map[string]ResourceTypeMeta{
"aws_api_gateway_deployment": {children: []ResourceType{
"aws_api_gateway_stage",
}},
"aws_api_gateway_stage": {},
"aws_api_gateway_resource": {},
"aws_api_gateway_stage": {},
"aws_api_gateway_resource": {children: []ResourceType{
"aws_api_gateway_method",
}},
"aws_api_gateway_domain_name": {},
"aws_api_gateway_vpc_link": {},
"aws_api_gateway_request_validator": {},
"aws_api_gateway_rest_api_policy": {},
"aws_api_gateway_base_path_mapping": {},
"aws_api_gateway_method": {},
"aws_appautoscaling_target": {},
"aws_rds_cluster_instance": {children: []ResourceType{
"aws_db_instance",