Upgrade to Pro — share decks privately, control downloads, hide ads and more …

TerraformExtensibleProviderArchitecture.pdf

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for Clint Shryock Clint Shryock
October 01, 2017
38

 TerraformExtensibleProviderArchitecture.pdf

Avatar for Clint Shryock

Clint Shryock

October 01, 2017
Tweet

Transcript

  1. Copyright © 2017 HashiCorp Terraform ▪ Provision, secure, connect, and

    run any infrastructure for any application !5 HashiCorp’s Mission
  2. 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…
  3. 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
  4. 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
  5. 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
  6. Copyright © 2017 HashiCorp Terraform ▪ Configuration, State ▪ Interpolation,

    translating configuration into a Dependency Graph ▪ Discovery, communication with Plugins ▪ plan and apply !12 Core Responsibilities
  7. Copyright © 2017 HashiCorp Terraform !14 Core Responsibilities Core Providers

    Upstream APIs Plugins Diff() Apply() Refresh() Terraform
  8. 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…
  9. 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
  10. Copyright © 2017 HashiCorp Provider Architecture !20 Provider Architecture Core

    Providers Upstream APIs Plugins Diff() Apply() Refresh() Terraform
  11. Copyright © 2017 HashiCorp Provider Architecture !21 Provider Architecture Core

    Providers Upstream APIs Plugins Diff() Apply() Refresh() Create() Read() Update() Delete() Terraform
  12. Copyright © 2017 HashiCorp Provider Architecture ▪ Providers are binary

    plugins ▪ Automatically discovered by Core ▪ Uses terraform/helper/schema framework to define lifecycle !22 Provider Architecture
  13. Copyright © 2017 HashiCorp Provider Architecture !23 Provider layout -

    terraform-provider-supercloud/ ⌙ main.go ⌙ provider.go ⌙ resource_supercloud_instance.go ⌙ data_source_supercloud_instance.go ⌙ [...]
  14. 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(), }, }, } }
  15. 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, } }
  16. 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, }, }, } }
  17. 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() }, }) }
  18. 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
  19. 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
  20. 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
  21. Copyright © 2017 HashiCorp Demo ▪ Provision, secure, connect, and

    run any infrastructure for any application !36 HashiCorp’s Mission
  22. Copyright © 2017 HashiCorp Demo ▪ Setup a Heroku app

    ▪ Setup a Lambda function ▪ Get them to talk? !37 What shall we do..
  23. 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
  24. 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..