crossplane / upjet

A code generation framework and runtime for Crossplane providers
Apache License 2.0
294 stars 84 forks source link

examples-generated contain terraform variables in the yaml that are not meaningfully consumable #349

Open humoflife opened 6 months ago

humoflife commented 6 months ago

What happened?

Upjet generates examples in the examples-generated folder to make it easy for users to create managed resources. However, the examples can include Terraform variables that are not meaningfully consumable by Crossplane and result in the generated examples not to work.

Some examples of included variables are as follows:

examples-generated/apm/retentionfilterorder.yaml:    - ${datadog_apm_retention_filter.foo.id}
examples-generated/authn/mapping.yaml:    role: ${data.datadog_role.ro_role.id}
examples-generated/dashboard/list.yaml:    - dashId: ${datadog_dashboard.time.id}
examples-generated/dashboard/list.yaml:    - dashId: ${datadog_dashboard.screen.id}
examples-generated/datadog/role.yaml:    - id: ${data.datadog_permissions.bar.permissions.monitors_downtime}
examples-generated/datadog/role.yaml:    - id: ${data.datadog_permissions.bar.permissions.monitors_write}
examples-generated/datadog/serviceaccount.yaml:    - ${data.datadog_role.ro_role.id}
examples-generated/datadog/user.yaml:    - ${data.datadog_role.ro_role.id}
examples-generated/datadog/slocorrection.yaml:    sloId: ${datadog_service_level_objective.example_slo.id}
examples-generated/integration/gcpsts.yaml:    clientEmail: ${google_service_account.datadog_integration.email}
examples-generated/integration/confluentresource.yaml:    accountId: ${datadog_integration_confluent_account.foo.id}
examples-generated/integration/fastlyservice.yaml:    accountId: ${datadog_integration_fastly_account.foo.id}
examples-generated/logs/indexorder.yaml:    - ${datadog_logs_index.sample_index.id}
examples-generated/logs/pipelineorder.yaml:    - ${datadog_logs_custom_pipeline.sample_pipeline.id}
examples-generated/logs/pipelineorder.yaml:    - ${datadog_logs_integration_pipeline.python.id}
examples-generated/logs/archiveorder.yaml:    - ${datadog_logs_archive.sample_archive_1.id}
examples-generated/logs/archiveorder.yaml:    - ${datadog_logs_archive.sample_archive_2.id}
examples-generated/sensitivedatascanner/rule.yaml:    groupId: ${datadog_sensitive_data_scanner_group.mygroup.id}
examples-generated/team/membership.yaml:    teamId: ${datadog_team.foo.id}
examples-generated/team/membership.yaml:    userId: ${datadog_user.foo.id}
examples-generated/team/permissionsetting.yaml:    teamId: ${datadog_team.foo.id}
examples-generated/team/link.yaml:    teamId: ${datadog_team.foo.id}
examples-generated/webhook/webhook.yaml:    customHeaders: '${jsonencode({ "custom" : "header" })}'
examples-generated/webhook/webhook.yaml:    payload: '${jsonencode({ "custom" : "payload" })}'

How can we reproduce it?

This can be reproduced as follows:

- git clone git@github.com:upbound/provider-datadog.git
- git checkout bootstrap
- make submodules
- make clean; make gen-clean; make generate
- make e2e

Once a cluster is up and configured `kubectl apply -f examples-generated/team/membership.yaml'. The membership resource status message will include the following due to the variables:

observe failed: cannot run refresh: refresh failed: Reference to undeclared resource: A managed resource "datadog_team" "foo" has not been declared in the root module. Reference to undeclared resource: A managed resource "datadog_user" "foo" has not been declared in the root module.
bobh66 commented 5 months ago

This is very confusing to new users and generates a fair number of questions in Slack. Generated examples should be usable "as is" and not require translation of terraform-specific formats and data references.