• Stars
    star
    119
  • Rank 296,819 (Top 6 %)
  • Language
    Go
  • License
    Mozilla Public Li...
  • Created over 7 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Terraform Fastly provider

Fastly Terraform Provider

Requirements

  • Terraform 0.12.x or higher
  • Go 1.18 (to build the provider plugin)

NOTE: the last version of the Fastly provider to support Terraform 0.11.x and below was v0.26.0

Building The Provider

Clone repository to: $GOPATH/src/github.com/fastly/terraform-provider-fastly

$ mkdir -p $GOPATH/src/github.com/fastly; cd $GOPATH/src/github.com/fastly
$ git clone [email protected]:fastly/terraform-provider-fastly

Enter the provider directory and build the provider

$ cd $GOPATH/src/github.com/fastly/terraform-provider-fastly
$ make build

Developing the Provider

If you wish to work on the provider, you'll first need Go installed on your machine (version 1.18+ is required).

To compile the provider, run make build. This will build the provider and put the provider binary in a local bin directory.

$ make build
...

Alongside the newly built binary a file called developer_overrides.tfrc will be created. The make build target will communicate back details for setting the TF_CLI_CONFIG_FILE environment variable that will enable Terraform to use your locally built provider binary.

NOTE: If you have issues seeing any behaviours from code changes you've made to the provider, then it might be the terraform CLI is getting confused by which provider binary it should be using. Check inside the ./bin/ directory to see if there are multiple providers with different commit hashes (e.g. terraform-provider-fastly_v2.2.0-5-gfdc37cee) and delete them first before running make build. This should help the Terraform CLI resolve to the correct binary.

Debugging the provider

The previous method with dev_overrides should be sufficient for most development use including testing your local changes with actual Terraform code. However, sometimes it can be helpful to run the provider in debug mode if you need to attach a debugger like delve to solve a particular issue.

The way Terraform normally works is that it starts the provider in a subprocess and connects to it using GRPC over a local socket. (For more information on this, see hashicorp/go-plugin). For debugging, it is possible to bypass this and execute the provider in a separate process, then tell Terraform how to communicate with it. The benefit of this is that the provider can be launched with a debugger attached in the same way that the debugger would attach to any normal executable.

There are a few ways to do this depending on which debugger is being used, but we will use delve here as the process should be pretty similar for other debuggers. The two things that need to be configured are that the provider is compiled without optimisations, and the executable is run with the --debug flag. Compiling without optimisations ensures that the debugger can access all of the symbols in the binary that it needs to, and the --debug flag tells the Terraform plugin SDK to expect to be run in its own process, and to display the instructions for connecting to it after it starts up.

With delve this can be done in a single command:

$ dlv debug . -- --debug
Type 'help' for list of commands.
(dlv) continue
{"@level":"debug","@message":"plugin address","@timestamp":"2021-03-26T12:10:13.320981Z","address":"/var/folders/qm/swg2hf4h5t8sdht8yhds4dg6m0000gn/T/plugin865249851","network":"unix"}
Provider started, to attach Terraform set the TF_REATTACH_PROVIDERS env var:

        TF_REATTACH_PROVIDERS='{"fastly/fastly":{"Protocol":"grpc","Pid":54132,"Test":true,"Addr":{"Network":"unix","String":"/var/folders/qm/swg2hf4h5t8sdht8yhds4dg6m0000gn/T/plugin865249851"}}}'

This can also be done in two separate steps. The -gcflags disables optimisations (-N) and inlining (-l).

$ go build -gcflags="all=-N -l" -o terraform-provider-fastly_debug
$ dlv exec terraform-provider-fastly_debug -- --debug

As the message instructs, go to another shell and export the TF_REATTACH_PROVIDERS environment variable. Then use Terraform as usual, and it will automatically use the provider in the debugger.

$ export TF_REATTACH_PROVIDERS='{"fastly/fastly":{"Protocol":"grpc","Pid":54132,"Test":true,"Addr":{"Network":"unix","String":"/var/folders/qm/swg2hf4h5t8sdht8yhds4dg6m0000gn/T/plugin865249851"}}}'
$ terraform plan

You will then be able to set breakpoints and trace the provider's execution using the debugger as you would expect.

The implementation for setting up debug mode presumes Terraform 0.13.x is being used. If you're using Terraform 0.12.x you'll need to manually modify the value assigned to TF_REATTACH_PROVIDERS so that the key "fastly/fastly" becomes "registry.terraform.io/-/fastly". See HashiCorp's "Support for Debuggable Provider Binaries" for more details.

Summary

(first shell)  dlv debug . --headless -- --debug
(second shell) dlv connect <output from first shell>
               continue
               <Ctrl-c>
               break fastly/block_fastly_service_package.go:123
(third shell)  export TF_REATTACH_PROVIDERS="..."
               terraform apply
(second shell) continue (do your step debugging)
               <Ctrl-c> (then run another terraform command from third shell)

Testing

In order to test the provider, you can simply run make test.

$ make test

In order to run the full suite of Acceptance tests, run make testacc.

Note: Acceptance tests create real resources, and often cost money to run. You should expect that the full acceptance test suite will take hours to run.

$ make testacc

In order to run an individual acceptance test, the '-run' flag can be used together with a regular expression. The following example uses a regular expression matching single test called 'TestAccFastlyServiceVCL_basic'.

$ make testacc TESTARGS='-run=TestAccFastlyServiceVCL_basic'

The following example uses a regular expression to execute a grouping of basic acceptance tests.

$ make testacc TESTARGS='-run=TestAccFastlyServiceVCL.*_basic'

In order to run the tests with extra debugging context, prefix the make command with TF_LOG (see the terraform documentation for details).

$ TF_LOG=trace make testacc

By default, the tests run with a parallelism of 4. This can be reduced if some tests are failing due to network-related issues, or increased if possible, to reduce the running time of the tests. Prefix the make command with TEST_PARALLELISM, as in the following example, to configure this.

$ TEST_PARALLELISM=8 make testacc

Depending on the Fastly account used, some features may not be enabled (e.g. Platform TLS). This may result in some tests failing, potentially with 403 Unauthorised errors, when the full test suite is being run. Check the Fastly API documentation to confirm if the failing tests use features in Limited Availability or only available to certain customers. If this is the case, either use the TESTARGS regular expressions described above, or temporarily add t.SkipNow() to the top of any tests that should be excluded.

Building The Documentation

The documentation is built from components (go templates) stored in the templates folder. Building the documentation copies the full markdown into the docs folder, ready for deployment to Hashicorp.

NOTE: you'll need the tfplugindocs tool for generating the Markdown to be deployed to Hashicorp. For more information on generating documentation, refer to https://www.terraform.io/docs/registry/providers/docs.html

  • To validate the /template directory structure:
make validate-docs
  • To build the /docs documentation Markdown files:
make generate-docs

Contributing

Refer to CONTRIBUTING.md

More Repositories

1

pushpin

A proxy server for adding push to your API, used at the core of Fastly's Fanout service
Rust
3,639
star
2

ftw

Framework for Testing WAFs (FTW!)
Python
264
star
3

js-compute-runtime

JavaScript SDK and runtime for building Fastly Compute applications
C++
197
star
4

go-fastly

A Fastly API client for Go
Go
154
star
5

fastly-rails

Please visit https://github.com/fastly/fastly-ruby.
Ruby
143
star
6

Viceroy

Viceroy provides local testing for developers working with Compute.
Rust
141
star
7

cli

Build, deploy and configure Fastly services from your terminal
Go
139
star
8

fastly-magento2

Module for integrating Fastly CDN with Magento 2 installations
PHP
125
star
9

Avalanche

Random, repeatable network fault injection
Python
104
star
10

fastly-exporter

A Prometheus exporter for the Fastly Real-time Analytics API
Go
97
star
11

fastly-ruby

A Fastly API client for Ruby
Ruby
91
star
12

compute-sdk-go

Go SDK for building Fastly Compute applications
Go
78
star
13

fastly-py

A Fastly API client for Python
Python
76
star
14

sidekiq-prometheus

Public repository with Prometheus instrumentation for Sidekiq
Ruby
74
star
15

wafefficacy

Measures the effectiveness of your Web Application Firewall (WAF)
Go
73
star
16

next-compute-js

Run Next.js on Fastly Compute
TypeScript
73
star
17

WordPress-Plugin

The Official Fastly WordPress Plugin
JavaScript
59
star
18

uslab

Lock-free slab allocator / freelist.
C
57
star
19

compute-starter-kit-rust-default

Default package template for Rust based Compute projects
Rust
50
star
20

go-utils

utils for go
Go
44
star
21

insights.js

Real user monitoring of network timing signals using the Open Insights framework
TypeScript
40
star
22

compute-actions

GitHub Actions for building on Fastly Compute.
JavaScript
39
star
23

compute-rust-auth

Authentication at Fastly's edge, using OAuth 2.0, OpenID Connect, and Fastly Compute.
Rust
36
star
24

waf_testbed

Chef Cookbook which provisions apache+mod_security+owasp-crs
HTML
35
star
25

fastlyctl

A CLI for managing Fastly configurations
Ruby
35
star
26

fastly2git

Create a git repository from Fastly service generated VCL
Ruby
32
star
27

token-functions

Example implementations for Fastly's token validation
Java
29
star
28

terrarium-rust-guest

The "http_guest" crate used by Fastly Labs Terrarium https://wasm.fastlylabs.com/
Rust
29
star
29

performance-observer-polyfill

🔎 Polyfill for the PerformanceObserver API
TypeScript
29
star
30

terrarium-templates

Template and example projects for Fastly Labs Terrarium https://wasm.fastlylabs.com
C
27
star
31

waflyctl

Fastly WAF CLI
Go
27
star
32

fastly-magento

Magento Extension for working with the Fastly Content Delivery Network
PHP
26
star
33

compute-js-static-publish

Static Publisher for Fastly Compute JavaScript
TypeScript
26
star
34

libvmod-urlcode

urlencode/urldecode functions vmod
C
24
star
35

fastly-php

A Fastly API client for PHP
PHP
24
star
36

compute-starter-kit-rust-static-content

Static content starter kit for Rust based Fastly Compute projects. Speed up your websites with a Compute application serving content from a static bucket, redirects, security and performance headers, and a 404 page.
Rust
23
star
37

log4j_interpreter

A Rust library for evaluating log4j substitution queries in order to determine whether or not malicious queries may exist.
Rust
22
star
38

expressly

Express style router for Fastly Compute
TypeScript
22
star
39

vcl-json-generate

A VCL module that allows you to generate JSON dynamically on the edge
VCL
21
star
40

compute-starter-kit-assemblyscript-default

Default package template for AssemblyScript based Fastly Compute projects
TypeScript
20
star
41

remix-compute-js

Remix for Fastly Compute JavaScript
TypeScript
19
star
42

compute-starter-kit-javascript-default

Default package template for JavaScript based Fastly Compute projects
JavaScript
19
star
43

fanout-compute-js-demo

Fanout Fastly Compute JavaScript demo
TypeScript
17
star
44

cd-with-terraform

Practical exercises for InfoQ "Continuous deployment with Terraform" workshop
HCL
16
star
45

fastly-perl

A Fastly API client for Perl
Perl
16
star
46

mruby-optparse

Port of Ruby's OptionParser to mruby
Ruby
16
star
47

http-compute-js

Node.js-compatible request and response objects
TypeScript
16
star
48

compute-at-edge-abi

Interface definitions for the Compute@Edge platform in witx.
Rust
15
star
49

compute-js-opentelemetry

An implementation of OpenTelemetry for Fastly Compute
TypeScript
14
star
50

blockbuster

VCR cassette manager
Ruby
13
star
51

demo-fiddle-ci

Using Fastly Fiddle to enable CI testing of Fastly services
JavaScript
13
star
52

secretd

Secret storage server
Go
12
star
53

fastly-rust

A Rust Fastly API client library.
Rust
12
star
54

heroku-fastly

Heroku CLI plugin for Fastly
JavaScript
10
star
55

go-mtr

go wrapped mtr --raw
Go
10
star
56

fastly-js

A Fastly API client for JavaScript
JavaScript
10
star
57

terrctl

A command-line client for Fastly Terrarium. https://wasm.fastlylabs.com
Go
10
star
58

compute-starter-kit-javascript-openapi-validation

OpenAPI Validation Starter Kit for Fastly Compute (JavaScript)
JavaScript
10
star
59

http_connection_monitor

Monitors your outbound HTTP requests for number of requests made over a persistent connection.
Ruby
9
star
60

security-use-cases

Placeholder for security related use cases and demos
HCL
9
star
61

fastly-test-blog

Test application for learning Fastly's UI
Ruby
9
star
62

uap-vcl

uap-vcl is a VCL module which parses a User-Agent string
VCL
8
star
63

sigsci-splunk-app

Splunk app for Fastly (Signal Sciences)
Python
8
star
64

librip

Librip is a minimal-overhead API for instruction-level tracing in highly concurrent software.
Python
8
star
65

fastly_nsq

Public repository with a convenience adapter & testing classes for apps talking to NSQ
Ruby
8
star
66

vscode-fastly-vcl

A Visual Studio Code extension which adds syntax highlighting for Fastly Varnish Configuration Language (VCL) files.
TypeScript
8
star
67

altitude-nyc-abcd-workshop

Practical exercises for "ABCD: Always be continuously deploying" workshop at Altitude NYC 2017
HCL
7
star
68

compute-starter-kit-typescript

A simple Fastly starter kit for Typescript
TypeScript
6
star
69

ember-anti-clickjacking

Anti-Clickjacking in Ember
JavaScript
6
star
70

compute-starter-kit-rust-beacon-termination

Beacon Termination package template for Rust based Fastly Compute projects.
Rust
6
star
71

Raikkonen

Räikkönen tests races.
C
6
star
72

js-compute-testing

Write JavaScript tests from Node.js, against a local or remote Fastly Compute application
TypeScript
6
star
73

diff-service

An experiment in powering Edge diff functionality from Google Cloud Functions
JavaScript
6
star
74

jlog-go

Go bindings for jlog
Go
6
star
75

vmdebootstrap

wrapper around debootstrap to create virtual machine disk images
Python
6
star
76

compute-starter-kit-go-default

Default package template for Go based Fastly Compute projects
Go
5
star
77

compute-hibp-filter

Fastly Compute enrichment to detect compromised passwords
Go
5
star
78

fastly-blocklist

Configure request blocking for a Fastly service.
Python
5
star
79

altitude-ci-cd-workshop

Practical exercises for "Building a continuous deployment pipeline" workshop at Altitude 2017
HCL
5
star
80

dnstap-utils

dnstap utilities implemented in Rust
Rust
5
star
81

compute-starter-kit-javascript-queue

Queuing package template for JavaScript based Fastly Compute projects. Park your users in a virtual queue to reduce the demand on your origins during peak times.
JavaScript
5
star
82

compute-starter-kit-rust-websockets

WebSockets starter kit for Fastly Compute (Rust)
Rust
4
star
83

altitude-LON-logging-workshop

Fiddle links & exercises for "Building an internal analytics platform with real-time logs" workshop at Altitude LON 2019
4
star
84

irc2slack

Python
4
star
85

Varnish-API

Perl extension for accessing varnish stats and logs
C
4
star
86

security-solutions-visualization-waf-bigquery-looker

4
star
87

compute-ll-hls

Fastly Compute application for LL-HLS playlist manipulation.
Rust
4
star
88

compute-starter-kit-javascript-empty

Empty package template for JavaScript based Fastly Compute projects
JavaScript
4
star
89

serve-vercel-build-output

A runtime environment that executes output that targets the Vercel Build Output API on Fastly Compute
TypeScript
4
star
90

compute-starter-kit-rust-empty

Empty package template for Rust based Fastly Compute projects
Rust
3
star
91

fastly-lem

Automate the deployment of Live Event Monitoring
Go
3
star
92

wasm-workshop-altitude-ldn-2019

Workshop materials for the "WebAssembly outside the web" workshop
Rust
3
star
93

compute-rust-sentry

Send error reports from Rust Fastly Compute services to Sentry.
Rust
3
star
94

compute-starter-kit-javascript-expressly

A lightweight starter kit for Fastly Compute, demonstrating the expressly framework.
JavaScript
3
star
95

fastly-template-rust-nel

Package template for a Rust based Network Error Logging Fastly Compute service
Rust
3
star
96

next-compute-js-server

Implementation of Next.js Server class for Fastly Compute JavaScript
TypeScript
3
star
97

compute-segmented-caching

Segmented Caching as a Fastly Compute app
Rust
3
star
98

homebrew-tap

Homebrew Formulae
Ruby
3
star
99

sse-demo

A demo of a streaming data use case for Fastly
CSS
3
star
100

compute-js-apiclarity

compute-js-apiclarity
JavaScript
3
star