forked from OpenNebula/terraform-provider-opennebula
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from true/improve-contributing-guidelines
Use dev_override to allow for easier local development environment
- Loading branch information
Showing
2 changed files
with
46 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,33 +9,36 @@ Thanks for getting involved in the Terraform Provider for OpenNebula. Here are a | |
* [Install Go](https://go.dev/doc/install) | ||
* [Install Terraform](https://learn.hashicorp.com/terraform/getting-started/install) | ||
|
||
### Building from sources | ||
### Local development of the provider | ||
|
||
```shell | ||
export tf_arch=darwin_arm64 | ||
export tf_one_version=0.0.1 | ||
To develop and use this provider locally, you can leverage th [`dev_override`](https://developer.hashicorp.com/terraform/cli/config/config-file#development-overrides-for-provider-developers) feature of the terraform CLI. | ||
To do so, create a `$HOME/.terraformrc` file if it doesn't exist yet (see the [`terraform` CLI documentation](https://developer.hashicorp.com/terraform/cli/config/config-file#locations) for different consideration for Windows systems) with the following content: | ||
|
||
# Clone terraform-provider-opennebula | ||
git clone [email protected]:OpenNebula/terraform-provider-opennebula.git | ||
|
||
# Create directory under Terraform plugins directory | ||
mkdir -p ${HOME}/.terraform.d/plugins/one.test/one/opennebula/${tf_one_version}/${tf_arch} | ||
|
||
# Create a link to the Provider binary | ||
ln -s $(pwd)/terraform-provider-opennebula/terraform-provider-opennebula ${HOME}/.terraform.d/plugins/one.test/one/opennebula/${tf_one_version}/${tf_arch} | ||
```hcl | ||
provider_installation { | ||
dev_overrides { | ||
"OpenNebula/opennebula" = "[LOCAL_PATH_TO_THIS_REPO]" | ||
} | ||
direct {} | ||
} | ||
``` | ||
|
||
# Build the Provider | ||
cd terraform-provider-opennebula | ||
go build | ||
This configuration will not apply any change for `terraform init` or your `.terraform.lock.hcl`. From the Terraform documentation: | ||
```text | ||
With development overrides in effect, the terraform init command will still attempt to select a suitable published | ||
version of your provider to install and record in the dependency lock file for future use, but other commands like | ||
terraform apply will disregard the lock file's entry and will use the given directory instead. | ||
``` | ||
|
||
Now you can create a new `main.tf` file: | ||
This configuration will check for the `terraform-provider-opennebula` binary at the given directory. You can generate it using `make build` | ||
|
||
Example: | ||
```hcl | ||
terraform { | ||
required_providers { | ||
opennebula = { | ||
source = "one.test/one/opennebula" | ||
source = "OpenNebula/opennebula" # use the real provider as source | ||
version = "1.4.0" | ||
} | ||
} | ||
} | ||
|
@@ -44,37 +47,30 @@ provider "opennebula" { | |
# ... | ||
} | ||
resource "opennebula_image" "image" { | ||
data opennebula_datastore "my_datastore" { | ||
# ... | ||
} | ||
``` | ||
|
||
During the `terraform init`, the provider should be initialized as `unauthenticated`: | ||
|
||
```text | ||
$ terraform init | ||
Initializing the backend... | ||
Initializing provider plugins... | ||
- Finding latest version of one.test/one/opennebula... | ||
- Installing one.test/one/opennebula v0.0.1... | ||
- Installed one.test/one/opennebula v0.0.1 (unauthenticated) | ||
Terraform has created a lock file .terraform.lock.hcl to record the provider | ||
selections it made above. Include this file in your version control repository | ||
so that Terraform can guarantee to make the same selections by default when | ||
you run "terraform init" in the future. | ||
Terraform has been successfully initialized! | ||
You may now begin working with Terraform. Try running "terraform plan" to see | ||
any changes that are required for your infrastructure. All Terraform commands | ||
should now work. | ||
If you ever set or change modules or backend configuration for Terraform, | ||
rerun this command to reinitialize your working directory. If you forget, other | ||
commands will detect it and remind you to do so if necessary. | ||
Applying changes for the above simple terraform module shows the override in action: | ||
```txt | ||
$> terraform apply | ||
╷ | ||
│ Warning: Provider development overrides are in effect | ||
│ | ||
│ The following provider development overrides are set in the CLI configuration: | ||
│ - opennebula/opennebula in [LOCAL_PATH_TO_THIS_REPO] | ||
│ | ||
│ The behavior may therefore not match any released version of the provider and applying changes may cause the state to become incompatible with published releases. | ||
╵ | ||
data.opennebula_datastore.my_datastore: Reading... | ||
data.opennebula_datastore.my_datastore: Read complete after 0s | ||
No changes. Your infrastructure matches the configuration. | ||
Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed. | ||
Apply complete! Resources: 0 added, 0 changed, 0 destroyed. | ||
``` | ||
|
||
## Issues and Pull Requests | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters