一键导入
tgc-add-field-to-handwritten-resource-skill
Add a new field to an existing handwritten resource in TGC. Use when you need to extend a handwritten resource.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Add a new field to an existing handwritten resource in TGC. Use when you need to extend a handwritten resource.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Skill for reviewing Magic Modules schemas. Currently covers the Enum vs. String decision via the knowledge base.
Opt resource into MMv1 list-resource generation by setting `generate_list_resource: true`, validate it locally, and open a one-resource PR against GoogleCloudPlatform/magic-modules. Invoke when the user asks to add list-resource support for a specific MMv1 resource or to enable `generate_list_resource` for an eligible resource.
Fallback workflow for general implementation and debugging tasks that do not involve creating a new resource.
Workflow specifically for creating a new resource, supporting both autogen and manual generation.
Create a Pull Request (PR) against GoogleCloudPlatform/magic-modules following repository standards, including branch management, commit formatting, mandatory release notes, pre-PR verification checks, and gh CLI commands.
Validate that changes to the generated providers don't introduce breaking changes or fields with missing tests or missing documentation. Use this skill when the user wants to check for breaking changes, missing tests, or missing documentation, or other problems in the downstream providers.
| name | tgc-add-field-to-handwritten-resource-skill |
| description | Add a new field to an existing handwritten resource in TGC. Use when you need to extend a handwritten resource. |
When you need to add a new field to an existing handwritten resource in the TGC Next pipeline, use this skill.
include_in_tgc_next: true and custom files under mmv1/third_party/tgc_next/pkg/services/), and you need to support a new configuration option or nested attribute that is currently missing from the conversion.To add a new field, you must update the schema definition, the HCL flattener, and the CAI expander, then compile and verify round-trip conversion.
Locate the Go files under mmv1/third_party/tgc_next/pkg/services/<product>/:
resource_<resource_name>.go (Schema definition)resource_<resource_name>_cai2hcl.go (Flattener)resource_<resource_name>_tfplan2cai.go (Expander)resource_<resource_name>.go)Add the schema definition of the new field to the schema definition map inside the resource function.
addons_config), find that block's schema definition and append the field to it.Example:
// In resource_<resource_name>.go
"new_field_name": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
resource_<resource_name>_cai2hcl.go)Retrieve the value from the CAI asset payload and map it to the HCL schema.
newFieldName), whereas HCL keys are snake_case (new_field_name).hclData) if the retrieved value is the same as the default value defined in the schema (e.g., if it's false for boolean, "" for string, or matches standard zero-values). This keeps the exported HCL clean and prevents unnecessary diffs.v interface{} as its parameter instead of a concrete type. Note that while standard Terraform provider flatteners often accept concrete client API structs (e.g. *container.StandardRolloutPolicy), TGC cai2hcl flatteners always decode raw JSON maps and must accept interface{} to allow safe type-assertion.Example:
// In resource_<resource_name>_cai2hcl.go
if newFieldVal, ok := apiObj["newFieldName"]; ok {
// Only set the field if it is not the default value (false)
if boolVal, ok := newFieldVal.(bool); ok && boolVal {
hclData["new_field_name"] = boolVal
}
}
// Example helper flattener function accepting interface{}
func flattenNestedConfig(v interface{}) []map[string]interface{} {
if v == nil {
return nil
}
// Safe type assertion to a map representing the JSON/API object
obj, ok := v.(map[string]interface{})
if !ok {
return nil
}
transformed := make(map[string]interface{})
if val, ok := obj["someApiField"]; ok {
transformed["some_hcl_field"] = val
}
return []map[string]interface{}{transformed}
}
resource_<resource_name>_tfplan2cai.go)Read the value from the Terraform planned resource data and map it to the API format.
d.GetOk("field_path") or d.Get("field_path") to retrieve the HCL configuration value.Example:
// In resource_<resource_name>_tfplan2cai.go
if v, ok := d.GetOk("new_field_name"); ok {
obj["newFieldName"] = v
}
make tgc OUTPUT_PATH="/path/to/your/terraform-google-conversion"
cd /path/to/your/terraform-google-conversion
make mod-clean
make build
# Run the integration tests for the resource to verify roundtrip correctness
make test-integration-local TESTPATH=./test/services/<product> TESTARGS='-run=TestAcc<ResourceName>'
WRITE_FILES=true environment variable before running tests. Inspect the generated test files under downstream test/services/<product>/:
Test_export.tf: Check that new_field_name is correctly flattened from the CAI payload.Test_roundtrip.json: Check that newFieldName is correctly expanded back into the CAI JSON payload.Test_roundtrip.tf: Check that new_field_name is present in the final roundtrip configuration.