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

How to develop a custom Terraform provider@Merp...

Keke
March 19, 2020

How to develop a custom Terraform provider@Merpay SRE Tech Talk

Keke

March 19, 2020
Tweet

More Decks by Keke

Other Decks in Technology

Transcript

  1. 1. What’s custom Terraform provider 2. How to develop your

    first Terraform provider 3. Making it better “Content”
  2. Whoever listens this presentation can 1. Understand how the Terraform

    is using Terraform provider to manage resources 2. Develop custom Terraform provider “Goal”
  3. Terraform Terraform Core Terraform Provider When $ terraform apply… Terraform

    Provisioner “Basic logic” “Logic between the service and how to manage” “Logic of how to provision”
  4. Example: Terraform Provider ɾNull resource ɾSecret ɾ… 3 kinds of

    Terraform provider 1. Built-in provider ɾterraform-provider-aws ɾterraform-provider-google ɾterraform-provider-azure ɾterraform-provider-datadog ɾ… 2. Distributed provider by Hashicorp Needs review by Hashicorp
  5. Example: Terraform Provider ɾNull resource ɾSecret ɾ… 3 kinds of

    Terraform provider 1. Built-in provider ɾterraform-provider-aws ɾterraform-provider-google ɾterraform-provider-azure ɾterraform-provider-datadog ɾ… 2. Distributed provider by Hashicorp 3. Third party provider ɾterraform-provider-keke ɾ… ɾterraform-provider-xxxx Needs review by Hashicorp You can built your own one!!! = Custom Terraform Provider
  6. Terraform Terraform Core When $ terraform apply… 1.Request PRC 2.

    Actual PRC Implemented in the Provider 3. Result 4. Store 5. Retrieve 6. Result tfstate Terraform Provisioner Terraform Provider
  7. When $ terraform apply… Any API Terraform Terraform Core Terraform

    Provider 1.Request PRC 2. Actual PRC Implemented in the Provider 3. Result 4. Store 5. Retrieve 6. Result tfstate Terraform Provisioner Custom
  8. Whoever listens this presentation can 1. Understand how the Terraform

    is using Terraform provider to manage resources 2. Develop custom Terraform provider “Goal”
  9. 1. One provider should focus on one service A custom

    provider (terraform-provider-god) API A API B API C
  10. A custom provider (terraform-provider-god) API A API B API C

    1. One provider should focus on one service
  11. A custom provider (terraform-provider-api-a) API A API B API C

    A custom provider (terraform-provider-api-b) A custom provider (terraform-provider-api-c) 1. One provider should focus on one service
  12. 2. Seperate API Client package A custom provider (terraform-provider-god) API

    B API Client package No unit tests or PRC logic in the provider
  13. 1. One resource should focus on one object in API

    A resource API for Object A API for Object B API for Object C .tf
  14. 1. One resource should focus on one object in API

    A resource API for Object A API for Object B API for Object C .tf
  15. 1. One resource should focus on one object in API

    resource_a .tf API for Object A API for Object B API for Object C resource_b .tf resource_c .tf
  16. 2. Follow schema to the actual API object API for

    xxxxxx { “name”: “xxxx”, “email”: “xxxx” } API field
  17. “All providers are same directory structure” ← Define this custom

    Terraform provider so that Terraform core can import ← Define the provider ← Define the resource
  18. “Minimum provider: build & use” 1. Run $ go build

    2. Create tf file for your provider 3. Run terraform init
  19. “Minimum provider: build & use” 1. Run $ go build

    2. Create tf file for your provider 3. Run terraform init
  20. “Minimum provider: build & use” 1. Run $ go build

    2. Create tf file for your provider 3. Run terraform init
  21. “Minimum provider: build & use” 1. Run $ go build

    2. Create tf file for your provider 3. Run terraform init
  22. “Minimum provider: build & use” 1. Run $ go build

    2. Create tf file for your provider 3. Run terraform init
  23. Whoever listens this presentation can 1. Understand how the Terraform

    is using Terraform provider to manage resources 2. Develop custom Terraform provider “Goal”