Skip to content

Commit

Permalink
Add support for Application Data Source (#10154) (#17679)
Browse files Browse the repository at this point in the history
[upstream:8a452f6ad41fb7d29c59d4516539589294d87e2f]

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Mar 25, 2024
1 parent 5bfbe5e commit ba4dd7c
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/10154.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-datasource
`google_apphub_application`
```
1 change: 1 addition & 0 deletions google/provider/provider_mmv1_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,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(),
"google_beyondcorp_app_connection": beyondcorp.DataSourceGoogleBeyondcorpAppConnection(),
"google_beyondcorp_app_connector": beyondcorp.DataSourceGoogleBeyondcorpAppConnector(),
Expand Down
47 changes: 47 additions & 0 deletions google/services/apphub/data_source_apphub_application.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
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
}
72 changes: 72 additions & 0 deletions google/services/apphub/data_source_apphub_application_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
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 = "alice@google.com%{random_suffix}"
}
developer_owners {
display_name = "Bob%{random_suffix}"
email = "bob@google.com%{random_suffix}"
}
operator_owners {
display_name = "Charlie%{random_suffix}"
email = "charlie@google.com%{random_suffix}"
}
}
}
`, context)
}
26 changes: 26 additions & 0 deletions website/docs/d/apphub_application.html.markdown
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 ba4dd7c

Please sign in to comment.