2 1 0 Custom Terraform Provider: Setup Skeleton (Go)
Andrew defines the Provider object in Go language.
Over the course of Week 2, Andrew develops the custom provider plugin in Golang. In this episode, we are setting up the skeleton to give shape to the provider. The Provider is instantiated with three attributes which are required to interact with the TerraTowns service.
Code Notes
A provider is a Terraform entity that interacts with a particular cloud infrastructure or service. In Andrews' Bootcamp, the provider will interact with the TerraTowns website using the AWS cloud services (
S3 bucket
andCloudFront
).A package in go is a collection of source files in the same directory that are compiled together.
main.go
: a conventional filename used as the entry point of a Go application. Themain.go
file typically contains the main function, which is the starting point for the execution of the program. If you are familiar with Java, this is pretty much the Go equivalent of Java'spublic static void main(String[] args)
.Lines 13-15 inside
main()
: are the boilerplate code provided by Terraform for creating a Terraform custom provider plugin in Go. If it doesn't make sense to you, just know that it just has to be there, otherwise the Provider won't be created :P
ResourcesMap
, line 3: theResourcesMap
block inside&schema.Provider{}
will have to contain the blueprint of the resources theProvider
can provision when instantiated. More on that later in 2.3.0.Schema
, lines 25-43: is the blueprint of theProvider()
entity. When declaring a provider in a.tf
file, you will have to provide the values for the Provider's attributes (configuration options). In our plugin, the Provider entity comes with three attributes:endpoint
,token
, anduser_uuid
. They are required when instantiating a provider in order for it to interact with TerraTowns (the cloud service).endpoint
: terraform should know where the service is (the website address, or API in other words). The value for this will eventually be TerraTowns' domain name.Your credentials information
user_uuid
: also unique to your account. In combination with thetoken
, TerraTowns authenticates you then processes your http request.
schema.Schema.attribute.Type
: defines the data type of the value you will provide for the attribute. They are categorised into two groups:Primitive typesAggregate typesTypeBool
TypeInt
TypeFloat
TypeString
Date & Time data
TypeMap
TypeType
TypeSet
This marks the end of the tutorial, and also the completion of the Provider skeleton. It now does have a shape - an object with three attributes. As there is no actions (functions) defined, however, it can't really do anything. If we were to compare this to web development, it's like we just finished writing an html file without any backend functions. So we can view the page, but cannot interact with it.
Resources
Development workflow documentation: 2.1.0 Setup Skeleton for Custom Terraform Provider
Terraform
Go
Last updated