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

Feature Request: CloudFront Functions #19225

Closed
alexjurkiewicz opened this issue May 4, 2021 · 8 comments · Fixed by #19315
Closed

Feature Request: CloudFront Functions #19225

alexjurkiewicz opened this issue May 4, 2021 · 8 comments · Fixed by #19315
Labels
enhancement Requests to existing resources that expand the functionality or scope. new-resource Introduces a new resource. service/cloudfront Issues and PRs that pertain to the cloudfront service.
Milestone

Comments

@alexjurkiewicz
Copy link
Contributor

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

Please add support for CloudFront Functions

New or Affected Resource(s)

  • aws_cloudfront_function

Potential Terraform Configuration

resource "aws_cloudfront_function" "default" {
  name = "test"
  runtime = "cloudfront-js-1.0"
  comment = "my function"
  publish = true
  code = file("${path.module}/function.js")
}

References

@alexjurkiewicz alexjurkiewicz added the enhancement Requests to existing resources that expand the functionality or scope. label May 4, 2021
@ghost ghost added the service/cloudfront Issues and PRs that pertain to the cloudfront service. label May 4, 2021
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label May 4, 2021
@ewbankkit
Copy link
Contributor

@ewbankkit ewbankkit added new-resource Introduces a new resource. and removed needs-triage Waiting for first response or review from a maintainer. labels May 4, 2021
@chrs-myrs
Copy link

We have been working with AWS on the private preview here, the above functionality creates the function, but what we urgently need is the ability to assign a function to a CloudFront Behaviour. We wouldn't use the above suggestion as our functions are deployed and published by a deployment pipeline. Currently we need to do the Function -> Behaviour assignment manually, but this is the perfect job for Terraform (which currently unassociates the functions every time an apply is made affecting a distribution)

@dbednall
Copy link

dbednall commented May 7, 2021

Cloudfront Functions basically get associated to distribution behaviour(s) like Lambda@Edge

In addition to the proposed new resource is a change is required to cloudfront_distribution to have a new config block to manage the function association as part of a Default/Ordered Cache Behaviour configuration.

So taking inspiration from the existing config block for Lambda@Edge: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudfront_distribution#lambda-function-association this feature requires the following

ordered_cache_behavior {
    # ... other configuration ...

    # zero or more of 
    function_association {
      event_type   = "viewer-request"
      # the specific event to trigger this function. Valid values: viewer-request, viewer-response

      arn   = aws_cloudfront_function.default.arn
      #  e.g. arn:aws:cloudfront::000000000001:function/test
    }
  }

Some might say function_association {} should be cloudfront_function_association {} or similar to fully distinguish from lambda_function_association {} but the API doesn't https://docs.aws.amazon.com/cloudfront/latest/APIReference/API_DefaultCacheBehavior.html (see FunctionAssociations)


Alternatively the config block could be made generic to handle both the association of Lambda@Edge functions AND Cloudfront Functions fuctions and deprecate lambda_function_association {}

@ZsoltPath
Copy link
Contributor

Is someone working on this? I could give it a go next week.

@rgant
Copy link

rgant commented May 8, 2021

Is there any work around in the meantime that I can use to stop terraform from removing the cloudfront functions from my distributions?

Right now every time my cloudfront distribution is modified it removes the functions without warning me. Even something that warns me would be good.

@andy-b-84
Copy link
Contributor

Is there any work around in the meantime that I can use to stop terraform from removing the cloudfront functions from my distributions?

Right now every time my cloudfront distribution is modified it removes the functions without warning me. Even something that warns me would be good.

The best you can get, without using a branch or a fork for the provider, would be to execute terraform plan & terraform apply using -target options and not target your aws_cloudfront_distributions .

@ghost
Copy link

ghost commented May 19, 2021

This has been released in version 3.41.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 for triage. Thanks!

@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 Jun 18, 2021
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. new-resource Introduces a new resource. service/cloudfront Issues and PRs that pertain to the cloudfront service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants