| // Copyright (c) HashiCorp, Inc. |
| // SPDX-License-Identifier: MPL-2.0 |
| package compute |
| |
| import ( |
| "fmt" |
| |
| "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
| "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" |
| ) |
| |
| func DataSourceGoogleComputeRouter() *schema.Resource { |
| dsSchema := tpgresource.DatasourceSchemaFromResourceSchema(ResourceComputeRouter().Schema) |
| tpgresource.AddRequiredFieldsToSchema(dsSchema, "name") |
| tpgresource.AddRequiredFieldsToSchema(dsSchema, "network") |
| tpgresource.AddOptionalFieldsToSchema(dsSchema, "region") |
| tpgresource.AddOptionalFieldsToSchema(dsSchema, "project") |
| |
| return &schema.Resource{ |
| Read: dataSourceComputeRouterRead, |
| Schema: dsSchema, |
| } |
| } |
| |
| func dataSourceComputeRouterRead(d *schema.ResourceData, meta interface{}) error { |
| routerName := d.Get("name").(string) |
| |
| d.SetId(routerName) |
| err := resourceComputeRouterRead(d, meta) |
| if err != nil { |
| return err |
| } |
| |
| if d.Id() == "" { |
| return fmt.Errorf("%s not found", routerName) |
| } |
| return nil |
| } |