The Terraform Provider for Octopus Deploy is under active development and undergoing migration from Terraform SDK to Terraform Plugin Framework. Its functionality can and will change; it is a v0.* product until its robustness can be assured. Please be aware that types like resources can and will be modified over time. It is strongly recommended to validate
and plan
configuration prior to committing changes via apply
.
This repository contains the source code for the Terraform Provider for Octopus Deploy. It supports provisioning/configuring of Octopus Deploy instances via Terraform. Documentation and guides for using this provider are located on the Terraform Registry: Documentation.
The Terraform Provider for Octopus Deploy is available via the Terraform Registry: OctopusDeployLabs/octopusdeploy. To install this provider, copy and paste this code into your Terraform configuration:
terraform {
required_providers {
octopusdeploy = {
source = "OctopusDeployLabs/octopusdeploy"
version = "version-number" # example: 0.21.1
}
}
}
provider "octopusdeploy" {
# configuration options
address = "https://octopus.example.com" # (required; string) the service endpoint of the Octopus REST API
api_key = "API-XXXXXXXXXXXXX" # (required; string) the API key to use with the Octopus REST API
space_id = "Spaces-1" # (optional; string) the space ID in Octopus Deploy
}
If space_id
is not specified the Terraform Provider for Octopus Deploy will assume the default space.
You can provide your Octopus Server configuration via the OCTOPUS_URL
and OCTOPUS_APIKEY
environment variables, representing your Octopus Server address and API Key, respectively.
provider "octopusdeploy" {}
Run terraform init
to initialize this provider and enable resource management.
A build of this Terraform Provider can be created using the Makefile provided in the source:
$ make
This will generate a binary that will be installed to the local plugins folder. Once installed, the provider may be used through the following configuration:
terraform {
required_providers {
octopusdeploy = {
source = "octopus.com/com/octopusdeploy"
version = "0.7.63"
}
}
}
provider "octopusdeploy" {
address = # address
api_key = # API key
space_id = # space ID
}
After the provider has been built and saved to the local plugins folder, it may be used after initialization:
$ terraform init
Terraform will scan the local plugins folder directory structure (first) to qualify the source name provided in your Terraform configuration. If it can resolve this name then the local copy will be initialized for use with Terraform. Otherwise, it will scan the Terraform Registry.
version
number specified in your Terraform configuration MUST match the version number specified in the Makefile. Futhermore, this version MUST either be incremented for each local re-build; otherwise, Terraform will use the cached version of the provider in the .terraform
folder. Alternatively, you can simply delete the folder and re-run the terraform init
command.
Important
We're currently migrating all resources and data sources from Terraform SDK to Terraform Plugin Framework.
All new resources should be created using Framework, in the octopusdeploy-framework
directory. A GitHub action will detect and prevent any new additions to the old octopusdeploy
SDK directory.
When modifying an existing SDK resource, we strongly recommend migrating it to Framework first - but this might not always be feasible. We'll judge it on a case-by-case basis.
All new resources need an acceptance test that will ensure the lifecycle of the resource works correctly this includes Create, Read, Update and Delete.
Please avoid using blocks: these are mainly used for backwards compatability of resources migrated from SDK. Use nested attributes instead.
If you want to debug the provider follow these steps!
- Terraform provider is configured to use the local version e.g.
"octopus.com/com/octopusdeploy"
terraform {
required_providers {
octopusdeploy = {
source = "octopus.com/com/octopusdeploy"
version = "0.7.63"
}
}
}
- Optional - Install delve https://github.com/go-delve/delve
- Debug the provided run configuration
Run provider
- This will run the provider with the-debug
flag set to true. - Export the environment variable that the running provider logs out, it will look something like this:
TF_REATTACH_PROVIDERS='{"octopus.com/com/octopusdeploy":{"Protocol":"grpc","ProtocolVersion":5,"Pid":37485,"Test":true,"Addr":{"Network":"unix","String":"/var/folders/pq/_cv_xzg97ts8t2tq25d_43wr0000gn/T/plugin447612806"}}}'
- In the same terminal session where you exported the environment variable, execute the Terraform commands you want to debug.
- Add your breakpoints, this can be done by adding
runtime.Breakpoint()
lines to where you want the code to break. - Run
dlv debug . -- --debug
in the root folder of the project (same directory wheremain.go
lives). - The debugger will start and wait, type
continue
in the terminal to get it to start the provider. - Export the environment variable that the running provider logs out, it will look something like this:
TF_REATTACH_PROVIDERS='{"octopus.com/com/octopusdeploy":{"Protocol":"grpc","ProtocolVersion":5,"Pid":37485,"Test":true,"Addr":{"Network":"unix","String":"/var/folders/pq/_cv_xzg97ts8t2tq25d_43wr0000gn/T/plugin447612806"}}}'
- In the same terminal session where you exported the environment variable, execute the Terraform commands you want to debug.
Documentation is auto-generated by the tfplugindocs CLI. To generate the documentation, run the following command:
$ make docs
or
go generate main.go
Contributions are welcome! β€οΈ Please read our Contributing Guide for information about how to get involved in this project.