Compare commits

...

4 Commits
main ... v1.4.2

Author SHA1 Message Date
Sergen Yalçın 0fbc2bfdea
Merge pull request #463 from crossplane/backport-462-to-release-1.4
[Backport release-1.4] Parametrize the registry name of the provider
2025-01-23 18:05:47 +03:00
Sergen Yalçın d11fb1ffbc Parametrize the registry name of the provider
Signed-off-by: Sergen Yalçın <yalcinsergen97@gmail.com>
(cherry picked from commit 5dbd74a606)
2025-01-23 14:57:03 +00:00
Alper Rifat Ulucinar 9f045fd1da
Merge pull request #418 from crossplane/backport-417-to-release-1.4
[Backport release-1.4] Do not prefix JSON fieldpaths starting with status.atProvider in resource.GetSensitiveParameters
2024-06-06 11:32:10 +00:00
Alper Rifat Ulucinar 7975d92bce Do not prefix JSON fieldpaths starting with status.atProvider in resource.GetSensitiveParameters
- If the MR API has a spec.forProvider.status field and there are sensitive attributes, then
  fieldpath.Paved.ExpandWildcards complains instead of expanding as an empty slice, which
  breaks the reconciliation.

Signed-off-by: Alper Rifat Ulucinar <ulucinar@users.noreply.github.com>
(cherry picked from commit 91d382de43)
2024-06-06 11:22:47 +00:00
3 changed files with 23 additions and 5 deletions

View File

@ -168,17 +168,25 @@ func GetSensitiveParameters(ctx context.Context, client SecretClient, from runti
return err
}
pavedTF := fieldpath.Pave(into)
prefixes := []string{"spec.initProvider.", "spec.forProvider."}
for tfPath, jsonPath := range mapping {
jp := jsonPath
groups := reFieldPathSpec.FindStringSubmatch(jsonPath)
if len(groups) == 3 {
jp = groups[2]
} else if strings.HasPrefix(jsonPath, "status.atProvider.") {
// we will not be prefixing the JSON fieldpath expression if it starts
// with "status.atProvider" in case there is a spec.forProvider.status
// field. If there exists a spec.forProvider.status field, then the
// fieldpath.ExpandWildcards will complain instead of expanding the
// fieldpath expression as an empty slice.
prefixes = []string{""}
}
// spec.forProvider secret references override the spec.initProvider
// references.
for _, p := range []string{"spec.initProvider.", "spec.forProvider."} {
for _, p := range prefixes {
if err := storeSensitiveData(ctx, client, tfPath, p+jp, pavedTF, pavedJSON, mapping); err != nil {
return err
}

View File

@ -34,6 +34,8 @@ const (
errUnmarshalTFState = "cannot unmarshal tfstate file"
errFmtNonString = "cannot work with a non-string id: %s"
errReadMainTF = "cannot read main.tf.json file"
defaultRegistry = `provider["registry.terraform.io/%s"]`
)
// FileProducerOption allows you to configure FileProducer
@ -190,7 +192,7 @@ func (fp *FileProducer) WriteMainTF() (ProviderHandle, error) {
// EnsureTFState writes the Terraform state that should exist in the filesystem
// to start any Terraform operation.
func (fp *FileProducer) EnsureTFState(_ context.Context, tfID string) error {
func (fp *FileProducer) EnsureTFState(_ context.Context, tfID string) error { //nolint:gocyclo // easier to follow as a unit
// TODO(muvaf): Reduce the cyclomatic complexity by separating the attributes
// generation into its own function/interface.
empty, err := fp.isStateEmpty()
@ -229,14 +231,19 @@ func (fp *FileProducer) EnsureTFState(_ context.Context, tfID string) error {
s := json.NewStateV4()
s.TerraformVersion = fp.Setup.Version
s.Lineage = string(fp.Resource.GetUID())
registry := fp.Setup.Requirement.Registry
if registry == "" {
registry = defaultRegistry
}
s.Resources = []json.ResourceStateV4{
{
Mode: "managed",
Type: fp.Resource.GetTerraformResourceType(),
Name: fp.Resource.GetName(),
// TODO(muvaf): we should get the full URL from Dockerfile since
// providers don't have to be hosted in registry.terraform.io
ProviderConfig: fmt.Sprintf(`provider["registry.terraform.io/%s"]`, fp.Setup.Requirement.Source),
// Support for private/non-default registries
ProviderConfig: fmt.Sprintf(registry, fp.Setup.Requirement.Source),
Instances: []json.InstanceObjectStateV4{
{
SchemaVersion: uint64(fp.Resource.GetTerraformSchemaVersion()),

View File

@ -47,6 +47,9 @@ type ProviderRequirement struct {
// Version of the provider. An example value is "4.0"
Version string
// Registry of the provider. An example value is `provider["registry.terraform.io/%s"]`
Registry string
}
// ProviderConfiguration holds the setup configuration body