Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding data source for App Connection resource #5025

Merged
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
3 changes: 3 additions & 0 deletions .changelog/7019.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-datasource
`google_beyondcorp_app_connection`
```
42 changes: 42 additions & 0 deletions google-beta/data_source_google_beyondcorp_app_connection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package google

import (
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func dataSourceGoogleBeyondcorpAppConnection() *schema.Resource {

dsSchema := datasourceSchemaFromResourceSchema(resourceBeyondcorpAppConnection().Schema)

addRequiredFieldsToSchema(dsSchema, "name")

addOptionalFieldsToSchema(dsSchema, "project")
addOptionalFieldsToSchema(dsSchema, "region")

return &schema.Resource{
Read: dataSourceGoogleBeyondcorpAppConnectionRead,
Schema: dsSchema,
}
}

func dataSourceGoogleBeyondcorpAppConnectionRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)

name := d.Get("name").(string)

project, err := getProject(d, config)
if err != nil {
return err
}

region, err := getRegion(d, config)
if err != nil {
return err
}

d.SetId(fmt.Sprintf("projects/%s/locations/%s/appConnections/%s", project, region, name))

return resourceBeyondcorpAppConnectionRead(d, meta)
}
117 changes: 117 additions & 0 deletions google-beta/data_source_google_beyondcorp_app_connection_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package google

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"

"testing"
)

func TestAccDataSourceGoogleBeyondcorpAppConnection_basic(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": randString(t, 10),
}

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckBeyondcorpAppConnectionDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccDataSourceGoogleBeyondcorpAppConnection_basic(context),
Check: resource.ComposeTestCheckFunc(
checkDataSourceStateMatchesResourceState("data.google_beyondcorp_app_connection.foo", "google_beyondcorp_app_connection.foo"),
),
},
},
})
}

func TestAccDataSourceGoogleBeyondcorpAppConnection_full(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": randString(t, 10),
}

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckBeyondcorpAppConnectionDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccDataSourceGoogleBeyondcorpAppConnection_full(context),
Check: resource.ComposeTestCheckFunc(
checkDataSourceStateMatchesResourceState("data.google_beyondcorp_app_connection.foo", "google_beyondcorp_app_connection.foo"),
),
},
},
})
}

func testAccDataSourceGoogleBeyondcorpAppConnection_basic(context map[string]interface{}) string {
return Nprintf(`
resource "google_service_account" "service_account" {
account_id = "tf-test-my-account%{random_suffix}"
display_name = "Test Service Account"
}

resource "google_beyondcorp_app_connector" "app_connector" {
name = "tf-test-appconnector-%{random_suffix}"
principal_info {
service_account {
email = google_service_account.service_account.email
}
}
}

resource "google_beyondcorp_app_connection" "foo" {
name = "tf-test-my-app-connection-%{random_suffix}"
type = "TCP_PROXY"
application_endpoint {
host = "foo-host"
port = 8080
}
connectors = [google_beyondcorp_app_connector.app_connector.id]
}

data "google_beyondcorp_app_connection" "foo" {
name = google_beyondcorp_app_connection.foo.name
}
`, context)
}

func testAccDataSourceGoogleBeyondcorpAppConnection_full(context map[string]interface{}) string {
return Nprintf(`
resource "google_service_account" "service_account" {
account_id = "tf-test-my-account%{random_suffix}"
display_name = "Test Service Account"
}

resource "google_beyondcorp_app_connector" "app_connector" {
name = "tf-test-appconnector-%{random_suffix}"
principal_info {
service_account {
email = google_service_account.service_account.email
}
}
}

resource "google_beyondcorp_app_connection" "foo" {
name = "tf-test-my-app-connection-%{random_suffix}"
type = "TCP_PROXY"
application_endpoint {
host = "foo-host"
port = 8080
}
connectors = [google_beyondcorp_app_connector.app_connector.id]
}

data "google_beyondcorp_app_connection" "foo" {
name = google_beyondcorp_app_connection.foo.name
project = google_beyondcorp_app_connection.foo.project
region = google_beyondcorp_app_connection.foo.region
}
`, context)
}
1 change: 1 addition & 0 deletions google-beta/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,7 @@ func Provider() *schema.Provider {
"google_active_folder": dataSourceGoogleActiveFolder(),
"google_artifact_registry_repository": dataSourceArtifactRegistryRepository(),
"google_app_engine_default_service_account": dataSourceGoogleAppEngineDefaultServiceAccount(),
"google_beyondcorp_app_connection": dataSourceGoogleBeyondcorpAppConnection(),
"google_beyondcorp_app_connector": dataSourceGoogleBeyondcorpAppConnector(),
"google_beyondcorp_app_gateway": dataSourceGoogleBeyondcorpAppGateway(),
"google_billing_account": dataSourceGoogleBillingAccount(),
Expand Down