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

helper/schema: Add helper function JsonEnvDefaultFunc #602

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gw0
Copy link

@gw0 gw0 commented Sep 30, 2020

Currently, there are only two simple helper functions available for providing default values in Terraform plugin schema definitions. These read env variables and can only return a single string.

This PR adds a helper function JsonEnvDefaultFunc that can be used in more complex scenarios that require a map with arbitrary keys (to be used with TypeMap). It expects the map to be encoded as an JSON object in a string.

For example if you have a provider that needs support for arbitrary HTTP headers:

provider "foo" {
  url  = "http://..."
  headers = {
    "Cookies" = "foo=bar"
  }
}

This helper function opens the door for passing HTTP headers using an env variable:

$ FOO_HTTP_HEADERS='{"Cookies":"foo=bar"}' terraform plan

@gw0 gw0 force-pushed the gw0/add-helper-JsonEnvDefaultFunc branch from 1fa7ac2 to 6b9b83b Compare November 2, 2020 11:44
@gw0
Copy link
Author

gw0 commented Nov 2, 2020

Rebased and corrected gofmt check.

Base automatically changed from master to main March 22, 2021 14:01
@hashicorp-cla
Copy link

hashicorp-cla commented Mar 12, 2022

CLA assistant check
All committers have signed the CLA.

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.

None yet

2 participants