Skip to content
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
20 changes: 6 additions & 14 deletions mmv1/api/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -2494,14 +2494,10 @@ func (r Resource) ShouldDatasourceSetAnnotations() bool {
// that should be marked as "Required".
func (r Resource) DatasourceRequiredFields() []string {
requiredFields := []string{}
uriParts := strings.Split(r.IdFormat, "/")

for _, part := range uriParts {
if strings.HasPrefix(part, "{{") && strings.HasSuffix(part, "}}") {
field := strings.TrimSuffix(strings.TrimPrefix(part, "{{"), "}}")
if field != "region" && field != "project" && field != "zone" {
requiredFields = append(requiredFields, field)
}
for _, field := range r.ExtractIdentifiers(r.IdFormat) {
if field != "region" && field != "project" && field != "zone" {
requiredFields = append(requiredFields, field)
}
}
return requiredFields
Expand All @@ -2511,14 +2507,10 @@ func (r Resource) DatasourceRequiredFields() []string {
// that should be marked as "Optional".
func (r Resource) DatasourceOptionalFields() []string {
optionalFields := []string{}
uriParts := strings.Split(r.IdFormat, "/")

for _, part := range uriParts {
if strings.HasPrefix(part, "{{") && strings.HasSuffix(part, "}}") {
field := strings.TrimSuffix(strings.TrimPrefix(part, "{{"), "}}")
if field == "region" || field == "project" || field == "zone" {
optionalFields = append(optionalFields, field)
}
for _, field := range r.ExtractIdentifiers(r.IdFormat) {
if field == "region" || field == "project" || field == "zone" {
optionalFields = append(optionalFields, field)
}
}
return optionalFields
Expand Down
10 changes: 10 additions & 0 deletions mmv1/provider/template_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ func (td *TemplateData) GenerateDocumentationFile(filePath string, resource api.
td.GenerateFile(filePath, templatePath, resource, false, templates...)
}

func (td *TemplateData) GenerateDataSourceDocumentationFile(filePath string, resource api.Resource) {
templatePath := "templates/terraform/datasource.html.markdown.tmpl"
templates := []string{
templatePath,
"templates/terraform/property_documentation.html.markdown.tmpl",
"templates/terraform/nested_property_documentation.html.markdown.tmpl",
}
td.GenerateFile(filePath, templatePath, resource, false, templates...)
}

func (td *TemplateData) GenerateTestFileLegacy(filePath string, resource api.Resource) {
templatePath := "templates/terraform/examples/base_configs/test_file.go.tmpl"
templates := []string{
Expand Down
18 changes: 13 additions & 5 deletions mmv1/provider/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ func (t *Terraform) GenerateObject(object api.Resource, outputFolder, productPat
if !object.IsExcluded() {
log.Printf("Generating %s resource", object.Name)
t.GenerateResource(object, *templateData, outputFolder, generateCode, generateDocs)
t.GenerateSingularDataSource(object, *templateData, outputFolder, generateCode, generateDocs)

if generateCode {
// log.Printf("Generating %s tests", object.Name)
t.GenerateResourceTests(object, *templateData, outputFolder)
t.GenerateResourceSweeper(object, *templateData, outputFolder)
t.GenerateSingularDataSource(object, *templateData, outputFolder)
t.GenerateSingularDataSourceTests(object, *templateData, outputFolder)
// log.Printf("Generating %s metadata", object.Name)
t.GenerateResourceMetadata(object, *templateData, outputFolder)
Expand Down Expand Up @@ -273,14 +273,22 @@ func (t *Terraform) GenerateResourceSweeperFile(object api.Resource, targetFileP
templateData.GenerateSweeperFile(targetFilePath, object)
}

func (t *Terraform) GenerateSingularDataSource(object api.Resource, templateData TemplateData, outputFolder string) {
func (t *Terraform) GenerateSingularDataSource(object api.Resource, templateData TemplateData, outputFolder string, generateCode, generateDocs bool) {
if !object.ShouldGenerateSingularDataSource() {
return
}

targetFolder := t.makeFolder(outputFolder, t.FolderName(), "services", t.Product.ApiName)
targetFilePath := path.Join(targetFolder, fmt.Sprintf("data_source_%s.go", t.ResourceGoFilename(object)))
templateData.GenerateDataSourceFile(targetFilePath, object)
if generateCode {
targetFolder := t.makeFolder(outputFolder, t.FolderName(), "services", t.Product.ApiName)
targetFilePath := path.Join(targetFolder, fmt.Sprintf("data_source_%s.go", t.ResourceGoFilename(object)))
templateData.GenerateDataSourceFile(targetFilePath, object)
}

if generateDocs {
targetFolder := t.makeFolder(outputFolder, "website", "docs", "d")
targetFilePath := path.Join(targetFolder, fmt.Sprintf("%s.html.markdown", t.FullResourceName(object)))
templateData.GenerateDataSourceDocumentationFile(targetFilePath, object)
}
}

func (t *Terraform) GenerateSingularDataSourceTestsLegacy(object api.Resource, templateData TemplateData, outputFolder string) {
Expand Down
78 changes: 78 additions & 0 deletions mmv1/templates/terraform/datasource.html.markdown.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{{- /* Copyright 2026 Google LLC. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */ -}}
---
{{$.MarkdownHeader TemplatePath}}
subcategory: "{{$.ProductMetadata.DisplayName}}"
description: |-
Get information about a {{$.ProductMetadata.DisplayName}} {{$.Name}}.
---

# {{$.TerraformName}}

Get information about a {{$.ProductMetadata.DisplayName}} {{$.Name}}.
{{ if eq $.MinVersion "beta"}}
~> **Warning:** This datasource is in beta, and should be used with the terraform-provider-google-beta provider.
See [Provider Versions](../guides/provider_versions.html.markdown) for more details on beta resources.
{{- end }}
{{ if and $.References.Api (index $.References.Guides "Official Documentation") }}
For more information see the [official documentation]({{index $.References.Guides "Official Documentation"}}) and
the [API]({{$.References.Api}}).
{{- end }}

## Example Usage

```hcl
{{- if $.Samples }}
{{- $sample := index $.Samples 0 }}
data "{{$.TerraformName}}" "default" {
{{- if eq $.MinVersionObj.Name "beta" }}
provider = google-beta
{{- end }}
{{- range $fieldName := $.DatasourceRequiredFields }}
{{ $fieldName }} = {{ $sample.ResourceType $.TerraformName }}.{{ $sample.PrimaryResourceId }}.{{ $fieldName }}
{{- end }}
}
{{- end }}
```

## Argument Reference

The following arguments are supported:

{{ "" }}
{{ "" }}
{{- range $p := $.AllUserProperties }}
{{- range $field := $.DatasourceRequiredFields }}
{{- if eq (underscore $p.Name) (underscore $field) }}
{{- trimTemplate "property_documentation.html.markdown.tmpl" $p -}}
{{- end }}
{{- end }}
{{- end }}
{{ "" }}
{{- range $p := $.AllUserProperties }}
{{- range $field := $.DatasourceOptionalFields }}
{{- if eq (underscore $p.Name) (underscore $field) }}
{{- trimTemplate "property_documentation.html.markdown.tmpl" $p -}}
{{- end }}
{{- end }}
{{- end }}
{{- if or (contains $.BaseUrl "{{project}}") (contains $.CreateUrl "{{project}}")}}
* `project` - (Optional) The ID of the project in which the resource belongs.
If it is not provided, the provider project is used.
{{ "" }}
{{- end }}

## Attributes Reference

See [{{$.TerraformName}}](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/{{replaceAll $.TerraformName "google_" ""}}#argument-reference) resource for details of the available attributes.

This file was deleted.

34 changes: 0 additions & 34 deletions mmv1/third_party/terraform/website/docs/d/iap_client.html.markdown

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading