-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check for compound default info values in provider schemas (#1458)
Fixes #1325. This PR adds an early check for the type of `tfbridge.DefaultInfo.Value` to reject unsupported values such as slices and maps. Only simple values such as strings and integers are currently supported. The PR also adds a line in the documentation about this limitation.
- Loading branch information
1 parent
4069819
commit e0f1893
Showing
5 changed files
with
208 additions
and
0 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,66 @@ | ||
// Copyright 2016-2023, Pulumi Corporation. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package testprovider | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
// Subset of pulumi-random provider. | ||
func ProviderDefaultInfo() *schema.Provider { | ||
resourceRuleset := func() *schema.Resource { | ||
return &schema.Resource{ | ||
Description: "Deploy a ruleset", | ||
Schema: resourceDefaultInfoSchema(), | ||
} | ||
} | ||
|
||
return &schema.Provider{ | ||
Schema: map[string]*schema.Schema{}, | ||
ResourcesMap: map[string]*schema.Resource{ | ||
"default_ruleset": resourceRuleset(), | ||
}, | ||
} | ||
} | ||
|
||
func resourceDefaultInfoSchema() map[string]*schema.Schema { | ||
return map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
Description: "Name of the ruleset.", | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Brief summary of the ruleset and its intended use.", | ||
}, | ||
"rules": { | ||
Type: schema.TypeList, | ||
Optional: true, | ||
Description: "List of rules to apply to the ruleset.", | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Unique rule identifier.", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} |
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
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
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
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,76 @@ | ||
// Copyright 2016-2022, Pulumi Corporation. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package testprovider | ||
|
||
import ( | ||
"unicode" | ||
|
||
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" | ||
shimv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2" | ||
"github.com/pulumi/pulumi/sdk/v3/go/common/tokens" | ||
|
||
testproviderdata "github.com/pulumi/pulumi-terraform-bridge/v3/internal/testprovider" | ||
) | ||
|
||
func ProviderDefaultInfo() tfbridge.ProviderInfo { | ||
|
||
member := func(mod string, mem string) tokens.ModuleMember { | ||
return tokens.ModuleMember("cloudflare" + ":" + mod + ":" + mem) | ||
} | ||
|
||
typ := func(mod string, typ string) tokens.Type { | ||
return tokens.Type(member(mod, typ)) | ||
} | ||
|
||
resource := func(mod string, res string) tokens.Type { | ||
fn := string(unicode.ToLower(rune(res[0]))) + res[1:] | ||
return typ(mod+"/"+fn, res) | ||
} | ||
|
||
return tfbridge.ProviderInfo{ | ||
P: shimv2.NewProvider(testproviderdata.ProviderDefaultInfo()), | ||
Name: "default-info", | ||
Description: "", | ||
Keywords: []string{"pulumi", "random"}, | ||
License: "Apache-2.0", | ||
Homepage: "https://pulumi.io", | ||
Repository: "", | ||
Config: map[string]*tfbridge.SchemaInfo{ | ||
"project": { | ||
Default: &tfbridge.DefaultInfo{ | ||
Value: []string{"default_project"}, | ||
}, | ||
}, | ||
}, | ||
Resources: map[string]*tfbridge.ResourceInfo{ | ||
"default_ruleset": { | ||
Tok: resource("index", "Ruleset"), | ||
Fields: map[string]*tfbridge.SchemaInfo{ | ||
"rules": { | ||
Elem: &tfbridge.SchemaInfo{ | ||
Fields: map[string]*tfbridge.SchemaInfo{ | ||
"id": { | ||
Default: &tfbridge.DefaultInfo{ | ||
Value: []string{"default_id"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} |