Skip to content

Allow configuring the provider by environment variables

Stwalkerster requested to merge stwalkerster/terraform-cloudvps:T321250 into main

I've got an implementation of this working.

Using the following OpenTofu code:

terraform {
  required_providers {
    cloudvps = {
        source = "terraform.wmcloud.org/registry/cloudvps"
    }
  }
}

provider "cloudvps" {}

resource "cloudvps_web_proxy" "debug" {
    hostname = "accounts-provider-debug"
    domain = "wmcloud.org"
    backends = ["http://172.16.6.17:80"]
}

And OpenTofu configured to use my local system as the provider source (this is the cause of the warnings below):

provider_installation {
  dev_overrides {
    "terraform.wmcloud.org/registry/cloudvps" = "/home/stwalkerster/go/bin"
  }

  direct {}
}

OpenTofu produces this output:

bash $ tofu plan

│ Warning: Provider development overrides are in effect

│ The following provider development overrides are set in the CLI configuration:
│  - terraform.wmcloud.org/registry/cloudvps in /home/stwalkerster/go/bin

│ 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.


Planning failed. OpenTofu encountered an error while generating this plan.


│ Error: OpenStack Auth URL not set

│   with provider["terraform.wmcloud.org/registry/cloudvps"],
│   on main.tf line 9, in provider "cloudvps":
│    9: provider "cloudvps" {}

│ The provider is unable to determine the OpenStack Auth URL. Please configure this setting in the provider block or by using the OS_AUTH_URL environment variable.


│ Error: OpenStack Project ID not set

│   with provider["terraform.wmcloud.org/registry/cloudvps"],
│   on main.tf line 9, in provider "cloudvps":
│    9: provider "cloudvps" {}

│ The provider is unable to determine the OpenStack Project ID. Please configure this setting in the provider block or by using the OS_PROJECT_ID environment variable.


│ Error: OpenStack Application Credential ID not set

│   with provider["terraform.wmcloud.org/registry/cloudvps"],
│   on main.tf line 9, in provider "cloudvps":
│    9: provider "cloudvps" {}

│ The provider is unable to determine the OpenStack Application Credential ID. Please configure this setting in the provider block or by using the OS_APPLICATION_CREDENTIAL_ID environment variable.


│ Error: OpenStack Application Credential Secret not set

│   with provider["terraform.wmcloud.org/registry/cloudvps"],
│   on main.tf line 9, in provider "cloudvps":
│    9: provider "cloudvps" {}

│ The provider is unable to determine the OpenStack Application Credential Secret. Please configure this setting in the provider block or by using the OS_APPLICATION_CREDENTIAL_SECRET environment variable.

However, running the following set of commands now allows the plan to execute successfully:

bash $ export OS_APPLICATION_CREDENTIAL_ID="e62...[snip]...30f"
bash $ export OS_APPLICATION_CREDENTIAL_SECRET="zB1...[snip]...NBA"
bash $ export OS_AUTH_URL="https://openstack.eqiad1.wikimediacloud.org:25000/v3"
bash $ export OS_PROJECT_ID=account-creation-assistance
bash $ tofu plan

│ Warning: Provider development overrides are in effect

│ The following provider development overrides are set in the CLI configuration:
│  - terraform.wmcloud.org/registry/cloudvps in /home/stwalkerster/go/bin

│ 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.

cloudvps_web_proxy.debug: Refreshing state...

No changes. Your infrastructure matches the configuration.

OpenTofu has compared your real infrastructure against your configuration and found no
differences, so no changes are needed.

Closes T321250

Merge request reports