-
Notifications
You must be signed in to change notification settings - Fork 242
Closed
Labels
documentationImprovements or additions to documentationImprovements or additions to documentation
Milestone
Description
SDK version
github.com/hashicorp/terraform-plugin-sdk/v2 v2.4.3
Relevant provider source code
The problem happens when I include AtLeastOneOf in one of my optional provider attributes.
func Provider() *schema.Provider {
p := &schema.Provider{
Schema: map[string]*schema.Schema{
"host": {
Type: schema.TypeString,
Optional: true,
Description: "The hostname (in form of URI) of Kubernetes master.",
AtLeastOneOf: []string{"token", "exec", "username", "password", "client_certificate", "client_key"},
},
When this code runs, the attribute references itself as one of the required attributes. (host appears in the list below).
$ terraform plan
╷
│ Error: AtLeastOne
│
│ "host": one of `client_certificate,client_key,exec,host,password,token,username` must be specified
╵
Terraform Configuration Files
$ cat main.tf
terraform {
required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
version = "9.9.9" # this is my dev version
}
}
}
provider "kubernetes" {
config_path = "~/.kube/config"
# note that `host` is omitted
}
resource "kubernetes_namespace" "test" {
metadata {
name = "test"
}
}Debug Output
Expected Behavior
I read the docs and they say:
AtLeastOneOf is a set of schema keys that, when set, at least one of the keys in that list must be specified.
I expected to get an error when I specify host without specifying one of the options that are needed with host. Specifically, client_certificate, client_key, exec, password, token, username.
Actual Behavior
I didn't specify host, because it's optional. But AtLeastOneOf tells me I need to specify host.
Steps to Reproduce
- Grab your favorite provider to do some development with, or fetch my branch here.
- If needed, add
AtLeastOneOfto an optional schema attribute. (This is already done on my branch). - Build the provider and initialize it using a configuration that specifies at least one resource (like my example config above). Omit the attribute that has
AtLeastOneOffrom your provider configuration. terraform planorterraform apply.
References
This is my PR where I'm trying to use AtLeastOneOf. hashicorp/terraform-provider-kubernetes#1141
Metadata
Metadata
Assignees
Labels
documentationImprovements or additions to documentationImprovements or additions to documentation