Skip to content

Commit 0aa7840

Browse files
author
Paddy Carver
committed
Allow hyphens in configurable names, too, I guess.
1 parent dd46fac commit 0aa7840

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

tfprotov5/tf5server/server.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ func WithoutLogLocation() ServeOpt {
9494
// logging environment variable that controls the provider's log level. It is
9595
// the part following TF_LOG_PROVIDER_ and defaults to the name part of the
9696
// provider's registry address, or disabled if it can't parse the provider's
97-
// registry address. Name must only contain letters and numbers.
97+
// registry address. Name must only contain letters, numbers, and hyphens.
9898
func WithLogEnvVarName(name string) ServeOpt {
9999
return serveConfigFunc(func(in *ServeConfig) error {
100-
if !regexp.MustCompile(`^[a-zA-Z0-9]+$`).MatchString(name) {
101-
return errors.New("environment variable names can only contain a-z, A-Z, and 0-9")
100+
if !regexp.MustCompile(`^[a-zA-Z0-9-]+$`).MatchString(name) {
101+
return errors.New("environment variable names can only contain a-z, A-Z, 0-9, and -")
102102
}
103103
in.envVar = name
104104
return nil
@@ -262,9 +262,10 @@ func New(name string, serve tfprotov5.ProviderServer, opts ...ServeOpt) tfplugin
262262
if err != nil {
263263
log.Println("[ERROR] Error parsing provider name:", err)
264264
} else {
265-
envVar = strings.ReplaceAll(addr.Type, "-", "_")
265+
envVar = addr.Type
266266
}
267267
}
268+
envVar = strings.ReplaceAll(envVar, "-", "_")
268269
if envVar != "" {
269270
options = append(options, tflog.WithLogName(envVar), tflog.WithLevelFromEnv("TF", "LOG", "PROVIDER", envVar))
270271
}

tfprotov6/tf6server/server.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ func WithoutLogLocation() ServeOpt {
9494
// logging environment variable that controls the provider's log level. It is
9595
// the part following TF_LOG_PROVIDER_ and defaults to the name part of the
9696
// provider's registry address, or disabled if it can't parse the provider's
97-
// registry address. Name must only contain letters and numbers.
97+
// registry address. Name must only contain letters, numbers, and hyphens.
9898
func WithLogEnvVarName(name string) ServeOpt {
9999
return serveConfigFunc(func(in *ServeConfig) error {
100-
if !regexp.MustCompile(`^[a-zA-Z0-9]+$`).MatchString(name) {
101-
return errors.New("environment variable names can only contain a-z, A-Z, and 0-9")
100+
if !regexp.MustCompile(`^[a-zA-Z0-9-]+$`).MatchString(name) {
101+
return errors.New("environment variable names can only contain a-z, A-Z, 0-9, and -")
102102
}
103103
in.envVar = name
104104
return nil
@@ -263,9 +263,10 @@ func New(name string, serve tfprotov6.ProviderServer, opts ...ServeOpt) tfplugin
263263
if err != nil {
264264
log.Println("[ERROR] Error parsing provider name:", err)
265265
} else {
266-
envVar = strings.ReplaceAll(addr.Type, "-", "_")
266+
envVar = addr.Type
267267
}
268268
}
269+
envVar = strings.ReplaceAll(envVar, "-", "_")
269270
if envVar != "" {
270271
options = append(options, tflog.WithLogName(envVar), tflog.WithLevelFromEnv("TF", "LOG", "PROVIDER", envVar))
271272
}

0 commit comments

Comments
 (0)