Skip to content

MMv1: Add list-resource Generation#17514

Open
BBBmau wants to merge 6 commits into
GoogleCloudPlatform:mainfrom
BBBmau:add-list-gen-mmv1
Open

MMv1: Add list-resource Generation#17514
BBBmau wants to merge 6 commits into
GoogleCloudPlatform:mainfrom
BBBmau:add-list-gen-mmv1

Conversation

@BBBmau
Copy link
Copy Markdown
Collaborator

@BBBmau BBBmau commented May 11, 2026

This PR introduces support for list resource generation in magic-modules.

It allows the ability to generate by simply opting a resource in with generate_list_resource: true

It's worth noting that in the current state it does not cover cases where test_vars need to be updated as well as the case where HCL attribute pathes are provided in test configurations. This will be addressed in a follow-up PR that focues on these two cases. Draft can be found here:

The new generated files will be the following:

  • list_*.go
  • list_*_generated_test.go
  • docs/list-resources/*.html.markdown

below is a passing test with cloud_run_service, the first list resource that will be introduced under magic-modules:

󰀵 mau  …/terraform-provider-google   main $⇣   v1.26.1   12:28   envchain GCLOUD make testacc TEST=./google/services/cloudrun TESTARGS='-run=TestAccCloudRunServiceListQuery_generated'
sh -c "'/Users/mau/Dev/terraform-provider-google/scripts/gofmtcheck.sh'"
==> Checking that code complies with gofmt requirements...
go vet
TF_ACC_REFRESH_AFTER_APPLY=1 TF_ACC=1 TF_SCHEMA_PANIC_ON_ERROR=1 go test ./google/services/cloudrun -v -run=TestAccCloudRunServiceListQuery_generated -timeout 240m -ldflags="-X=github.com/hashicorp/terraform-provider-google/version.ProviderVersion=acc"
=== RUN   TestAccCloudRunServiceListQuery_generated
=== PAUSE TestAccCloudRunServiceListQuery_generated
=== CONT  TestAccCloudRunServiceListQuery_generated
--- PASS: TestAccCloudRunServiceListQuery_generated (38.43s)
PASS
ok      github.com/hashicorp/terraform-provider-google/google/services/cloudrun 39.835s

Release Note Template for Downstream PRs (will be copied)

See Write release notes for guidance.

`google_cloud_run_service`
add list generation support in MMv1

@BBBmau BBBmau mentioned this pull request May 11, 2026
@BBBmau BBBmau requested review from NickElliot and c2thorn May 11, 2026 19:35
@modular-magician
Copy link
Copy Markdown
Collaborator

modular-magician commented May 11, 2026

Hi there, I'm the Modular magician. I've detected the following information about your changes for commit 4533c2a:

Diff report

Your PR generated the following diffs in downstream repositories:

Repository Diff Link Changes
google provider View Diff 3 files changed, 332 insertions(+)
google-beta provider View Diff 3 files changed, 332 insertions(+)

Test report

Analytics

Total Tests Passed Skipped Affected
39 29 8 2
Affected Service Packages
  • cloudrun

Learn how VCR tests work


Step 1: Replaying Mode

Action taken

Found 2 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
  • TestAccCloudRunServiceListQuery_generated
  • TestAccCloudRunService_cloudRunServiceGpuExample

View the build log


Step 2: Recording Mode

Recording Mode Replaying Rerun Test Name
✅ Log TestAccCloudRunServiceListQuery_generated
❌ Error · Log - TestAccCloudRunService_cloudRunServiceGpuExample

Caution

Issues requiring attention before PR completion

🔴 Initial Recording Failed: Some tests failed during the recording step. See the table above for details.

Please address these issues to complete your PR. If you believe these detections are incorrect or unrelated to your change, please raise the concern with your reviewer.

View the build log or the debug logs folder for detailed results.

@BBBmau, @c2thorn, @NickElliot VCR tests complete for 4533c2a!

Copy link
Copy Markdown
Contributor

@NickElliot NickElliot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you revise the unit test issue causing this PR to fail the "unused-template-check"?

@BBBmau
Copy link
Copy Markdown
Collaborator Author

BBBmau commented May 13, 2026

could you revise the unit test issue causing this PR to fail the "unused-template-check"?

@NickElliot the unused-template-check comes from the template files being introduced not being found in use within product/ directories. this makes sense that it's failing since the list template files are used within terraform.go the same as resources.

These unused-template-checks would be ignored once we have this PR merged as they'll be treated the same way as resources in magic-modules. correct me if im wrong @c2thorn

@c2thorn
Copy link
Copy Markdown
Member

c2thorn commented May 14, 2026

@NickElliot the unused-template-check comes from the template files being introduced not being found in use within product/ directories. this makes sense that it's failing since the list template files are used within terraform.go the same as resources.

These unused-template-checks would be ignored once we have this PR merged as they'll be treated the same way as resources in magic-modules. correct me if im wrong @c2thorn

@BBBmau I don't think the tool correctly recognizes template files that aren't meant to be referenced directly in YAML files. I think files like this would need to be ignored in https://github.com/GoogleCloudPlatform/magic-modules/blob/main/tools/template-check/cmd/unusedtmpl.go#L123. Can either @shuyama1 or @iyabchen confirm?

I'm assuming if we just merge it won't fail downstream, but I'm not sure.

Copy link
Copy Markdown
Member

@c2thorn c2thorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very minor

Comment thread mmv1/api/resource.go
if len(markers) > 0 {
keys = append(keys, markers[len(markers)-1][1])
}
return keys
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be length checking keys here? if for some reason it's zero, should it just go ahead and error out instead of propagating through?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think a length check is necessary since we do that within the Capture function. in generated resources the capture method takes the value returned from `ListResultDisplayNameKeyStrings1

func (c *ListDisplayName) Capture(resourceAddr string, attrCandidates []string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[resourceAddr]
if !ok {
return fmt.Errorf("resource not found in state: %s", resourceAddr)
}
for _, k := range attrCandidates {
if v, ok := rs.Primary.Attributes[k]; ok && v != "" {
c.value = v
return nil
}
}
return fmt.Errorf("no display name attribute found in state for resource %s; tried %v", resourceAddr, attrCandidates)
}
}

Comment thread mmv1/api/resource.go

func (r Resource) ListResultDisplayNameKeyStrings() []string {
var keys []string
if slices.ContainsFunc(r.RootProperties(), func(p *Type) bool { return p.Name == "display_name" }) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe being able to override this in the YAML could be a useful feature for some resources. this is probably the best default

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't run into a resource where we needed to explicitly set the display_name for list representation. We can add in a list_display_name_override field in the event that we do need this for a specific resource. I'd lean towards adding this once a resource does come up that requires this.

Comment thread mmv1/templates/terraform/list_resource.go.tmpl Outdated
}.Register()
}

var _ list.ListResource = &{{ $.ResourceName -}}ListResource{}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to your PR, but why is the official name a list RESOURCE

In my mind resources vs data sources were separated by the CUD parts of CRUD

isn't this more of a list data source? :)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good question, it's been tricky navigating naming since i do agree we aren't technically creating a resource but more calling existing resources (which exactly matches what data source is)

List Source probably would've been better? Reviewed the list resources docs and mentions the following

List resources are an abstraction that allows Terraform to search for a specific resource type within a given scope, for example listing all EC2 instances within an AWS account or all virtual networks within a resource group. Taking a list configuration as input, remote objects are retrieved and returned to Terraform as list result data which is displayed to the user.

@@ -0,0 +1,123 @@
// Copyright IBM Corp. 2014, 2026
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apache license header?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

@@ -0,0 +1,99 @@
{{ define "listResourceMethod" }}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This template looks consistent with the handwritten resource

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI i'll be pushing one more change to this once this PR gets merged:

@modular-magician
Copy link
Copy Markdown
Collaborator

modular-magician commented May 15, 2026

Hi there, I'm the Modular magician. I've detected the following information about your changes for commit 63b0154:

Diff report

Your PR generated the following diffs in downstream repositories:

Repository Diff Link Changes
google provider View Diff 3 files changed, 332 insertions(+)
google-beta provider View Diff 3 files changed, 332 insertions(+)

Test report

Analytics

Total Tests Passed Skipped Affected
39 30 8 1
Affected Service Packages
  • cloudrun

Learn how VCR tests work


Step 1: Replaying Mode

Action taken

Found 1 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
  • TestAccCloudRunService_cloudRunServiceGpuExample

View the build log


Step 2: Recording Mode

Recording Mode Replaying Rerun Test Name
❌ Error · Log - TestAccCloudRunService_cloudRunServiceGpuExample

Caution

Issues requiring attention before PR completion

🔴 Initial Recording Failed: Some tests failed during the recording step. See the table above for details.

Please address these issues to complete your PR. If you believe these detections are incorrect or unrelated to your change, please raise the concern with your reviewer.

View the build log or the debug logs folder for detailed results.

@BBBmau VCR tests complete for 63b0154!

@modular-magician
Copy link
Copy Markdown
Collaborator

modular-magician commented May 15, 2026

Hi there, I'm the Modular magician. I've detected the following information about your changes for commit 711b9b7:

Diff report

Your PR generated the following diffs in downstream repositories:

Repository Diff Link Changes
google provider View Diff 3 files changed, 332 insertions(+)
google-beta provider View Diff 3 files changed, 332 insertions(+)

Test report

Analytics

Total Tests Passed Skipped Affected
39 30 8 1
Affected Service Packages
  • cloudrun

Learn how VCR tests work


Step 1: Replaying Mode

Action taken

Found 1 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
  • TestAccCloudRunService_cloudRunServiceGpuExample

View the build log


Step 2: Recording Mode

Recording Mode Replaying Rerun Test Name
❌ Error · Log - TestAccCloudRunService_cloudRunServiceGpuExample

Caution

Issues requiring attention before PR completion

🔴 Initial Recording Failed: Some tests failed during the recording step. See the table above for details.

Please address these issues to complete your PR. If you believe these detections are incorrect or unrelated to your change, please raise the concern with your reviewer.

View the build log or the debug logs folder for detailed results.

@BBBmau VCR tests complete for 711b9b7!

@BBBmau BBBmau requested review from NickElliot and c2thorn May 15, 2026 16:46
@shuyama1
Copy link
Copy Markdown
Member

shuyama1 commented May 15, 2026

@NickElliot the unused-template-check comes from the template files being introduced not being found in use within product/ directories. this makes sense that it's failing since the list template files are used within terraform.go the same as resources.
These unused-template-checks would be ignored once we have this PR merged as they'll be treated the same way as resources in magic-modules. correct me if im wrong @c2thorn

@BBBmau I don't think the tool correctly recognizes template files that aren't meant to be referenced directly in YAML files. I think files like this would need to be ignored in main/tools/template-check/cmd/unusedtmpl.go#L123. Can either @shuyama1 or @iyabchen confirm?

I'm assuming if we just merge it won't fail downstream, but I'm not sure.

Thanks for flagging! Yeah, this type of template files should probably be excluded from this check. This is non blocking and I'll look into how to fix it. The check only targets new changes, so merging this won't break other PRs. Sorry for the noise.

@shuyama1
Copy link
Copy Markdown
Member

Created #17594 to fix the unused-template-check

@modular-magician
Copy link
Copy Markdown
Collaborator

modular-magician commented May 19, 2026

Hi there, I'm the Modular magician. I've detected the following information about your changes for commit 4bb46c3:

Diff report

Your PR generated the following diffs in downstream repositories:

Repository Diff Link Changes
google provider View Diff 3 files changed, 332 insertions(+)
google-beta provider View Diff 3 files changed, 332 insertions(+)

Test report

Analytics

Total Tests Passed Skipped Affected
39 30 8 1
Affected Service Packages
  • cloudrun

Learn how VCR tests work


Step 1: Replaying Mode

Action taken

Found 1 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit.

Click here to see the affected tests
  • TestAccCloudRunService_cloudRunServiceGpuExample

View the replaying VCR build log


Step 2: Recording Mode

Recording Mode Replaying Rerun Test Name
❌ Error · Log - TestAccCloudRunService_cloudRunServiceGpuExample

Caution

Issues requiring attention before PR completion

🔴 Initial Recording Failed: Some tests failed during the recording step. See the table above for details.

Please address these issues to complete your PR. If you believe these detections are incorrect or unrelated to your change, please raise the concern with your reviewer.

View the recording VCR build log or the debug logs folder for detailed results.

@BBBmau, @c2thorn, @NickElliot VCR tests complete for 4bb46c3!

@modular-magician modular-magician added the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label May 19, 2026
@BBBmau BBBmau force-pushed the add-list-gen-mmv1 branch from 151f0a1 to c2e4616 Compare May 19, 2026 20:41
@BBBmau
Copy link
Copy Markdown
Collaborator Author

BBBmau commented May 19, 2026

Thanks @shuyama1 ! PR ready for review once more after rebase and updates to list_method.go.tmpl to include Resource in ListPagesOpts

@modular-magician modular-magician removed the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label May 19, 2026
@BBBmau BBBmau force-pushed the add-list-gen-mmv1 branch from b1b4e5d to f146f4c Compare May 19, 2026 20:45
@modular-magician
Copy link
Copy Markdown
Collaborator

modular-magician commented May 19, 2026

Hi there, I'm the Modular magician. I've detected the following information about your changes for commit b1b4e5d:

Diff report

Your PR generated the following diffs in downstream repositories:

Repository Diff Link Changes
google provider View Diff 3 files changed, 333 insertions(+)
google-beta provider View Diff 3 files changed, 333 insertions(+)

Test report

Analytics

Total Tests Passed Skipped Affected
39 30 8 1
Affected Service Packages
  • cloudrun

Learn how VCR tests work


Step 1: Replaying Mode

Action taken

Found 1 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit.

Click here to see the affected tests
  • TestAccCloudRunService_cloudRunServiceGpuExample

View the replaying VCR build log


Step 2: Recording Mode

Recording Mode Replaying Rerun Test Name
❌ Error · Log - TestAccCloudRunService_cloudRunServiceGpuExample

Caution

Issues requiring attention before PR completion

🔴 Initial Recording Failed: Some tests failed during the recording step. See the table above for details.

Please address these issues to complete your PR. If you believe these detections are incorrect or unrelated to your change, please raise the concern with your reviewer.

View the recording VCR build log or the debug logs folder for detailed results.

@BBBmau, @c2thorn, @NickElliot VCR tests complete for b1b4e5d!

@modular-magician
Copy link
Copy Markdown
Collaborator

modular-magician commented May 19, 2026

Hi there, I'm the Modular magician. I've detected the following information about your changes for commit f146f4c:

Diff report

Your PR generated the following diffs in downstream repositories:

Repository Diff Link Changes
google provider View Diff 3 files changed, 333 insertions(+)
google-beta provider View Diff 3 files changed, 333 insertions(+)

Test report

Analytics

Total Tests Passed Skipped Affected
39 30 8 1
Affected Service Packages
  • cloudrun

Learn how VCR tests work


Step 1: Replaying Mode

Action taken

Found 1 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit.

Click here to see the affected tests
  • TestAccCloudRunService_cloudRunServiceGpuExample

View the replaying VCR build log


Step 2: Recording Mode

Recording Mode Replaying Rerun Test Name
❌ Error · Log - TestAccCloudRunService_cloudRunServiceGpuExample

Caution

Issues requiring attention before PR completion

🔴 Initial Recording Failed: Some tests failed during the recording step. See the table above for details.

Please address these issues to complete your PR. If you believe these detections are incorrect or unrelated to your change, please raise the concern with your reviewer.

View the recording VCR build log or the debug logs folder for detailed results.

@BBBmau, @c2thorn, @NickElliot VCR tests complete for f146f4c!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants