This repository has been archived by the owner on Nov 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add warning message for deprecated "hashicorp/terraform" provider (#111)
- Loading branch information
Showing
3 changed files
with
104 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Package warnings defines the warnings associated with the provider | ||
package warnings | ||
|
||
// ProviderWarnings return the list of warnings for a given provider identified by its namespace and type | ||
// | ||
// Example: registry.terraform.io/hashicorp/terraform | ||
// | ||
// warn := ProviderWarnings("hashicorp", "terraform") | ||
// fmt.Println(warn) | ||
// >> [This provider is archived and no longer needed. The terraform_remote_state data source is built into the latest OpenTofu release.] | ||
func ProviderWarnings(providerNamespace, providerType string) []string { | ||
switch providerNamespace { //nolint:gocritic // Switch is more appropriate than 'if' for the use case | ||
case "hashicorp": | ||
switch providerType { //nolint:gocritic // Switch is more appropriate than 'if' for the use case | ||
case "terraform": | ||
return []string{`This provider is archived and no longer needed. The terraform_remote_state data source is built into the latest OpenTofu release.`} | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package warnings | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestProviderWarnings(t *testing.T) { | ||
type args struct { | ||
providerNamespace string | ||
providerType string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want []string | ||
}{ | ||
{ | ||
name: "shall return no warnings", | ||
args: args{ | ||
providerNamespace: "foo", | ||
providerType: "bar", | ||
}, | ||
want: nil, | ||
}, | ||
{ | ||
name: "shall return warnings as in https://github.com/opentofu/registry/issues/108", | ||
args: args{ | ||
providerNamespace: "hashicorp", | ||
providerType: "terraform", | ||
}, | ||
want: []string{`This provider is archived and no longer needed. The terraform_remote_state data source is built into the latest OpenTofu release.`}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run( | ||
tt.name, func(t *testing.T) { | ||
if got := ProviderWarnings(tt.args.providerNamespace, tt.args.providerType); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("ProviderWarnings() = %v, want %v", got, tt.want) | ||
} | ||
}, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters