Skip to content

Commit

Permalink
Merge pull request #463 from crossplane/backport-462-to-release-1.4
Browse files Browse the repository at this point in the history
[Backport release-1.4] Parametrize the registry name of the provider
  • Loading branch information
sergenyalcin authored Jan 23, 2025
2 parents 9f045fd + d11fb1f commit 0fbc2bf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
15 changes: 11 additions & 4 deletions pkg/terraform/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()),
Expand Down
3 changes: 3 additions & 0 deletions pkg/terraform/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0fbc2bf

Please sign in to comment.