Share
Embed
Transcript
41 slides
-
Copyright © 2017 HashiCorp Terraform ▪ Provision, secure, connect, and
run any infrastructure for any application !5 HashiCorp’s Mission -
Copyright © 2017 HashiCorp Terraform ▪ Write, Plan, and Create
Infrastructure as Code ▪ Provision on any infrastructure / service / cloud !6 Goals Amazon GitHub DigitalOcean Fastly Microsoft Azure Packet Heroku DNSimple Librato Google Cloud Docker VMWare Sphere Many more… -
Copyright © 2017 HashiCorp Terraform ▪ Unified view of infrastructure
▪ Easily compose multiple tiers/services (IaaS to PaaS to SaaS) ▪ Safely change/iterate infrastructure over time ▪ Manage anything with an API ▪ One workflow, many clouds !7 Write, Plan, and Create Infrastructure as Code -
Copyright © 2017 HashiCorp Terraform ▪ Open Source! ▪ HCL:
human readable, machine editable JSON ▪ Dependency graph ▪ terraform plan shows you changes ▪ terraform apply executes those changes in order ▪ Collaboration, history, audit trail [Enterprise] !8 Key Features -
Copyright © 2017 HashiCorp Terraform ▪ Single binary written in
Go, support for *nix, Windows ▪ Provider/Provisioner Plugins over RPC ▪ Split into Terraform Core and Terraform Providers (as of v0.10.0) ▪ Directed Acyclic Graph (DAG) !10 Architecture -
Copyright © 2017 HashiCorp Terraform ▪ Configuration, State ▪ Interpolation,
translating configuration into a Dependency Graph ▪ Discovery, communication with Plugins ▪ plan and apply !12 Core Responsibilities -
Copyright © 2017 HashiCorp Terraform !13 Core Responsibilities Core Providers
Upstream APIs Plugins Terraform -
Copyright © 2017 HashiCorp Terraform !14 Core Responsibilities Core Providers
Upstream APIs Plugins Diff() Apply() Refresh() Terraform -
Copyright © 2017 HashiCorp Terraform !15 Core Responsibilities dag config
terraform reads makes -
Copyright © 2017 HashiCorp Provider Architecture ▪ Write, Plan, and
Create Infrastructure as Code ▪ Provision on any infrastructure / service / cloud !18 Goals Amazon GitHub DigitalOcean Fastly Microsoft Azure Packet Heroku DNSimple Librato Google Cloud Docker VMWare Sphere Many more… -
Copyright © 2017 HashiCorp Provider Architecture ▪ Detailed knowledge of
the specific Provider (API, SDK, Authentication) ▪ Define Resources that map to specific Services ▪ Resource: abstraction/lifecycle management for cloud units/ resources !19 Provider Responsibilities -
Copyright © 2017 HashiCorp Provider Architecture !20 Provider Architecture Core
Providers Upstream APIs Plugins Diff() Apply() Refresh() Terraform -
Copyright © 2017 HashiCorp Provider Architecture !21 Provider Architecture Core
Providers Upstream APIs Plugins Diff() Apply() Refresh() Create() Read() Update() Delete() Terraform -
Copyright © 2017 HashiCorp Provider Architecture ▪ Providers are binary
plugins ▪ Automatically discovered by Core ▪ Uses terraform/helper/schema framework to define lifecycle !22 Provider Architecture -
Copyright © 2017 HashiCorp Provider Architecture !23 Provider layout -
terraform-provider-supercloud/ ⌙ main.go ⌙ provider.go ⌙ resource_supercloud_instance.go ⌙ data_source_supercloud_instance.go ⌙ [...] -
Copyright © 2017 HashiCorp Provider Architecture !24 Provider layout: provider.go
package supercloud import ( "github.com/hashicorp/terraform/helper/schema" ) func Provider() *schema.Provider { return &schema.Provider{ Schema: map[string]*schema.Schema{ "access_key": { Type: schema.TypeString, Optional: true, Description: descriptions["access_key"], }, ResourcesMap: map[string]*schema.Resource{ "sc_cloud_instance": resourceSupercloudInstance(), }, }, } } -
Copyright © 2017 HashiCorp Provider Architecture !25 Provider layout: resource_supercloud_instance.go
package supercloud import ( "github.com/hashicorp/terraform/helper/schema" "github.com/supercloud/supercloud-sdk-go/supercloud" ) func resourceSupercloudInstance() *schema.Resource { return &schema.Resource{ Create: resourceSupercloudInstanceCreate, Read: resourceSupercloudInstanceRead, Update: resourceSupercloudInstanceUpdate, Delete: resourceSupercloudInstanceDelete, } } -
Copyright © 2017 HashiCorp Provider Architecture !26 Provider layout: data_source_supercloud_instance.go
package supercloud import ( "github.com/aws/aws-sdk-go/aws" "github.com/hashicorp/terraform/helper/schema" ) func dataSourceSupercloudInstance() *schema.Resource { return &schema.Resource{ Read: dataSourceSupercloudInstanceRead, Schema: map[string]*schema.Schema{ "id": { Type: schema.TypeString, }, }, } } -
Copyright © 2017 HashiCorp Provider Architecture !27 Provider layout: main.go
package main import ( "github.com/hashicorp/terraform/plugin" "github.com/hashicorp/terraform/terraform" ) func main() { plugin.Serve(&plugin.ServeOpts{ ProviderFunc: func() terraform.ResourceProvider { return supercloud.Provider() }, }) } -
Copyright © 2017 HashiCorp v0.10.0 !29 Recall: Terraform/Provider architecture Core
Providers Upstream APIs Plugins Terraform -
Copyright © 2017 HashiCorp v0.10.0 ▪ Everything in a single
repo ▪ Tightly coupled ▪ Releases every ~2 weeks (v0.6.16, v0.7.13, v0.9.11) !31 Challenges -
Copyright © 2017 HashiCorp v0.10.0 !32 The Core/Provider split Core
Providers Upstream APIs Plugins Terraform -
Copyright © 2017 HashiCorp v0.10.0 ▪ Separate core and provider
versioning and release ▪ Enable the Provider community ▪ Per-project plugin management, version locking ▪ Minimal change to users !33 The Core/Provider split: Benefits -
Copyright © 2017 HashiCorp Extending Terraform ▪ Users of Terraform
are able to write new plugins in order to support new functionality in Terraform ▪ If it has an API, it can (probably) be managed by Terraform !34 Plugins -
Copyright © 2017 HashiCorp Demo ▪ Provision, secure, connect, and
run any infrastructure for any application !36 HashiCorp’s Mission -
Copyright © 2017 HashiCorp Demo ▪ Setup a Heroku app
▪ Setup a Lambda function ▪ Get them to talk? !37 What shall we do.. -
Copyright © 2017 HashiCorp Demo ▪ I already wrote the
Heroku app ▪ I already wrote the Lambda function ▪ Other things were already written (I’ll explain soon enough) ▪ Code is proof of concept, not production ready ▪ Live demos always contain dragons !38 DISCLAIMERS -
Copyright © 2017 HashiCorp Demo ▪ Setup a Heroku app
▪ Setup a Lambda function ▪ Wrote a new Provider ▪ With 2 data sources ▪ Extended an existing Provider ▪ Added a new resource ▪ Installed locally ▪ Integrated and clicked a physical button (hopefully it worked) !39 What did we do..