-
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.
Autonaming configuration in Configure and Check (#2675)
This PR implements the bridge part of [Autonaming Configuration](pulumi/pulumi#1518). See [RFC](pulumi/pulumi#17592) for the full design. In short, [Protobuf definition for autonaming configuration](pulumi/pulumi#17810) introduced the protobuf changes required for the provider-side implementation. With those, a provider can: - Declare that it supports autonaming configurations with a response flag in Configure - Accept two extra properties in CheckRequest: a proposed name and a mode to apply it This PR implements autonaming configuration for all bridged providers. It passes the configuration from CheckRequest all the way down to the autonaming module. The module itself is now able to understand the modes and use the proposed name appropriately: - For `disable` mode, it will disable autonaming and throw an error if no explicit name was provided by a user - For `enforce` mode, it will use the proposed name verbatim. Note that all checks on that name are ignored: this is by design, so that users would be able to override the provider's settings with `enforce: true` if they need to - For `propose` mode, it will try using the proposed name but can also modify and validate it. The bridge applies transformations (e.g. lowercasing the name) and checks max length/character set requirements. See the test cases for details. No changes are needed to the provider themselves beyond rolling to the new version of TF bridge once it's published. The PR is split into three commits: (1) all the manual changes, (2) mechanical updates of replay tests, (3) end-to-end tests. Resolves #2722
- Loading branch information
1 parent
e53958b
commit 7b3ace6
Showing
31 changed files
with
666 additions
and
56 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
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
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,57 @@ | ||
package tfbridgetests | ||
|
||
import ( | ||
"testing" | ||
|
||
rschema "github.com/hashicorp/terraform-plugin-framework/resource/schema" | ||
"github.com/pulumi/providertest/pulumitest/opttest" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tests/internal/providerbuilder" | ||
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tests/pulcheck" | ||
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge" | ||
) | ||
|
||
func TestAutonaming(t *testing.T) { | ||
t.Parallel() | ||
provBuilder := providerbuilder.NewProvider( | ||
providerbuilder.NewProviderArgs{ | ||
AllResources: []providerbuilder.Resource{ | ||
providerbuilder.NewResource(providerbuilder.NewResourceArgs{ | ||
ResourceSchema: rschema.Schema{ | ||
Attributes: map[string]rschema.Attribute{ | ||
"name": rschema.StringAttribute{Optional: true}, | ||
}, | ||
}, | ||
}), | ||
}, | ||
}) | ||
|
||
prov := bridgedProvider(provBuilder) | ||
prov.Resources["testprovider_test"] = &tfbridge.ResourceInfo{ | ||
Tok: "testprovider:index:Test", | ||
Fields: map[string]*tfbridge.SchemaInfo{ | ||
"name": tfbridge.AutoName("name", 50, "-"), | ||
}, | ||
} | ||
program := ` | ||
name: test | ||
runtime: yaml | ||
config: | ||
pulumi:autonaming: | ||
value: | ||
pattern: ${project}-${name} | ||
resources: | ||
hello: | ||
type: testprovider:index:Test | ||
outputs: | ||
testOut: ${hello.name} | ||
` | ||
opts := []opttest.Option{ | ||
opttest.Env("PULUMI_EXPERIMENTAL", "true"), | ||
} | ||
pt, err := pulcheck.PulCheck(t, prov, program, opts...) | ||
require.NoError(t, err) | ||
res := pt.Up(t) | ||
require.Equal(t, "test-hello", res.Outputs["testOut"].Value) | ||
} |
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
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
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
Oops, something went wrong.