Building a continuous deployment pipeline
Patrick HamannWeb Performance Engineer | Fastly
Clint ShryockSoftware Engineer | Hashicorp
• Configuration drift
• Manual deployment
• Not reproducible
• Can’t see outcomes ahead of time
• Changes can’t be traced
• Can’t easily rollback state
The problem?
• Services can be easily reproduced
• Services are consistent
• Processes are repeatable & predictable
• Configuration is continuously tested
• Visibility and actionability
The goal
• Declare our service configuration in code
• Configuration is maintained in VCS
• Small changes get tested and continuously integrated
• Deployment is automated on every change
How?
• How to apply changes to your services via the CLI
• What is Terraform?
• How we can define our Fastly configuration as code
• How to use CI to automate the application of your changes
• How to manage multiple environments*
What we'll learn today
• Find the active version of service
• Clone the active version
• Delete all the existing VCL files
• Upload the new VCL files
• Define the main VCL
• Validate the newly cloned version
• Activate version
Manually deploying a new version
Find active version
curl https://api.fastly.com/service/<SERVICE_ID>/version -H 'Fastly-Key: <API_TOKEN>'
< HTTP/1.1 200 OK< Status: 200 OK< Content-Type: application/json
{ "testing": false, "locked": true, "number": 88, "active": true, "service_id": "5DYjgYJ8SeELWdjbdJtZdD", "staging": false, "created_at": "2017-06-06T16:28:31+00:00", "deleted_at": null, "comment": "", "updated_at": "2017-06-06T16:28:41+00:00", "deployed": false}
Clone active version
curl https://api.fastly.com/service/<SERVICE_ID>/version -H 'Fastly-Key: <API_TOKEN>'
< HTTP/1.1 200 OK< Status: 200 OK< Content-Type: application/json
{ "testing": false, "locked": true, "number": 88, "active": true, "service_id": "5DYjgYJ8SeELWdjbdJtZdD", "staging": false, "created_at": "2017-06-06T16:28:31+00:00", "deleted_at": null, "comment": "", "updated_at": "2017-06-06T16:28:41+00:00", "deployed": false}
• Unify the view of resources using infrastructure as code
• Support the modern data center (IaaS, PaaS, SaaS)
• Expose a way to safely and predictably change infrastructure
• Provide a workflow that is technology agnostic
• Manage anything with an API
Terraform's Goals
• Provides a high-level abstraction of infrastructure (IaC)
• Allows for composition and combination
• Supports parallel management of resources (graph, fast)
• Separates planning from execution (dry-run)
Terraform vs. Other Tools
• Human-readable configuration (HCL) is designed for human
consumption so users can quickly interpret and understand their
infrastructure configuration.
• HCL includes a full JSON parser for machine-generated
configurations.
Infrastructure as Code (Terraform)
variable "fastly_api_token" {}
provider "fastly" { api_key = "${var.fastly_api_token}"}
resource "fastly_service_v1" "www-fastly-com" { name = "www.fastly.com"
domain { name = "www.fastly.com" comment = "Production service" }}
main.tf
variable "fastly_api_token" {}
provider "fastly" { api_key = "${var.fastly_api_token}"}
resource "fastly_service_v1" "www-fastly-com" { name = "www.fastly.com"
domain { name = "www.fastly.com" comment = "Production service" }}
main.tf
variable "fastly_api_token" {}
provider "fastly" { api_key = "${var.fastly_api_token}"}
resource "fastly_service_v1" "www-fastly-com" { name = "www.fastly.com"
domain { name = "www.fastly.com" comment = "Production service" }}
main.tf
variable "fastly_api_token" {}
provider "fastly" { api_key = "${var.fastly_api_token}"}
resource "fastly_service_v1" "www-fastly-com" { name = "www.fastly.com"
domain { name = "www.fastly.com" comment = "Production service" }}
main.tf
Terminal
bit.ly/altitude-abcd
$ ssh -A [email protected]
$ password: altitude2017
$ cd workshop
Terminal