Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws_appsync_graphql_api resource doesn't support LAMBDA authentication type #20644

Closed
rkeiii opened this issue Aug 20, 2021 · 8 comments · Fixed by #20857
Closed

aws_appsync_graphql_api resource doesn't support LAMBDA authentication type #20644

rkeiii opened this issue Aug 20, 2021 · 8 comments · Fixed by #20857
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/appsync Issues and PRs that pertain to the appsync service.
Milestone

Comments

@rkeiii
Copy link

rkeiii commented Aug 20, 2021

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 other comments that do not add relevant new information or questions, 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

The aws_appsync_graphql_api resource is missing the new LAMBDA authentication_type that was released on July 30th 2021. This new authentication system makes it much simpler to add entirely custom auth to AppSync (no Cognito/etc. needed).

I might be interested in adding support for this but I've never contributed to this codebase before.

Feature release blog post: https://aws.amazon.com/blogs/mobile/appsync-lambda-auth/

New or Affected Resource(s)

  • aws_appsync_graphql_api
@rkeiii rkeiii added the enhancement Requests to existing resources that expand the functionality or scope. label Aug 20, 2021
@github-actions github-actions bot added needs-triage Waiting for first response or review from a maintainer. service/appsync Issues and PRs that pertain to the appsync service. labels Aug 20, 2021
@breathingdust breathingdust removed the needs-triage Waiting for first response or review from a maintainer. label Aug 26, 2021
@bengiddins
Copy link

bengiddins commented Sep 1, 2021

Suggested implementation (I need this too!):

additional_authentication_provider {
  authentication_type = "AWS_LAMBDA"

  lambda_config {
    region = "..."
    function_arn = "..."
    auth_ttl = "..."
    token_regex = "..."
  }
}

Based on AppSync's additional authorization provider UI for AWS Lambda authorization mode.

In the meantime, anyone who needs to use this by manually updating their AppSync configuration through the console can use the following inside of their aws_appsync_graphql_api resource declaration:

  lifecycle {
    ignore_changes = [additional_authentication_provider]
  }

@Pharb
Copy link
Contributor

Pharb commented Sep 8, 2021

I am working on a PR for this.

Usage example:

resource "aws_appsync_graphql_api" "example" {
  authentication_type = "AWS_LAMBDA"
  name                = "example"

  lambda_authorizer_config {
    authorizer_uri = "arn:aws:lambda:us-east-1:123456789012:function:custom_lambda_authorizer"
  }
}

resource "aws_lambda_permission" "appsync_lambda_authorizer" {
  statement_id  = "appsync_lambda_authorizer"
  action        = "lambda:InvokeFunction"
  function_name = "custom_lambda_authorizer"
  principal     = "appsync.amazonaws.com"
  source_arn    = aws_appsync_graphql_api.example.arn
}

Pharb added a commit to Pharb/terraform-provider-aws that referenced this issue Sep 9, 2021
…ment (hashicorp#20644)

Issue: hashicorp#20644
API docs: https://docs.aws.amazon.com/appsync/latest/APIReference/API_LambdaAuthorizerConfig.html

Output from acceptance testing:
```
make testacc TESTARGS='-run=TestAccAWSAppsyncGraphqlApi_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAWSAppsyncGraphqlApi_ -timeout 180m
--- PASS: TestAccAWSAppsyncGraphqlApi_basic (147.72s)
--- PASS: TestAccAWSAppsyncGraphqlApi_AdditionalAuthentication_AWSIAM (148.24s)
--- PASS: TestAccAWSAppsyncGraphqlApi_AdditionalAuthentication_APIKey (149.20s)
--- PASS: TestAccAWSAppsyncGraphqlApi_AdditionalAuthentication_OpenIDConnect (149.32s)
--- PASS: TestAccAWSAppsyncGraphqlApi_LogConfig (153.51s)
--- PASS: TestAccAWSAppsyncGraphqlApi_AdditionalAuthentication_CognitoUserPools (173.33s)
--- PASS: TestAccAWSAppsyncGraphqlApi_AdditionalAuthentication_AwsLambda (196.04s)
--- PASS: TestAccAWSAppsyncGraphqlApi_AdditionalAuthentication_Multiple (204.38s)
--- PASS: TestAccAWSAppsyncGraphqlApi_XrayEnabled (214.18s)
--- PASS: TestAccAWSAppsyncGraphqlApi_Name (215.34s)
--- PASS: TestAccAWSAppsyncGraphqlApi_AuthenticationType_AwsLambda (221.80s)
--- PASS: TestAccAWSAppsyncGraphqlApi_OpenIDConnectConfig_AuthTTL (235.05s)
--- PASS: TestAccAWSAppsyncGraphqlApi_Tags (236.82s)
--- PASS: TestAccAWSAppsyncGraphqlApi_UserPoolConfig_AwsRegion (242.45s)
--- PASS: TestAccAWSAppsyncGraphqlApi_LogConfig_ExcludeVerboseContent (250.77s)
--- PASS: TestAccAWSAppsyncGraphqlApi_UserPoolConfig_DefaultAction (250.94s)
--- PASS: TestAccAWSAppsyncGraphqlApi_AuthenticationType_APIKey (116.05s)
--- PASS: TestAccAWSAppsyncGraphqlApi_AuthenticationType_OpenIDConnect (115.22s)
--- PASS: TestAccAWSAppsyncGraphqlApi_AuthenticationType_AmazonCognitoUserPools (125.39s)
--- PASS: TestAccAWSAppsyncGraphqlApi_disappears (65.90s)
--- PASS: TestAccAWSAppsyncGraphqlApi_LambdaAuthorizerConfig_IdentityValidationExpression (281.96s)
--- PASS: TestAccAWSAppsyncGraphqlApi_AuthenticationType_AWSIAM (88.56s)
--- PASS: TestAccAWSAppsyncGraphqlApi_LambdaAuthorizerConfig_AuthorizerUri (294.85s)
--- PASS: TestAccAWSAppsyncGraphqlApi_OpenIDConnectConfig_IatTTL (158.58s)
--- PASS: TestAccAWSAppsyncGraphqlApi_OpenIDConnectConfig_Issuer (154.12s)
--- PASS: TestAccAWSAppsyncGraphqlApi_LogConfig_FieldLogLevel (312.61s)
--- PASS: TestAccAWSAppsyncGraphqlApi_Schema (143.80s)
--- PASS: TestAccAWSAppsyncGraphqlApi_AuthenticationType (126.84s)
--- PASS: TestAccAWSAppsyncGraphqlApi_OpenIDConnectConfig_ClientID (113.13s)
--- PASS: TestAccAWSAppsyncGraphqlApi_LambdaAuthorizerConfig_AuthorizerResultTtlInSeconds (356.98s)
PASS
ok      github.com/terraform-providers/terraform-provider-aws/aws       359.589s
```
@digitalfiz
Copy link
Contributor

digitalfiz commented Oct 7, 2021

How can we get #20857 pushed over that finish line?

@6be709c0
Copy link

Any update, would love to use this feature :)

@filipjakubowski
Copy link

filipjakubowski commented Nov 22, 2021

I am waiting for this change. At this moment I am using AWS CLI command in my CI/CD post terraform but still when working form console by myself I find this being a pain.

 aws appsync update-graphql-api \
            --no-cli-auto-prompt \
            --name "$PROJECT_NAME" \
            --api-id "$APPSYNC_ID" \
            --authentication-type "AWS_LAMBDA" \
            --lambda-authorizer-config "{ \"authorizerResultTtlInSeconds\": 300, \"authorizerUri\": \"$LAMBDA_AUTH_APPSYNC_ARN\" }"

@6be709c0
Copy link

thank you @filipjakubowski, based on your cli, I'm using AWS_LAMBDA as second auth type:

          aws appsync update-graphql-api \
          --no-cli-auto-prompt \
          --name "$PROJECT_NAME" \
          --authentication-type "API_KEY" \
          --api-id "$APPSYNC_ID" \
          --region us-east-1 \
          --additional-authentication-providers "[ { \"authenticationType\":\"AWS_LAMBDA\", \"lambdaAuthorizerConfig\": { \"authorizerResultTtlInSeconds\": 0, \"authorizerUri\": \"$LAMBDA_AUTH_APPSYNC_ARN\", \"identityValidationExpression\": \"auth\" } } ]"

breathingdust pushed a commit that referenced this issue Dec 10, 2021
…ment (#20857)

* tests/resource/aws_appsync_graphql_api: Update deprecated Providers to ProviderFactories

* resource/aws_appsync_graphql_api: Add `lambda_authorizer_config` argument (#20644)

Issue: #20644
API docs: https://docs.aws.amazon.com/appsync/latest/APIReference/API_LambdaAuthorizerConfig.html

Output from acceptance testing:
```
make testacc TESTARGS='-run=TestAccAWSAppsyncGraphqlApi_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAWSAppsyncGraphqlApi_ -timeout 180m
--- PASS: TestAccAWSAppsyncGraphqlApi_basic (147.72s)
--- PASS: TestAccAWSAppsyncGraphqlApi_AdditionalAuthentication_AWSIAM (148.24s)
--- PASS: TestAccAWSAppsyncGraphqlApi_AdditionalAuthentication_APIKey (149.20s)
--- PASS: TestAccAWSAppsyncGraphqlApi_AdditionalAuthentication_OpenIDConnect (149.32s)
--- PASS: TestAccAWSAppsyncGraphqlApi_LogConfig (153.51s)
--- PASS: TestAccAWSAppsyncGraphqlApi_AdditionalAuthentication_CognitoUserPools (173.33s)
--- PASS: TestAccAWSAppsyncGraphqlApi_AdditionalAuthentication_AwsLambda (196.04s)
--- PASS: TestAccAWSAppsyncGraphqlApi_AdditionalAuthentication_Multiple (204.38s)
--- PASS: TestAccAWSAppsyncGraphqlApi_XrayEnabled (214.18s)
--- PASS: TestAccAWSAppsyncGraphqlApi_Name (215.34s)
--- PASS: TestAccAWSAppsyncGraphqlApi_AuthenticationType_AwsLambda (221.80s)
--- PASS: TestAccAWSAppsyncGraphqlApi_OpenIDConnectConfig_AuthTTL (235.05s)
--- PASS: TestAccAWSAppsyncGraphqlApi_Tags (236.82s)
--- PASS: TestAccAWSAppsyncGraphqlApi_UserPoolConfig_AwsRegion (242.45s)
--- PASS: TestAccAWSAppsyncGraphqlApi_LogConfig_ExcludeVerboseContent (250.77s)
--- PASS: TestAccAWSAppsyncGraphqlApi_UserPoolConfig_DefaultAction (250.94s)
--- PASS: TestAccAWSAppsyncGraphqlApi_AuthenticationType_APIKey (116.05s)
--- PASS: TestAccAWSAppsyncGraphqlApi_AuthenticationType_OpenIDConnect (115.22s)
--- PASS: TestAccAWSAppsyncGraphqlApi_AuthenticationType_AmazonCognitoUserPools (125.39s)
--- PASS: TestAccAWSAppsyncGraphqlApi_disappears (65.90s)
--- PASS: TestAccAWSAppsyncGraphqlApi_LambdaAuthorizerConfig_IdentityValidationExpression (281.96s)
--- PASS: TestAccAWSAppsyncGraphqlApi_AuthenticationType_AWSIAM (88.56s)
--- PASS: TestAccAWSAppsyncGraphqlApi_LambdaAuthorizerConfig_AuthorizerUri (294.85s)
--- PASS: TestAccAWSAppsyncGraphqlApi_OpenIDConnectConfig_IatTTL (158.58s)
--- PASS: TestAccAWSAppsyncGraphqlApi_OpenIDConnectConfig_Issuer (154.12s)
--- PASS: TestAccAWSAppsyncGraphqlApi_LogConfig_FieldLogLevel (312.61s)
--- PASS: TestAccAWSAppsyncGraphqlApi_Schema (143.80s)
--- PASS: TestAccAWSAppsyncGraphqlApi_AuthenticationType (126.84s)
--- PASS: TestAccAWSAppsyncGraphqlApi_OpenIDConnectConfig_ClientID (113.13s)
--- PASS: TestAccAWSAppsyncGraphqlApi_LambdaAuthorizerConfig_AuthorizerResultTtlInSeconds (356.98s)
PASS
ok      github.com/terraform-providers/terraform-provider-aws/aws       359.589s
```

* resource/aws_appsync_graphql_api: Add changelog entry 20857.txt

* resource/aws_appsync_graphql_api: Terraform fmt in test config

* Revert "tests/resource/aws_appsync_graphql_api: Update deprecated Providers to ProviderFactories"

This reverts commit 1f981fc.

* tests/resource/aws_appsync_graphql_api: Changes from #20000 and #21400

* graphql_api: Re-order map alphabetically (review comment)
@github-actions github-actions bot added this to the v3.70.0 milestone Dec 10, 2021
@github-actions
Copy link

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

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/appsync Issues and PRs that pertain to the appsync service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants