forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding data source for App Connection resource (GoogleCloudPlatform#7019
) * Adding data source for App Connection resource * Minor formatting fix * Minor formatting fix * Addressing code review comments
- Loading branch information
1 parent
8d2432e
commit 4eace72
Showing
3 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
mmv1/third_party/terraform/data_sources/data_source_google_beyondcorp_app_connection.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,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
117
mmv1/third_party/terraform/tests/data_source_google_beyondcorp_app_connection_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,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) | ||
} |
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