title: terraform: unable to link api gateway usage plan to stage, "api_stages.0.stage" is required
body: <p>I am somehow unable to create an API gateway usage plan to its stage even though I followed what was given in the <a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_usage_plan" rel="nofollow noreferrer">docs</a>.</p>
  <p>This is the block of resource code.</p>
  <pre><code>resource &quot;aws_api_gateway_usage_plan&quot; &quot;main&quot; {
    name = var.project
  
    api_stages {
      api_id = aws_api_gateway_rest_api.main.id
      stage  = aws_api_gateway_deployment.main.stage_name
    }
  
    quota_settings {
      limit  = 10000
      period = &quot;WEEK&quot;
    }
  
    throttle_settings {
      burst_limit = 5
      rate_limit  = 50
    }
  
    tags = var.tags
  }
  </code></pre>
  <p>and the error msg when I <code>terraform apply</code>; which was strange when I already specified the stage arg &amp; value.</p>
  <pre class="lang-bash prettyprint-override"><code>Error: Missing required argument
  │
  │   with aws_api_gateway_usage_plan.main,
  │   on main.tf line 112, in resource &quot;aws_api_gateway_usage_plan&quot; &quot;main&quot;:
  │  112: resource &quot;aws_api_gateway_usage_plan&quot; &quot;main&quot; {
  │
  │ The argument &quot;api_stages.0.stage&quot; is required, but no definition was found.
  </code></pre>
  <p>The entire script is as such.</p>
  <pre><code>
  
  resource &quot;aws_api_gateway_rest_api&quot; &quot;main&quot; {
    # naming api gateway
    name        = &quot;api-gateway-${var.project}-${var.env}&quot;
    description = &quot;API gateway for ${var.project}&quot;
    tags        = var.tags
  }
  
  resource &quot;aws_api_gateway_resource&quot; &quot;main&quot; {
    # define API endpoint
    rest_api_id = aws_api_gateway_rest_api.main.id
    parent_id   = aws_api_gateway_rest_api.main.root_resource_id
    path_part   = &quot;{proxy+}&quot;
  }
  
  
  # method ------
  
  resource &quot;aws_api_gateway_method&quot; &quot;main&quot; {
    # define the method(s), e.g. GET / POST / etc.
    resource_id   = aws_api_gateway_resource.main.id
    rest_api_id   = aws_api_gateway_rest_api.main.id
    authorization = &quot;NONE&quot;
    http_method   = &quot;ANY&quot;
  }
  
  
  # integration ------
  
  resource &quot;aws_api_gateway_integration&quot; &quot;main&quot; {
    # link with a lambda function
    rest_api_id = aws_api_gateway_rest_api.main.id
    resource_id = aws_api_gateway_resource.main.id
    http_method = aws_api_gateway_method.main.http_method
  
    integration_http_method = &quot;POST&quot;
    type                    = &quot;AWS_PROXY&quot;
    uri                     = var.lambda_arn
  }
  
  
  # deployment to stage ------
  
  resource &quot;aws_api_gateway_deployment&quot; &quot;main&quot; {
    # deploy API to a stage
    rest_api_id = aws_api_gateway_rest_api.main.id
    depends_on = [
      aws_api_gateway_integration.main
    ]
    lifecycle {
      create_before_destroy = true
    }
  }
  
  resource &quot;aws_api_gateway_stage&quot; &quot;main&quot; {
    # define a stage
    deployment_id = aws_api_gateway_deployment.main.id
    rest_api_id   = aws_api_gateway_rest_api.main.id
    stage_name    = var.env
  }
  
  resource &quot;aws_lambda_permission&quot; &quot;apigw_lambda&quot; {
    statement_id  = &quot;AllowExecutionFromAPIGateway-${var.project}-${var.env}&quot;
    action        = &quot;lambda:InvokeFunction&quot;
    function_name = var.lambda_name
    principal     = &quot;apigateway.amazonaws.com&quot;
    source_arn = &quot;${aws_api_gateway_rest_api.main.execution_arn}/*/*&quot;
  }
  
  
  # API key ------
  
  resource &quot;aws_api_gateway_usage_plan&quot; &quot;main&quot; {
    name = var.project
  
    api_stages {
      api_id = aws_api_gateway_rest_api.main.id
      stage  = aws_api_gateway_deployment.main.stage_name
    }
  
    quota_settings {
      limit  = 10000
      period = &quot;WEEK&quot;
    }
  
    throttle_settings {
      burst_limit = 5
      rate_limit  = 50
    }
  
    tags = var.tags
  }
  
  resource &quot;aws_api_gateway_api_key&quot; &quot;main&quot; {
    name = &quot;api-key-${var.project}&quot;
  }
  
  resource &quot;aws_api_gateway_usage_plan_key&quot; &quot;main&quot; {
    key_id        = aws_api_gateway_api_key.main.id
    key_type      = &quot;API_KEY&quot;
    usage_plan_id = aws_api_gateway_usage_plan.main.id
  }
  
  </code></pre>
  <p>The versions used were</p>
  <pre><code>terraform {
    required_providers {
      aws = {
        source  = &quot;hashicorp/aws&quot;
        version = &quot;~&gt; 4.21.0&quot;
      }
    }
    required_version = &quot;&gt;= 1.2.2&quot;
  }
  </code></pre>