Skip to content

Commit

Permalink
Add support for Application Data Source (#10154)
Browse files Browse the repository at this point in the history
Co-authored-by: Krishnan Gopal <[email protected]>
  • Loading branch information
krishnangopal1810 and Krishnan Gopal authored Mar 25, 2024
1 parent 4abde8d commit 8a452f6
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var handwrittenDatasources = map[string]*schema.Resource{
"google_artifact_registry_repository": artifactregistry.DataSourceArtifactRegistryRepository(),
"google_apphub_discovered_workload": apphub.DataSourceApphubDiscoveredWorkload(),
"google_app_engine_default_service_account": appengine.DataSourceGoogleAppEngineDefaultServiceAccount(),
"google_apphub_application": apphub.DataSourceGoogleApphubApplication(),
"google_apphub_discovered_service": apphub.DataSourceApphubDiscoveredService(),
<% unless version == 'ga' -%>
"google_backup_dr_management_server": backupdr.DataSourceGoogleCloudBackupDRService(),
Expand Down
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
}
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)
}
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.

0 comments on commit 8a452f6

Please sign in to comment.