Skip to content

Commit

Permalink
[WIP] AWS APIGateway Custom Authorizer
Browse files Browse the repository at this point in the history
  • Loading branch information
johnjelinek committed May 17, 2016
1 parent 6263962 commit a1c8bc6
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
6 changes: 6 additions & 0 deletions builtin/providers/aws/resource_aws_api_gateway_method.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ func resourceAwsApiGatewayMethod() *schema.Resource {
Required: true,
},

"authorizer_id": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},

"api_key_required": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -89,6 +94,7 @@ func resourceAwsApiGatewayMethodCreate(d *schema.ResourceData, meta interface{})
// TODO reimplement once [GH-2143](https://github.com/hashicorp/terraform/issues/2143) has been implemented
RequestParameters: aws.BoolMap(parameters),
ApiKeyRequired: aws.Bool(d.Get("api_key_required").(bool)),
AuthorizerId: aws.String(d.Get("authorizer_id").(string)),
})
if err != nil {
return fmt.Errorf("Error creating API Gateway Method: %s", err)
Expand Down
64 changes: 64 additions & 0 deletions builtin/providers/aws/resource_aws_api_gateway_method_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,39 @@ func TestAccAWSAPIGatewayMethod_basic(t *testing.T) {
})
}

func TestAccAWSAPIGatewayMethod_customauthorizer(t *testing.T) {
var conf apigateway.Method

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSAPIGatewayMethodDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSAPIGatewayMethodConfigWithCustomAuthorizer,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAPIGatewayMethodExists("aws_api_gateway_method.test", &conf),
testAccCheckAWSAPIGatewayMethodAttributes(&conf),
resource.TestCheckResourceAttr(
"aws_api_gateway_method.test", "http_method", "GET"),
resource.TestCheckResourceAttr(
"aws_api_gateway_method.test", "authorization", "CUSTOM"),
resource.TestCheckResourceAttr(
"aws_api_gateway_method.test", "request_models.application/json", "Error"),
),
},

resource.TestStep{
Config: testAccAWSAPIGatewayMethodConfigUpdate,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAPIGatewayMethodExists("aws_api_gateway_method.test", &conf),
testAccCheckAWSAPIGatewayMethodAttributesUpdate(&conf),
),
},
},
})
}

func testAccCheckAWSAPIGatewayMethodAttributes(conf *apigateway.Method) resource.TestCheckFunc {
return func(s *terraform.State) error {
if *conf.HttpMethod != "GET" {
Expand Down Expand Up @@ -154,6 +187,37 @@ func testAccCheckAWSAPIGatewayMethodDestroy(s *terraform.State) error {
return nil
}

const testAccAWSAPIGatewayMethodConfigWithCustomAuthorizer = `
resource "aws_api_gateway_rest_api" "test" {
name = "test"
}
resource "aws_api_gateway_resource" "test" {
rest_api_id = "${aws_api_gateway_rest_api.test.id}"
parent_id = "${aws_api_gateway_rest_api.test.root_resource_id}"
path_part = "test"
}
resource "aws_api_gateway_method" "test" {
rest_api_id = "${aws_api_gateway_rest_api.test.id}"
resource_id = "${aws_api_gateway_resource.test.id}"
http_method = "GET"
authorization = "CUSTOM"
authorizer_id = "efjvkr"
request_models = {
"application/json" = "Error"
}
request_parameters_in_json = <<PARAMS
{
"method.request.header.Content-Type": false,
"method.request.querystring.page": true
}
PARAMS
}
`

const testAccAWSAPIGatewayMethodConfig = `
resource "aws_api_gateway_rest_api" "test" {
name = "test"
Expand Down

0 comments on commit a1c8bc6

Please sign in to comment.