Skip to content

Commit 415a860

Browse files
committed
Add conflictswith warning level message
1 parent 211009c commit 415a860

File tree

1 file changed

+95
-68
lines changed

1 file changed

+95
-68
lines changed

kubernetes/provider.go

Lines changed: 95 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
88
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging"
99
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
10-
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
1110
"github.com/mitchellh/go-homedir"
1211
apimachineryschema "k8s.io/apimachinery/pkg/runtime/schema"
1312
"k8s.io/client-go/discovery"
@@ -25,65 +24,80 @@ import (
2524
)
2625

2726
func Provider() *schema.Provider {
27+
conditionsMessage := "Specifying more than one authentication method can lead to unpredictable behavior." +
28+
" This option will be removed in a future release. Please update your configuration."
2829
p := &schema.Provider{
2930
Schema: map[string]*schema.Schema{
3031
"host": {
31-
Type: schema.TypeString,
32-
Optional: true,
33-
DefaultFunc: schema.EnvDefaultFunc("KUBE_HOST", nil),
34-
Description: "The hostname (in form of URI) of Kubernetes master.",
35-
ConflictsWith: []string{"config_path", "config_paths"},
36-
ValidateDiagFunc: validation.ToDiagFunc(validation.IsURLWithHTTPorHTTPS),
32+
Type: schema.TypeString,
33+
Optional: true,
34+
DefaultFunc: schema.EnvDefaultFunc("KUBE_HOST", nil),
35+
Description: "The hostname (in form of URI) of Kubernetes master.",
36+
ConflictsWith: []string{"config_path", "config_paths"},
37+
ConditionsMode: "warning",
38+
ConditionsMessage: conditionsMessage,
3739
// TODO: enable this when AtLeastOneOf works with optional attributes.
3840
// https://github.com/hashicorp/terraform-plugin-sdk/issues/705
3941
// AtLeastOneOf: []string{"token", "exec", "username", "password", "client_certificate", "client_key"},
4042
},
4143
"username": {
42-
Type: schema.TypeString,
43-
Optional: true,
44-
DefaultFunc: schema.EnvDefaultFunc("KUBE_USER", nil),
45-
Description: "The username to use for HTTP basic authentication when accessing the Kubernetes master endpoint.",
46-
ConflictsWith: []string{"config_path", "config_paths", "exec", "token", "client_certificate", "client_key"},
47-
RequiredWith: []string{"password", "host"},
44+
Type: schema.TypeString,
45+
Optional: true,
46+
DefaultFunc: schema.EnvDefaultFunc("KUBE_USER", nil),
47+
Description: "The username to use for HTTP basic authentication when accessing the Kubernetes master endpoint.",
48+
ConflictsWith: []string{"config_path", "config_paths", "exec", "token", "client_certificate", "client_key"},
49+
RequiredWith: []string{"password", "host"},
50+
ConditionsMode: "warning",
51+
ConditionsMessage: conditionsMessage,
4852
},
4953
"password": {
50-
Type: schema.TypeString,
51-
Optional: true,
52-
DefaultFunc: schema.EnvDefaultFunc("KUBE_PASSWORD", nil),
53-
Description: "The password to use for HTTP basic authentication when accessing the Kubernetes master endpoint.",
54-
ConflictsWith: []string{"config_path", "config_paths", "exec", "token", "client_certificate", "client_key"},
55-
RequiredWith: []string{"username", "host"},
54+
Type: schema.TypeString,
55+
Optional: true,
56+
DefaultFunc: schema.EnvDefaultFunc("KUBE_PASSWORD", nil),
57+
Description: "The password to use for HTTP basic authentication when accessing the Kubernetes master endpoint.",
58+
ConflictsWith: []string{"config_path", "config_paths", "exec", "token", "client_certificate", "client_key"},
59+
RequiredWith: []string{"username", "host"},
60+
ConditionsMode: "warning",
61+
ConditionsMessage: conditionsMessage,
5662
},
5763
"insecure": {
58-
Type: schema.TypeBool,
59-
Optional: true,
60-
DefaultFunc: schema.EnvDefaultFunc("KUBE_INSECURE", nil),
61-
Description: "Whether server should be accessed without verifying the TLS certificate.",
62-
ConflictsWith: []string{"cluster_ca_certificate", "client_key", "client_certificate", "exec"},
64+
Type: schema.TypeBool,
65+
Optional: true,
66+
DefaultFunc: schema.EnvDefaultFunc("KUBE_INSECURE", nil),
67+
Description: "Whether server should be accessed without verifying the TLS certificate.",
68+
ConflictsWith: []string{"cluster_ca_certificate", "client_key", "client_certificate", "exec"},
69+
ConditionsMode: "warning",
70+
ConditionsMessage: conditionsMessage,
6371
},
6472
"client_certificate": {
65-
Type: schema.TypeString,
66-
Optional: true,
67-
DefaultFunc: schema.EnvDefaultFunc("KUBE_CLIENT_CERT_DATA", nil),
68-
Description: "PEM-encoded client certificate for TLS authentication.",
69-
ConflictsWith: []string{"config_path", "config_paths", "username", "password", "insecure"},
70-
RequiredWith: []string{"client_key", "cluster_ca_certificate", "host"},
73+
Type: schema.TypeString,
74+
Optional: true,
75+
DefaultFunc: schema.EnvDefaultFunc("KUBE_CLIENT_CERT_DATA", nil),
76+
Description: "PEM-encoded client certificate for TLS authentication.",
77+
ConflictsWith: []string{"config_path", "config_paths", "username", "password", "insecure"},
78+
RequiredWith: []string{"client_key", "cluster_ca_certificate", "host"},
79+
ConditionsMode: "warning",
80+
ConditionsMessage: conditionsMessage,
7181
},
7282
"client_key": {
73-
Type: schema.TypeString,
74-
Optional: true,
75-
DefaultFunc: schema.EnvDefaultFunc("KUBE_CLIENT_KEY_DATA", nil),
76-
Description: "PEM-encoded client certificate key for TLS authentication.",
77-
ConflictsWith: []string{"config_path", "config_paths", "username", "password", "exec", "insecure"},
78-
RequiredWith: []string{"client_certificate", "cluster_ca_certificate", "host"},
83+
Type: schema.TypeString,
84+
Optional: true,
85+
DefaultFunc: schema.EnvDefaultFunc("KUBE_CLIENT_KEY_DATA", nil),
86+
Description: "PEM-encoded client certificate key for TLS authentication.",
87+
ConflictsWith: []string{"config_path", "config_paths", "username", "password", "exec", "insecure"},
88+
RequiredWith: []string{"client_certificate", "cluster_ca_certificate", "host"},
89+
ConditionsMode: "warning",
90+
ConditionsMessage: conditionsMessage,
7991
},
8092
"cluster_ca_certificate": {
81-
Type: schema.TypeString,
82-
Optional: true,
83-
DefaultFunc: schema.EnvDefaultFunc("KUBE_CLUSTER_CA_CERT_DATA", nil),
84-
Description: "PEM-encoded root certificates bundle for TLS authentication.",
85-
ConflictsWith: []string{"config_path", "config_paths", "insecure"},
86-
RequiredWith: []string{"host"},
93+
Type: schema.TypeString,
94+
Optional: true,
95+
DefaultFunc: schema.EnvDefaultFunc("KUBE_CLUSTER_CA_CERT_DATA", nil),
96+
Description: "PEM-encoded root certificates bundle for TLS authentication.",
97+
ConflictsWith: []string{"config_path", "config_paths", "insecure"},
98+
RequiredWith: []string{"host"},
99+
ConditionsMode: "warning",
100+
ConditionsMessage: conditionsMessage,
87101
// TODO: enable this when AtLeastOneOf works with optional attributes.
88102
// https://github.com/hashicorp/terraform-plugin-sdk/issues/705
89103
// AtLeastOneOf: []string{"token", "exec", "client_certificate", "client_key"},
@@ -95,50 +109,61 @@ func Provider() *schema.Provider {
95109
Optional: true,
96110
Description: "A list of paths to kube config files. Can be set with KUBE_CONFIG_PATHS environment variable.",
97111
// config_paths conflicts with every attribute except for "insecure", since all of these options will be read from the kubeconfig.
98-
ConflictsWith: []string{"config_path", "exec", "token", "host", "client_certificate", "client_key", "cluster_ca_certificate", "username", "password"},
112+
ConflictsWith: []string{"config_path", "exec", "token", "host", "client_certificate", "client_key", "cluster_ca_certificate", "username", "password"},
113+
ConditionsMode: "warning",
114+
ConditionsMessage: conditionsMessage,
99115
},
100116
"config_path": {
101117
Type: schema.TypeString,
102118
Optional: true,
103119
DefaultFunc: schema.EnvDefaultFunc("KUBE_CONFIG_PATH", nil),
104120
Description: "Path to the kube config file. Can be set with KUBE_CONFIG_PATH.",
105121
// config_path conflicts with every attribute except for "insecure", since all of these options will be read from the kubeconfig.
106-
ConflictsWith: []string{"config_paths", "exec", "token", "host", "client_certificate", "client_key", "cluster_ca_certificate", "username", "password"},
122+
ConflictsWith: []string{"config_paths", "exec", "token", "host", "client_certificate", "client_key", "cluster_ca_certificate", "username", "password"},
123+
ConditionsMode: "warning",
124+
ConditionsMessage: conditionsMessage,
107125
},
108126
"config_context": {
109-
Type: schema.TypeString,
110-
Optional: true,
111-
DefaultFunc: schema.EnvDefaultFunc("KUBE_CTX", nil),
112-
Description: "Context to choose from the kube config file. ",
113-
ConflictsWith: []string{"exec", "token", "client_certificate", "client_key", "username", "password"},
127+
Type: schema.TypeString,
128+
Optional: true,
129+
DefaultFunc: schema.EnvDefaultFunc("KUBE_CTX", nil),
130+
Description: "Context to choose from the kube config file. ",
131+
ConflictsWith: []string{"exec", "token", "client_certificate", "client_key", "username", "password"},
132+
ConditionsMode: "warning",
133+
ConditionsMessage: "This functionality will be removed in a later release. Please update your configuration.",
114134
// TODO: enable this when AtLeastOneOf works with optional attributes.
115135
// AtLeastOneOf: []string{"config_path", "config_paths"},
116136
},
117137
"config_context_auth_info": {
118-
Type: schema.TypeString,
119-
Optional: true,
120-
DefaultFunc: schema.EnvDefaultFunc("KUBE_CTX_AUTH_INFO", nil),
121-
Description: "Authentication info context of the kube config (name of the kubeconfig user, --user flag in kubectl).",
122-
ConflictsWith: []string{"exec", "token", "client_certificate", "client_key", "username", "password"},
138+
Type: schema.TypeString,
139+
Optional: true,
140+
DefaultFunc: schema.EnvDefaultFunc("KUBE_CTX_AUTH_INFO", nil),
141+
Description: "Authentication info context of the kube config (name of the kubeconfig user, --user flag in kubectl).",
142+
ConflictsWith: []string{"exec", "token", "client_certificate", "client_key", "username", "password"},
143+
ConditionsMode: "warning",
144+
ConditionsMessage: "This functionality will be removed in a later release. Please update your configuration.",
123145
// TODO: enable this when AtLeastOneOf works with optional attributes.
124146
// AtLeastOneOf: []string{"config_path", "config_paths"},
125147
},
126148
"config_context_cluster": {
127-
Type: schema.TypeString,
128-
Optional: true,
129-
DefaultFunc: schema.EnvDefaultFunc("KUBE_CTX_CLUSTER", nil),
130-
Description: "Cluster context of the kube config (name of the kubeconfig cluster, --cluster flag in kubectl).",
131-
ConflictsWith: []string{"exec", "token", "client_certificate", "client_key", "username", "password"},
149+
Type: schema.TypeString,
150+
Optional: true,
151+
DefaultFunc: schema.EnvDefaultFunc("KUBE_CTX_CLUSTER", nil),
152+
Description: "Cluster context of the kube config (name of the kubeconfig cluster, --cluster flag in kubectl).",
153+
ConflictsWith: []string{"exec", "token", "client_certificate", "client_key", "username", "password"},
154+
ConditionsMessage: "Specifying more than one authentication method can lead to unpredictable behavior. This option will be removed in a future release. Please update your configuration.",
132155
// TODO: enable this when AtLeastOneOf works with optional attributes.
133156
// AtLeastOneOf: []string{"config_path", "config_paths"},
134157
},
135158
"token": {
136-
Type: schema.TypeString,
137-
Optional: true,
138-
DefaultFunc: schema.EnvDefaultFunc("KUBE_TOKEN", nil),
139-
Description: "Bearer token for authenticating the Kubernetes API.",
140-
ConflictsWith: []string{"config_path", "config_paths", "exec", "client_certificate", "client_key", "username", "password"},
141-
RequiredWith: []string{"host"},
159+
Type: schema.TypeString,
160+
Optional: true,
161+
DefaultFunc: schema.EnvDefaultFunc("KUBE_TOKEN", nil),
162+
Description: "Bearer token for authenticating the Kubernetes API.",
163+
ConflictsWith: []string{"config_path", "config_paths", "exec", "client_certificate", "client_key", "username", "password"},
164+
ConditionsMode: "warning",
165+
ConditionsMessage: "Specifying more than one authentication method can lead to unpredictable behavior. This option will be removed in a future release. Please update your configuration.",
166+
RequiredWith: []string{"host"},
142167
},
143168
"exec": {
144169
Type: schema.TypeList,
@@ -166,9 +191,11 @@ func Provider() *schema.Provider {
166191
},
167192
},
168193
},
169-
Description: "Configuration block to use an exec-based credential plugin, e.g. call an external command to receive user credentials.",
170-
ConflictsWith: []string{"config_path", "config_paths", "token", "client_certificate", "client_key", "username", "password", "insecure"},
171-
RequiredWith: []string{"host", "cluster_ca_certificate"},
194+
Description: "Configuration block to use an exec-based credential plugin, e.g. call an external command to receive user credentials.",
195+
ConflictsWith: []string{"config_path", "config_paths", "token", "client_certificate", "client_key", "username", "password", "insecure"},
196+
RequiredWith: []string{"host", "cluster_ca_certificate"},
197+
ConditionsMode: "warning",
198+
ConditionsMessage: "Specifying more than one authentication method can lead to unpredictable behavior. This option will be removed in a future release. Please update your configuration.",
172199
},
173200
},
174201

0 commit comments

Comments
 (0)