Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: populate terraform attributes from resource's metadata.name #453

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/config/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,10 @@ type Resource struct {
// requiredFields are the fields that will be marked as required in the
// generated CRD schema, although they are not required in the TF schema.
requiredFields []string

// AttributesToPopulateWithMetadataName defines Terraform attributes that
// should be populated with the resources metadata.name
AttributesToPopulateWithMetadataName []string
}

// RequiredFields returns slice of the marked as required fieldpaths.
Expand Down
3 changes: 3 additions & 0 deletions pkg/controller/external_tfpluginsdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ func getExtendedParameters(ctx context.Context, tr resource.Terraformed, externa
if err = resource.GetSensitiveParameters(ctx, &APISecretClient{kube: kube}, tr, params, tr.GetConnectionDetailsMapping()); err != nil {
return nil, errors.Wrap(err, "cannot store sensitive parameters into params")
}
for _, a := range cfg.AttributesToPopulateWithMetadataName {
params[a] = tr.GetName()
}
cfg.ExternalName.SetIdentifierArgumentFn(params, externalName)
if cfg.TerraformConfigurationInjector != nil {
m, err := getJSONMap(tr)
Expand Down
2 changes: 1 addition & 1 deletion pkg/examples/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (eg *Generator) StoreExamples() error { // nolint:gocyclo
func paveCRManifest(exampleParams map[string]any, r *config.Resource, eName, group, version, eGroup string) *reference.PavedWithManifest {
delete(exampleParams, "depends_on")
delete(exampleParams, "lifecycle")
transformFields(r, exampleParams, r.ExternalName.OmittedFields, "")
transformFields(r, exampleParams, append(r.ExternalName.OmittedFields, r.AttributesToPopulateWithMetadataName...), "")
metadata := map[string]any{
"labels": map[string]string{
labelExampleName: eName,
Expand Down
2 changes: 1 addition & 1 deletion pkg/pipeline/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (cg *CRDGenerator) Generate(cfg *config.Resource) (string, error) {
wrapper.WithHeaderPath(cg.LicenseHeaderPath),
)

deleteOmittedFields(cfg.TerraformResource.Schema, cfg.ExternalName.OmittedFields)
deleteOmittedFields(cfg.TerraformResource.Schema, append(cfg.ExternalName.OmittedFields, cfg.AttributesToPopulateWithMetadataName...))
cfg.TerraformResource.Schema["id"] = &schema.Schema{
Type: schema.TypeString,
Computed: true,
Expand Down
3 changes: 3 additions & 0 deletions pkg/terraform/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ func NewFileProducer(ctx context.Context, client resource.SecretClient, dir stri
return nil, errors.Wrap(err, "cannot get sensitive parameters")
}
fp.Config.ExternalName.SetIdentifierArgumentFn(params, meta.GetExternalName(tr))
for _, a := range cfg.AttributesToPopulateWithMetadataName {
params[a] = tr.GetName()
}
fp.parameters = params

obs, err := tr.GetObservation()
Expand Down
Loading