2 4 0 Custom Terraform Provider: Resource and CRUD (Go)
This section walks through the Resource block and the logic flow of the CRUD functions in the
main.go
file in detail. As the code is quite long, each function is covered in its own subpage.
Code Notes
Andrew finishes the development of the
main.go
file by flashing out the internal logic ofResource()
and the CRUD functions. In this episode onwards, we'll be able to actually use the features we developed here in other terraform files.In this page, we will look into
Resource()
only.
Lines 23-50 Schema
Line 16: The
Resource()
function returns a pointer (*) to theschema.Resource
object.The
*
operator is used to access the value stored at a particular address.pointer argument
: it points to the actual value. So if the value is updated, your functions are working with the updated value.non-pointer argument
: it is a copy of the argument. The copy’s value will stay the same even after the argument’s current value is updated.
Line 22: inside the function, a variable
resource
is declared, which isschema.Resource
object that has 4 CRUD functions and a map of Schema with 5 attributes.These CRUD functions will allow us to make http requests to the API endpoints of the chosen cloud service. These requests contain instructions for provisioning cloud resources.
A map is a data type in Go which is equivalent to hash table, or a collection of key:value pairs.
Line 23-47: each key comes with 3 attributes (
Type
,Required
,Description
) which define the properties of the value that can be assigned to the key. All the attributes are the string type (schema.TypeString
) except for the keycontent_version
(schema.TypeInt
).
Resources
Development workflow documentation: 2.4.0 CRUD Resource
Last updated