Terraform-provider-aws: Need AppSync API attributes to include endpoint URL

Created on 19 Jun 2018  ·  12Comments  ·  Source: hashicorp/terraform-provider-aws

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

Currently the aws_appsync_graphql_api resource only exports arn and id as attributes (no others). It would be very very useful to me if the endpoint URL was also exported (like CloudFormation does).

New or Affected Resource(s)

  • aws_appsync_graphql_api

Potential Terraform Configuration

No change is proposed to the resource definition, the existing example is fine:

resource "aws_appsync_graphql_api" "example" {
  authentication_type = "API_KEY"
  name = "example"
}

However this change would also enable these usages:

output "api_endpoint" {
  value = "${aws_appsync_graphql_api.example.api_endpoint}"
}

and:

resource "aws_lambda_function" "iot_event" {
  ...

  environment {
    variables {
      GRAPHQL_ENDPOINT = "${aws_appsync_graphql_api.example.api_endpoint}"
    }
  }
}

References

  • #2705 -- more comprehensive proposal for AppSync generally
enhancement servicappsync

Most helpful comment

For those that need to access the endpoint in TF, here is a script that will get it for you in an external data resource. Usage in TF is below.

data "external" "appsync_graphql_endpoint" {
  program = [
    "bash",
    "${path.module}/scripts/get-graphql-endpoint.sh"
  ]
  query {
    api_id = "${aws_appsync_graphql_api.ff_graphql.id}"
  }
}

Use the external like the following:
${data.external.appsync_graphql_endpoint.result["endpoint"]}

Change the .txt extension to .sh (won't let me upload a script)
get-graphql-endpoint.txt

All 12 comments

I took a quick look at what would be required to do this and it's not as simple as I'd expected. The API returns a map of URLs which I imagine would contain a single entry with the URL that I'm interested in. I don't know under what circumstances it might contain something else as well.

Is there any update on this? It's almost useless to create an API endpoint and then not expose the endpoint URI.

It appears that the URI required is under the "GRAPHQL" key in the map that you referenced @macbutch .

Thanks @joseph-wortmann. I can't see where the keys in that map are documented - did you figure this out from calling the API and inspecting the results or am I just not reading the docs right? I think we'd be interested in at least starting working on a pull request it's not very high priority for us (yet) but it's becoming more and more important.

@macbutch I figured it out by calling the CLI and observing the results compared against the console. Honestly, I didn't even go to the docs. As we all know, sometimes they can be a little less than they should. Maybe it is AWS's way of testing us.

I'd be happy to help with the PR, but Go is like reading greek for me. I can't read greek either

For those that need to access the endpoint in TF, here is a script that will get it for you in an external data resource. Usage in TF is below.

data "external" "appsync_graphql_endpoint" {
  program = [
    "bash",
    "${path.module}/scripts/get-graphql-endpoint.sh"
  ]
  query {
    api_id = "${aws_appsync_graphql_api.ff_graphql.id}"
  }
}

Use the external like the following:
${data.external.appsync_graphql_endpoint.result["endpoint"]}

Change the .txt extension to .sh (won't let me upload a script)
get-graphql-endpoint.txt

I'm not a patient person, so I created a module that does the above for you. Feel free to use until the resource publishes the endpoint.

https://registry.terraform.io/modules/QuiNovas/appsync-graphql-api-endpoint/aws/1.0.3

Thanks, @macbutch and @joseph-wortmann! I would also like to see this feature implemented. Additionally, I would like to see this information in the .tfstate file because I use it to grab information about the infrastructure in my js app.

Pull request submitted which includes the endpoint via aws_appsync_graphql_api.example.uris["GRAPHQL"]: #6138

The above feature has been merged and will release with version 1.41.0 of the AWS provider, likely later today. 👍

This has been released in version 1.41.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

Was this page helpful?
0 / 5 - 0 ratings