-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Application Data Source (#10154)
Co-authored-by: Krishnan Gopal <[email protected]>
- Loading branch information
1 parent
4abde8d
commit 8a452f6
Showing
4 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
mmv1/third_party/terraform/services/apphub/data_source_apphub_application.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package apphub | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-provider-google/google/tpgresource" | ||
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func DataSourceGoogleApphubApplication() *schema.Resource { | ||
dsSchema := tpgresource.DatasourceSchemaFromResourceSchema(ResourceApphubApplication().Schema) | ||
tpgresource.AddRequiredFieldsToSchema(dsSchema, "project") | ||
tpgresource.AddRequiredFieldsToSchema(dsSchema, "application_id") | ||
tpgresource.AddRequiredFieldsToSchema(dsSchema, "location") | ||
|
||
return &schema.Resource{ | ||
Read: dataSourceGoogleApphubApplicationRead, | ||
Schema: dsSchema, | ||
} | ||
} | ||
|
||
func dataSourceGoogleApphubApplicationRead(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*transport_tpg.Config) | ||
|
||
id, err := tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/{{location}}/applications/{{application_id}}") | ||
if err != nil { | ||
return fmt.Errorf("Error constructing id: %s", err) | ||
} | ||
d.SetId(id) | ||
err = resourceApphubApplicationRead(d, meta) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err := tpgresource.SetDataSourceLabels(d); err != nil { | ||
return err | ||
} | ||
|
||
if d.Id() == "" { | ||
return fmt.Errorf("%s not found", id) | ||
} | ||
return nil | ||
} |
70 changes: 70 additions & 0 deletions
70
mmv1/third_party/terraform/services/apphub/data_source_apphub_application_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package apphub_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-provider-google/google/acctest" | ||
) | ||
|
||
func TestDataSourceApphubApplication_basic(t *testing.T) { | ||
t.Parallel() | ||
|
||
context := map[string]interface{}{ | ||
"random_suffix": acctest.RandString(t, 10), | ||
} | ||
|
||
acctest.VcrTest(t, resource.TestCase{ | ||
PreCheck: func() { acctest.AccTestPreCheck(t) }, | ||
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), | ||
CheckDestroy: testAccCheckApphubApplicationDestroyProducer(t), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testDataSourceApphubApplication_basic(context), | ||
Check: resource.ComposeTestCheckFunc( | ||
acctest.CheckDataSourceStateMatchesResourceState("data.google_apphub_application.example_data", "google_apphub_application.example"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testDataSourceApphubApplication_basic(context map[string]interface{}) string { | ||
return acctest.Nprintf(` | ||
data "google_apphub_application" "example_data" { | ||
project = google_apphub_application.example.project | ||
application_id = google_apphub_application.example.application_id | ||
location = google_apphub_application.example.location | ||
} | ||
resource "google_apphub_application" "example" { | ||
location = "us-central1" | ||
application_id = "tf-test-example-application%{random_suffix}" | ||
display_name = "Application Full New%{random_suffix}" | ||
scope { | ||
type = "REGIONAL" | ||
} | ||
attributes { | ||
environment { | ||
type = "STAGING" | ||
} | ||
criticality { | ||
type = "MISSION_CRITICAL" | ||
} | ||
business_owners { | ||
display_name = "Alice%{random_suffix}" | ||
email = "[email protected]%{random_suffix}" | ||
} | ||
developer_owners { | ||
display_name = "Bob%{random_suffix}" | ||
email = "[email protected]%{random_suffix}" | ||
} | ||
operator_owners { | ||
display_name = "Charlie%{random_suffix}" | ||
email = "[email protected]%{random_suffix}" | ||
} | ||
} | ||
} | ||
`, context) | ||
} |
26 changes: 26 additions & 0 deletions
26
mmv1/third_party/terraform/website/docs/d/apphub_application.html.markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
subcategory: "App Hub" | ||
description: |- | ||
Application is a functional grouping of Services and Workloads that helps achieve a desired end-to-end business functionality. | ||
--- | ||
|
||
# google\_apphub\_application | ||
|
||
Application is a functional grouping of Services and Workloads that helps achieve a desired end-to-end business functionality. Services and Workloads are owned by the Application. | ||
|
||
|
||
## Example Usage | ||
|
||
|
||
```hcl | ||
data "google_apphub_application" "application" { | ||
project = "project-id" | ||
application_id = "application" | ||
location = "location" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
See [google_resource_application](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/apphub_application#argument-reference) resource for details of the available attributes. | ||
|