feat: sync add UseStateForUnknown to computed ID/timestamp fields provider-wide - #96
Conversation
📝 WalkthroughWalkthroughResource schemas across catalog, access-control, masking, filtering, service-account, cluster, and tag resources now apply Terraform 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (3)
internal/provider/bigquery_catalog_resource.go (1)
55-65: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider extracting a helper for the repeated
UseStateForUnknownpattern.The same ~10-line block (type-assert → set PlanModifiers → write back) is duplicated across 11+ catalog resource files and several non-catalog resources. A small helper would reduce maintenance burden and prevent divergence.
♻️ Proposed helper extraction
// applyUseStateForUnknown adds a UseStateForUnknown plan modifier to a string attribute // in the schema. No-op if the attribute is missing or not a StringAttribute. func applyUseStateForUnknown(s *schema.Schema, attrName string) { if attr, ok := s.Attributes[attrName].(schema.StringAttribute); ok { attr.PlanModifiers = append(attr.PlanModifiers, stringplanmodifier.UseStateForUnknown()) s.Attributes[attrName] = attr } }Then each call site simplifies to:
- // catalog_id is assigned at creation and never changes. Without UseStateForUnknown, any update - // to the catalog causes Terraform to mark catalog_id as "known after apply", which propagates to - // downstream resources referencing it (e.g. galaxy_role_privilege_grant.entity_id) and forces - // unnecessary destroy/recreate cycles. - if attr, ok := s.Attributes["catalog_id"].(schema.StringAttribute); ok { - attr.PlanModifiers = []planmodifier.String{ - stringplanmodifier.UseStateForUnknown(), - } - s.Attributes["catalog_id"] = attr - } + // catalog_id is assigned at creation and never changes. UseStateForUnknown prevents + // "known after apply" propagation to downstream resources (e.g. galaxy_role_privilege_grant.entity_id). + applyUseStateForUnknown(&s, "catalog_id")internal/provider/gcs_catalog_resource.go (1)
57-67: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚖️ Poor tradeoffRepeated attach-modifier boilerplate across ~20 files.
The
if attr, ok := s.Attributes[...].(schema.StringAttribute); ok { ... }block is duplicated verbatim in every catalog and non-catalog resource file in this PR stack. Since this repo is synced fromterraform-provider-galaxy-generation, a shared helper (e.g.applyUseStateForUnknown(attrs map[string]schema.Attribute, name string)) would reduce duplication, but should be introduced upstream in the generator to survive the next sync rather than patched only here.internal/provider/mysql_catalog_resource.go (1)
57-67: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider extracting a shared helper for the
UseStateForUnknownplan modifier block.This identical 10-line block is duplicated across 11+ catalog resource files. If the plan modifier logic ever needs to change (e.g., adding a second modifier or adjusting the attribute name), every file must be updated independently. A small helper function would centralize the logic and reduce the risk of drift.
♻️ Proposed helper extraction
// applyUseStateForUnknown sets the UseStateForUnknown plan modifier on a string // attribute in a generated schema so Terraform retains the prior state value // during updates instead of marking it "known after apply". func applyUseStateForUnknown(s schema.Schema, attrName string) { if attr, ok := s.Attributes[attrName].(schema.StringAttribute); ok { attr.PlanModifiers = []planmodifier.String{ stringplanmodifier.UseStateForUnknown(), } s.Attributes[attrName] = attr } }Then each
Schema()method simplifies to:- // catalog_id is assigned at creation and never changes. Without UseStateForUnknown, any update - // to the catalog causes Terraform to mark catalog_id as "known after apply", which propagates to - // downstream resources referencing it (e.g. galaxy_role_privilege_grant.entity_id) and forces - // unnecessary destroy/recreate cycles. - if attr, ok := s.Attributes["catalog_id"].(schema.StringAttribute); ok { - attr.PlanModifiers = []planmodifier.String{ - stringplanmodifier.UseStateForUnknown(), - } - s.Attributes["catalog_id"] = attr - } + // catalog_id is assigned at creation and never changes. + applyUseStateForUnknown(s, "catalog_id")
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Enterprise
Run ID: de6d571d-bf49-4e9a-8d8b-160491d21e94
📒 Files selected for processing (20)
internal/provider/bigquery_catalog_resource.gointernal/provider/cassandra_catalog_resource.gointernal/provider/cluster_resource.gointernal/provider/column_mask_resource.gointernal/provider/data_product_resource.gointernal/provider/gcs_catalog_resource.gointernal/provider/mongodb_catalog_resource.gointernal/provider/mysql_catalog_resource.gointernal/provider/opensearch_catalog_resource.gointernal/provider/policy_resource.gointernal/provider/postgresql_catalog_resource.gointernal/provider/redshift_catalog_resource.gointernal/provider/role_resource.gointernal/provider/row_filter_resource.gointernal/provider/s3_catalog_resource.gointernal/provider/service_account_password_resource.gointernal/provider/service_account_resource.gointernal/provider/snowflake_catalog_resource.gointernal/provider/sqlserver_catalog_resource.gointernal/provider/tag_resource.go
Automated sync from terraform-provider-galaxy-generation repository.
Source commit: 00934baee3ceaa163bdde028a6efd5f4e3f6ab57
This PR contains the latest generated provider code from the generation repository.