Requirements
Building The Provider
- Clone the repository
- Enter the repository directory
- Build the provider using the
make install
command:
$ make install
Result:
go build -o terraform-provider-gophers
mkdir -p ~/.terraform.d/plugins/terraform.local/local/gophers/0.0.1/darwin_amd64
mv terraform-provider-gophers ~/.terraform.d/plugins/terraform.local/local/gophers/0.0.1/darwin_amd64
Using the provider
- Define the provider you want to use
The provider is defined in examples/provider.tf
file:
terraform {
required_providers {
gophers = {
source = "terraform.local/local/gophers"
version = "0.0.1"
}
}
}
- Define the datasources
We defined several datasources in examples/data.f
file:
# List of available gophers
data "gophers" "my_gophers" {
}
output "return_gophers" {
value = length(data.gophers.my_gophers.gophers) >= 1
}
# Display information about a Gopher
data "gophers_gopher" "moultipass" {
name = "5th-element"
}
- Define resources
We defined a resource in examples/resource.f
file:
resource "gophers_gopher" "x-files" {
name = "x-files"
displayname = "X Files"
url = "https://raw.githubusercontent.com/scraly/gophers/main/x-files.png"
}
- Init Terraform
rm .terraform.lock.hcl && terraform init
- Apply the configuration you defined
terraform apply
- destroy datasource and resources you created
terraform destroy
Developing the Provider
If you wish to work on the provider, you'll first need Go installed on your machine (see Requirements above).
To compile the provider, run go install
. This will build the provider and put the provider binary in the $GOPATH/bin
directory.
To generate or update documentation, run go generate
.
In order to run the full suite of Acceptance tests, run make testacc
.
Note: Acceptance tests create real resources, and often cost money to run.
$ make testacc
Documentation
When the plugin will be relkeased, add the following content in the main.tf
file:
// Run the docs generation tool, check its repository for more information on how it works and how docs
// can be customized.
//go:generate go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs
And execute the go generate
command to generate the documentation:
go generate