github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/aws/resource_aws_api_gateway_usage_plan_test.go (about)

     1  package aws
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/aws/aws-sdk-go/aws"
     8  	"github.com/aws/aws-sdk-go/aws/awserr"
     9  	"github.com/aws/aws-sdk-go/service/apigateway"
    10  	"github.com/hashicorp/terraform/helper/acctest"
    11  	"github.com/hashicorp/terraform/helper/resource"
    12  	"github.com/hashicorp/terraform/terraform"
    13  )
    14  
    15  func TestAccAWSAPIGatewayUsagePlan_basic(t *testing.T) {
    16  	var conf apigateway.UsagePlan
    17  	name := acctest.RandString(10)
    18  	updatedName := acctest.RandString(10)
    19  
    20  	resource.Test(t, resource.TestCase{
    21  		PreCheck:     func() { testAccPreCheck(t) },
    22  		Providers:    testAccProviders,
    23  		CheckDestroy: testAccCheckAWSAPIGatewayUsagePlanDestroy,
    24  		Steps: []resource.TestStep{
    25  			{
    26  				Config: testAccAWSApiGatewayUsagePlanBasicConfig(name),
    27  				Check: resource.ComposeTestCheckFunc(
    28  					testAccCheckAWSAPIGatewayUsagePlanExists("aws_api_gateway_usage_plan.main", &conf),
    29  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "name", name),
    30  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "description", ""),
    31  				),
    32  			},
    33  			{
    34  				Config: testAccAWSApiGatewayUsagePlanBasicUpdatedConfig(updatedName),
    35  				Check: resource.ComposeTestCheckFunc(
    36  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "name", updatedName),
    37  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "description", ""),
    38  				),
    39  			},
    40  			{
    41  				Config: testAccAWSApiGatewayUsagePlanBasicConfig(name),
    42  				Check: resource.ComposeTestCheckFunc(
    43  					testAccCheckAWSAPIGatewayUsagePlanExists("aws_api_gateway_usage_plan.main", &conf),
    44  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "name", name),
    45  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "description", ""),
    46  				),
    47  			},
    48  		},
    49  	})
    50  }
    51  
    52  func TestAccAWSAPIGatewayUsagePlan_description(t *testing.T) {
    53  	var conf apigateway.UsagePlan
    54  	name := acctest.RandString(10)
    55  
    56  	resource.Test(t, resource.TestCase{
    57  		PreCheck:     func() { testAccPreCheck(t) },
    58  		Providers:    testAccProviders,
    59  		CheckDestroy: testAccCheckAWSAPIGatewayUsagePlanDestroy,
    60  		Steps: []resource.TestStep{
    61  			{
    62  				Config: testAccAWSApiGatewayUsagePlanBasicConfig(name),
    63  				Check: resource.ComposeTestCheckFunc(
    64  					testAccCheckAWSAPIGatewayUsagePlanExists("aws_api_gateway_usage_plan.main", &conf),
    65  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "description", ""),
    66  				),
    67  			},
    68  			{
    69  				Config: testAccAWSApiGatewayUsagePlanDescriptionConfig(name),
    70  				Check: resource.ComposeTestCheckFunc(
    71  					testAccCheckAWSAPIGatewayUsagePlanExists("aws_api_gateway_usage_plan.main", &conf),
    72  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "description", "This is a description"),
    73  				),
    74  			},
    75  			{
    76  				Config: testAccAWSApiGatewayUsagePlanDescriptionUpdatedConfig(name),
    77  				Check: resource.ComposeTestCheckFunc(
    78  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "description", "This is a new description"),
    79  				),
    80  			},
    81  			{
    82  				Config: testAccAWSApiGatewayUsagePlanDescriptionConfig(name),
    83  				Check: resource.ComposeTestCheckFunc(
    84  					testAccCheckAWSAPIGatewayUsagePlanExists("aws_api_gateway_usage_plan.main", &conf),
    85  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "description", "This is a description"),
    86  				),
    87  			},
    88  			{
    89  				Config: testAccAWSApiGatewayUsagePlanBasicConfig(name),
    90  				Check: resource.ComposeTestCheckFunc(
    91  					testAccCheckAWSAPIGatewayUsagePlanExists("aws_api_gateway_usage_plan.main", &conf),
    92  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "description", ""),
    93  				),
    94  			},
    95  		},
    96  	})
    97  }
    98  
    99  func TestAccAWSAPIGatewayUsagePlan_productCode(t *testing.T) {
   100  	var conf apigateway.UsagePlan
   101  	name := acctest.RandString(10)
   102  
   103  	resource.Test(t, resource.TestCase{
   104  		PreCheck:     func() { testAccPreCheck(t) },
   105  		Providers:    testAccProviders,
   106  		CheckDestroy: testAccCheckAWSAPIGatewayUsagePlanDestroy,
   107  		Steps: []resource.TestStep{
   108  			{
   109  				Config: testAccAWSApiGatewayUsagePlanBasicConfig(name),
   110  				Check: resource.ComposeTestCheckFunc(
   111  					testAccCheckAWSAPIGatewayUsagePlanExists("aws_api_gateway_usage_plan.main", &conf),
   112  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "product_code", ""),
   113  				),
   114  			},
   115  			{
   116  				Config: testAccAWSApiGatewayUsagePlanProductCodeConfig(name),
   117  				Check: resource.ComposeTestCheckFunc(
   118  					testAccCheckAWSAPIGatewayUsagePlanExists("aws_api_gateway_usage_plan.main", &conf),
   119  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "product_code", "MYCODE"),
   120  				),
   121  			},
   122  			{
   123  				Config: testAccAWSApiGatewayUsagePlanProductCodeUpdatedConfig(name),
   124  				Check: resource.ComposeTestCheckFunc(
   125  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "product_code", "MYCODE2"),
   126  				),
   127  			},
   128  			{
   129  				Config: testAccAWSApiGatewayUsagePlanProductCodeConfig(name),
   130  				Check: resource.ComposeTestCheckFunc(
   131  					testAccCheckAWSAPIGatewayUsagePlanExists("aws_api_gateway_usage_plan.main", &conf),
   132  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "product_code", "MYCODE"),
   133  				),
   134  			},
   135  			{
   136  				Config: testAccAWSApiGatewayUsagePlanBasicConfig(name),
   137  				Check: resource.ComposeTestCheckFunc(
   138  					testAccCheckAWSAPIGatewayUsagePlanExists("aws_api_gateway_usage_plan.main", &conf),
   139  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "product_code", ""),
   140  				),
   141  			},
   142  		},
   143  	})
   144  }
   145  
   146  func TestAccAWSAPIGatewayUsagePlan_throttling(t *testing.T) {
   147  	var conf apigateway.UsagePlan
   148  	name := acctest.RandString(10)
   149  
   150  	resource.Test(t, resource.TestCase{
   151  		PreCheck:     func() { testAccPreCheck(t) },
   152  		Providers:    testAccProviders,
   153  		CheckDestroy: testAccCheckAWSAPIGatewayUsagePlanDestroy,
   154  		Steps: []resource.TestStep{
   155  			{
   156  				Config: testAccAWSApiGatewayUsagePlanBasicConfig(name),
   157  				Check: resource.ComposeTestCheckFunc(
   158  					testAccCheckAWSAPIGatewayUsagePlanExists("aws_api_gateway_usage_plan.main", &conf),
   159  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "name", name),
   160  					resource.TestCheckNoResourceAttr("aws_api_gateway_usage_plan.main", "throttle_settings"),
   161  				),
   162  			},
   163  			{
   164  				Config: testAccAWSApiGatewayUsagePlanThrottlingConfig(name),
   165  				Check: resource.ComposeTestCheckFunc(
   166  					testAccCheckAWSAPIGatewayUsagePlanExists("aws_api_gateway_usage_plan.main", &conf),
   167  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "name", name),
   168  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "throttle_settings.4173790118.burst_limit", "2"),
   169  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "throttle_settings.4173790118.rate_limit", "5"),
   170  				),
   171  			},
   172  			{
   173  				Config: testAccAWSApiGatewayUsagePlanThrottlingModifiedConfig(name),
   174  				Check: resource.ComposeTestCheckFunc(
   175  					testAccCheckAWSAPIGatewayUsagePlanExists("aws_api_gateway_usage_plan.main", &conf),
   176  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "name", name),
   177  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "throttle_settings.1779463053.burst_limit", "3"),
   178  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "throttle_settings.1779463053.rate_limit", "6"),
   179  				),
   180  			},
   181  			{
   182  				Config: testAccAWSApiGatewayUsagePlanBasicConfig(name),
   183  				Check: resource.ComposeTestCheckFunc(
   184  					testAccCheckAWSAPIGatewayUsagePlanExists("aws_api_gateway_usage_plan.main", &conf),
   185  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "name", name),
   186  					resource.TestCheckNoResourceAttr("aws_api_gateway_usage_plan.main", "throttle_settings"),
   187  				),
   188  			},
   189  		},
   190  	})
   191  }
   192  
   193  func TestAccAWSAPIGatewayUsagePlan_quota(t *testing.T) {
   194  	var conf apigateway.UsagePlan
   195  	name := acctest.RandString(10)
   196  
   197  	resource.Test(t, resource.TestCase{
   198  		PreCheck:     func() { testAccPreCheck(t) },
   199  		Providers:    testAccProviders,
   200  		CheckDestroy: testAccCheckAWSAPIGatewayUsagePlanDestroy,
   201  		Steps: []resource.TestStep{
   202  			{
   203  				Config: testAccAWSApiGatewayUsagePlanBasicConfig(name),
   204  				Check: resource.ComposeTestCheckFunc(
   205  					testAccCheckAWSAPIGatewayUsagePlanExists("aws_api_gateway_usage_plan.main", &conf),
   206  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "name", name),
   207  					resource.TestCheckNoResourceAttr("aws_api_gateway_usage_plan.main", "quota_settings"),
   208  				),
   209  			},
   210  			{
   211  				Config: testAccAWSApiGatewayUsagePlanQuotaConfig(name),
   212  				Check: resource.ComposeTestCheckFunc(
   213  					testAccCheckAWSAPIGatewayUsagePlanExists("aws_api_gateway_usage_plan.main", &conf),
   214  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "name", name),
   215  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "quota_settings.1956747625.limit", "100"),
   216  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "quota_settings.1956747625.offset", "6"),
   217  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "quota_settings.1956747625.period", "WEEK"),
   218  				),
   219  			},
   220  			{
   221  				Config: testAccAWSApiGatewayUsagePlanQuotaModifiedConfig(name),
   222  				Check: resource.ComposeTestCheckFunc(
   223  					testAccCheckAWSAPIGatewayUsagePlanExists("aws_api_gateway_usage_plan.main", &conf),
   224  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "name", name),
   225  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "quota_settings.3909168194.limit", "200"),
   226  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "quota_settings.3909168194.offset", "20"),
   227  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "quota_settings.3909168194.period", "MONTH"),
   228  				),
   229  			},
   230  			{
   231  				Config: testAccAWSApiGatewayUsagePlanBasicConfig(name),
   232  				Check: resource.ComposeTestCheckFunc(
   233  					testAccCheckAWSAPIGatewayUsagePlanExists("aws_api_gateway_usage_plan.main", &conf),
   234  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "name", name),
   235  					resource.TestCheckNoResourceAttr("aws_api_gateway_usage_plan.main", "quota_settings"),
   236  				),
   237  			},
   238  		},
   239  	})
   240  }
   241  
   242  func TestAccAWSAPIGatewayUsagePlan_apiStages(t *testing.T) {
   243  	var conf apigateway.UsagePlan
   244  	name := acctest.RandString(10)
   245  
   246  	resource.Test(t, resource.TestCase{
   247  		PreCheck:     func() { testAccPreCheck(t) },
   248  		Providers:    testAccProviders,
   249  		CheckDestroy: testAccCheckAWSAPIGatewayUsagePlanDestroy,
   250  		Steps: []resource.TestStep{
   251  			// Create UsagePlan WITH Stages as the API calls are different
   252  			// when creating or updating.
   253  			{
   254  				Config: testAccAWSApiGatewayUsagePlanApiStagesConfig(name),
   255  				Check: resource.ComposeTestCheckFunc(
   256  					testAccCheckAWSAPIGatewayUsagePlanExists("aws_api_gateway_usage_plan.main", &conf),
   257  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "name", name),
   258  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "api_stages.0.stage", "test"),
   259  				),
   260  			},
   261  			// Handle api stages removal
   262  			{
   263  				Config: testAccAWSApiGatewayUsagePlanBasicConfig(name),
   264  				Check: resource.ComposeTestCheckFunc(
   265  					testAccCheckAWSAPIGatewayUsagePlanExists("aws_api_gateway_usage_plan.main", &conf),
   266  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "name", name),
   267  					resource.TestCheckNoResourceAttr("aws_api_gateway_usage_plan.main", "api_stages"),
   268  				),
   269  			},
   270  			// Handle api stages additions
   271  			{
   272  				Config: testAccAWSApiGatewayUsagePlanApiStagesConfig(name),
   273  				Check: resource.ComposeTestCheckFunc(
   274  					testAccCheckAWSAPIGatewayUsagePlanExists("aws_api_gateway_usage_plan.main", &conf),
   275  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "name", name),
   276  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "api_stages.0.stage", "test"),
   277  				),
   278  			},
   279  			// Handle api stages updates
   280  			{
   281  				Config: testAccAWSApiGatewayUsagePlanApiStagesModifiedConfig(name),
   282  				Check: resource.ComposeTestCheckFunc(
   283  					testAccCheckAWSAPIGatewayUsagePlanExists("aws_api_gateway_usage_plan.main", &conf),
   284  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "name", name),
   285  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "api_stages.0.stage", "foo"),
   286  				),
   287  			},
   288  			{
   289  				Config: testAccAWSApiGatewayUsagePlanBasicConfig(name),
   290  				Check: resource.ComposeTestCheckFunc(
   291  					testAccCheckAWSAPIGatewayUsagePlanExists("aws_api_gateway_usage_plan.main", &conf),
   292  					resource.TestCheckResourceAttr("aws_api_gateway_usage_plan.main", "name", name),
   293  					resource.TestCheckNoResourceAttr("aws_api_gateway_usage_plan.main", "api_stages"),
   294  				),
   295  			},
   296  		},
   297  	})
   298  }
   299  
   300  func testAccCheckAWSAPIGatewayUsagePlanExists(n string, res *apigateway.UsagePlan) resource.TestCheckFunc {
   301  	return func(s *terraform.State) error {
   302  		rs, ok := s.RootModule().Resources[n]
   303  		if !ok {
   304  			return fmt.Errorf("Not found: %s", n)
   305  		}
   306  
   307  		if rs.Primary.ID == "" {
   308  			return fmt.Errorf("No API Gateway Usage Plan ID is set")
   309  		}
   310  
   311  		conn := testAccProvider.Meta().(*AWSClient).apigateway
   312  
   313  		req := &apigateway.GetUsagePlanInput{
   314  			UsagePlanId: aws.String(rs.Primary.ID),
   315  		}
   316  		up, err := conn.GetUsagePlan(req)
   317  		if err != nil {
   318  			return err
   319  		}
   320  
   321  		if *up.Id != rs.Primary.ID {
   322  			return fmt.Errorf("APIGateway Usage Plan not found")
   323  		}
   324  
   325  		*res = *up
   326  
   327  		return nil
   328  	}
   329  }
   330  
   331  func testAccCheckAWSAPIGatewayUsagePlanDestroy(s *terraform.State) error {
   332  	conn := testAccProvider.Meta().(*AWSClient).apigateway
   333  
   334  	for _, rs := range s.RootModule().Resources {
   335  		if rs.Type != "aws_api_gateway_usage_plan" {
   336  			continue
   337  		}
   338  
   339  		req := &apigateway.GetUsagePlanInput{
   340  			UsagePlanId: aws.String(s.RootModule().Resources["aws_api_gateway_rest_api.test"].Primary.ID),
   341  		}
   342  		describe, err := conn.GetUsagePlan(req)
   343  
   344  		if err == nil {
   345  			if describe.Id != nil && *describe.Id == rs.Primary.ID {
   346  				return fmt.Errorf("API Gateway Usage Plan still exists")
   347  			}
   348  		}
   349  
   350  		aws2err, ok := err.(awserr.Error)
   351  		if !ok {
   352  			return err
   353  		}
   354  		if aws2err.Code() != "NotFoundException" {
   355  			return err
   356  		}
   357  
   358  		return nil
   359  	}
   360  
   361  	return nil
   362  }
   363  
   364  const testAccAWSAPIGatewayUsagePlanConfig = `
   365  resource "aws_api_gateway_rest_api" "test" {
   366    name = "test"
   367  }
   368  
   369  resource "aws_api_gateway_resource" "test" {
   370    rest_api_id = "${aws_api_gateway_rest_api.test.id}"
   371    parent_id = "${aws_api_gateway_rest_api.test.root_resource_id}"
   372    path_part = "test"
   373  }
   374  
   375  resource "aws_api_gateway_method" "test" {
   376    rest_api_id = "${aws_api_gateway_rest_api.test.id}"
   377    resource_id = "${aws_api_gateway_resource.test.id}"
   378    http_method = "GET"
   379    authorization = "NONE"
   380  }
   381  
   382  resource "aws_api_gateway_method_response" "error" {
   383    rest_api_id = "${aws_api_gateway_rest_api.test.id}"
   384    resource_id = "${aws_api_gateway_resource.test.id}"
   385    http_method = "${aws_api_gateway_method.test.http_method}"
   386    status_code = "400"
   387  }
   388  
   389  resource "aws_api_gateway_integration" "test" {
   390    rest_api_id = "${aws_api_gateway_rest_api.test.id}"
   391    resource_id = "${aws_api_gateway_resource.test.id}"
   392    http_method = "${aws_api_gateway_method.test.http_method}"
   393  
   394    type = "HTTP"
   395    uri = "https://www.google.de"
   396    integration_http_method = "GET"
   397  }
   398  
   399  resource "aws_api_gateway_integration_response" "test" {
   400    rest_api_id = "${aws_api_gateway_rest_api.test.id}"
   401    resource_id = "${aws_api_gateway_resource.test.id}"
   402    http_method = "${aws_api_gateway_integration.test.http_method}"
   403    status_code = "${aws_api_gateway_method_response.error.status_code}"
   404  }
   405  
   406  resource "aws_api_gateway_deployment" "test" {
   407    depends_on = ["aws_api_gateway_integration.test"]
   408  
   409    rest_api_id = "${aws_api_gateway_rest_api.test.id}"
   410    stage_name = "test"
   411    description = "This is a test"
   412  
   413    variables = {
   414      "a" = "2"
   415    }
   416  }
   417  
   418  resource "aws_api_gateway_deployment" "foo" {
   419    depends_on = ["aws_api_gateway_integration.test"]
   420  
   421    rest_api_id = "${aws_api_gateway_rest_api.test.id}"
   422    stage_name = "foo"
   423    description = "This is a prod stage"
   424  }
   425  `
   426  
   427  func testAccAWSApiGatewayUsagePlanBasicConfig(rName string) string {
   428  	return fmt.Sprintf(testAccAWSAPIGatewayUsagePlanConfig+`
   429  resource "aws_api_gateway_usage_plan" "main" {
   430    name = "%s"
   431  }
   432  `, rName)
   433  }
   434  
   435  func testAccAWSApiGatewayUsagePlanDescriptionConfig(rName string) string {
   436  	return fmt.Sprintf(testAccAWSAPIGatewayUsagePlanConfig+`
   437  resource "aws_api_gateway_usage_plan" "main" {
   438    name        = "%s"
   439    description = "This is a description"
   440  }
   441  `, rName)
   442  }
   443  
   444  func testAccAWSApiGatewayUsagePlanDescriptionUpdatedConfig(rName string) string {
   445  	return fmt.Sprintf(testAccAWSAPIGatewayUsagePlanConfig+`
   446  resource "aws_api_gateway_usage_plan" "main" {
   447    name        = "%s"
   448    description = "This is a new description"
   449  }
   450  `, rName)
   451  }
   452  
   453  func testAccAWSApiGatewayUsagePlanProductCodeConfig(rName string) string {
   454  	return fmt.Sprintf(testAccAWSAPIGatewayUsagePlanConfig+`
   455  resource "aws_api_gateway_usage_plan" "main" {
   456    name         = "%s"
   457    product_code = "MYCODE"
   458  }
   459  `, rName)
   460  }
   461  
   462  func testAccAWSApiGatewayUsagePlanProductCodeUpdatedConfig(rName string) string {
   463  	return fmt.Sprintf(testAccAWSAPIGatewayUsagePlanConfig+`
   464  resource "aws_api_gateway_usage_plan" "main" {
   465    name         = "%s"
   466    product_code = "MYCODE2"
   467  }
   468  `, rName)
   469  }
   470  
   471  func testAccAWSApiGatewayUsagePlanBasicUpdatedConfig(rName string) string {
   472  	return fmt.Sprintf(testAccAWSAPIGatewayUsagePlanConfig+`
   473  resource "aws_api_gateway_usage_plan" "main" {
   474    name = "%s"
   475  }
   476  `, rName)
   477  }
   478  
   479  func testAccAWSApiGatewayUsagePlanThrottlingConfig(rName string) string {
   480  	return fmt.Sprintf(testAccAWSAPIGatewayUsagePlanConfig+`
   481  resource "aws_api_gateway_usage_plan" "main" {
   482    name        = "%s"
   483  
   484    throttle_settings {
   485      burst_limit = 2
   486      rate_limit  = 5
   487    }
   488  }
   489  `, rName)
   490  }
   491  
   492  func testAccAWSApiGatewayUsagePlanThrottlingModifiedConfig(rName string) string {
   493  	return fmt.Sprintf(testAccAWSAPIGatewayUsagePlanConfig+`
   494  resource "aws_api_gateway_usage_plan" "main" {
   495    name        = "%s"
   496  
   497    throttle_settings {
   498      burst_limit = 3
   499      rate_limit  = 6
   500    }
   501  }
   502  `, rName)
   503  }
   504  
   505  func testAccAWSApiGatewayUsagePlanQuotaConfig(rName string) string {
   506  	return fmt.Sprintf(testAccAWSAPIGatewayUsagePlanConfig+`
   507  resource "aws_api_gateway_usage_plan" "main" {
   508    name        = "%s"
   509  
   510    quota_settings {
   511      limit  = 100
   512      offset = 6
   513      period = "WEEK"
   514    }
   515  }
   516  `, rName)
   517  }
   518  
   519  func testAccAWSApiGatewayUsagePlanQuotaModifiedConfig(rName string) string {
   520  	return fmt.Sprintf(testAccAWSAPIGatewayUsagePlanConfig+`
   521  resource "aws_api_gateway_usage_plan" "main" {
   522    name        = "%s"
   523  
   524    quota_settings {
   525      limit  = 200
   526      offset = 20
   527      period = "MONTH"
   528    }
   529  }
   530  `, rName)
   531  }
   532  
   533  func testAccAWSApiGatewayUsagePlanApiStagesConfig(rName string) string {
   534  	return fmt.Sprintf(testAccAWSAPIGatewayUsagePlanConfig+`
   535  resource "aws_api_gateway_usage_plan" "main" {
   536    name        = "%s"
   537  
   538    api_stages {
   539      api_id = "${aws_api_gateway_rest_api.test.id}"
   540      stage  = "${aws_api_gateway_deployment.test.stage_name}"
   541    }
   542  }
   543  `, rName)
   544  }
   545  
   546  func testAccAWSApiGatewayUsagePlanApiStagesModifiedConfig(rName string) string {
   547  	return fmt.Sprintf(testAccAWSAPIGatewayUsagePlanConfig+`
   548  resource "aws_api_gateway_usage_plan" "main" {
   549    name        = "%s"
   550  
   551    api_stages {
   552      api_id = "${aws_api_gateway_rest_api.test.id}"
   553      stage  = "${aws_api_gateway_deployment.foo.stage_name}"
   554    }
   555  }
   556  `, rName)
   557  }