Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allows setting the provider host and authorisation_token via CAPELLA prefixed environment variables #239

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

cdsre
Copy link

@cdsre cdsre commented Nov 6, 2024

Jira

Description

Please include a summary of the fix/feature/change, including any relevant motivation and context.

Updates the provider to allow setting of the host and authorisation_token as environment variables prefixed with CAPELLA_ and removes authorisation_token as a required attribute in the configuration block as it can now be provided from an environment variable

Type of Change

  • Bug fix (non-breaking change which fixes an issue). Please, add the "bug" label to the PR.
  • New feature (non-breaking change which adds functionality). Please, add the "enhancement" label to the PR.
  • Breaking change (fix or feature that would cause existing functionality to not work as expected). Please, add the "breaking change" label to the PR.
  • This change requires a documentation update
  • Documentation fix/enhancement

Manual Testing Approach

How was this change tested and do you have evidence? (REQUIRED: Select at least 1)

  • Manually tested
  • Unit tested
  • Acceptance tested
  • Unable to test / will not test (Please provide comments in section below)

Testing

Testing

Example terraform code

terraform {
  required_providers {
    couchbase-capella = {
      source = "couchbasecloud/couchbase-capella"
    }
  }
}

data "couchbase-capella_projects" "this" {
  organization_id = "e5456751-XXXXXXXXXXXXXX-aecb859d7db0"
}

output "clusters_list" {
  value = "Number of current projects: ${length(data.couchbase-capella_projects.this.data)}"
}

Execution

$ export CAPELLA_AUTHENTICATION_TOKEN=UTZFcXXXXXXXXXXXXXXXXXXXXXXXGV0WQ==
$ terraform apply --auto-approve
╷
│ Warning: Provider development overrides are in effect
│
│ The following provider development overrides are set in the CLI configuration:
│  - couchbasecloud/couchbase-capella in C:\Users\CDoyle\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.
╵
data.couchbase-capella_projects.this: Reading...
data.couchbase-capella_projects.this: Read complete after 0s

Changes to Outputs:
  + clusters_list = "Number of current projects: 1"

You can apply this plan to save these new output values to the Terraform state, without changing any real infrastructure.

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:

clusters_list = "Number of current projects: 1"

Without using a provider block in the terraform code and setting only the CAPELLA_AUTHORISATION_TOKEN the provider still successfully interacts with the API and retrieves project details.

Required Checklist:

  • I have checked that this change does not generate any credentials and that they are NOT accidentally logged anywhere.
  • I have added tests that prove my fix is effective or that my feature works per HashiCorp requirements
  • I have added any necessary documentation (if required)
  • I have run make fmt and formatted my code
  • I have made sure that no schema field is marked with both requiresReplace and computed

Further comments

The make fmt has formatted the internal/schema/cluster.go There is no functional change here other than the go formatter passing the spaces.

…PELLA prefixed environment variables

Signed-off-by: Chris Doyle <[email protected]>
Signed-off-by: Chris Doyle <[email protected]>
@cdsre cdsre requested review from a team as code owners November 6, 2024 23:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: Allow provider config to be set from environment variables.
1 participant