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

Update bq connection types from v1 api #6025

Merged
merged 11 commits into from
May 19, 2022
Merged
99 changes: 88 additions & 11 deletions mmv1/products/bigqueryconnection/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ objects:
references: !ruby/object:Api::Resource::ReferenceLinks
guides:
"Cloud SQL federated queries": "https://cloud.google.com/bigquery/docs/cloud-sql-federated-queries"
api: "https://cloud.google.com/bigquery/docs/reference/bigqueryconnection/rest/v1beta1/projects.locations.connections/create"
api: "https://cloud.google.com/bigquery/docs/reference/bigqueryconnection/rest/v1/projects.locations.connections/create"
properties:
- !ruby/object:Api::Type::String
name: name
Expand All @@ -56,37 +56,41 @@ objects:
required: false
input: true
url_param_only: true
default_value: US
description: |-
The geographic location where the connection should reside.
Cloud SQL instance must be in the same location as the connection
with following exceptions: Cloud SQL us-central1 maps to BigQuery US, Cloud SQL europe-west1 maps to BigQuery EU.
Examples: US, EU, asia-northeast1, us-central1, europe-west1. The default value is US.
Examples: US, EU, asia-northeast1, us-central1, europe-west1.
Spanner Connections same as spanner region
AWS allowed regions are aws-us-east-1
Azure allowed regions are azure-eastus2
- !ruby/object:Api::Type::String
name: 'friendlyName'
description: A descriptive name for the connection
- !ruby/object:Api::Type::String
name: 'description'
description: A descriptive description for the connection
- !ruby/object:Api::Type::Boolean
name: 'hasCredential'
name: 'hasCredential'
output: true
description: |
True if the connection has credential assigned.
True if the connection has credential assigned.
- !ruby/object:Api::Type::NestedObject
name: 'cloudSql'
exactly_one_of:
- cloud_sql
- aws
- azure
- cloud_spanner
- cloud_resource
description: Cloud SQL properties.
properties:
- !ruby/object:Api::Type::String
name: 'instanceId'
description: Cloud SQL instance ID in the form project:location:instance.
description: Cloud SQL instance ID in the form project:location:instance.
required: true
- !ruby/object:Api::Type::String
name: 'database'
description: Database name.
description: Database name.
required: true
- !ruby/object:Api::Type::NestedObject
name: credential
Expand All @@ -110,14 +114,87 @@ objects:
- :POSTGRES
- :MYSQL
- !ruby/object:Api::Type::NestedObject
name: 'cloudResource'
name: aws
description: Connection properties specific to Amazon Web Services.
exactly_one_of:
- cloud_sql
- aws
- azure
- cloud_spanner
- cloud_resource
properties:
- !ruby/object:Api::Type::NestedObject
name: accessRole
description: Authentication using Google owned service account to assume into customer's AWS IAM Role.
required: true
properties:
- !ruby/object:Api::Type::String
name: iamRoleId
description: The user’s AWS IAM Role that trusts the Google-owned AWS IAM user Connection.
required: true
- !ruby/object:Api::Type::String
name: identity
description: A unique Google-owned and Google-generated identity for the Connection. This identity will be used to access the user's AWS IAM Role.
output: true
- !ruby/object:Api::Type::NestedObject
name: azure
description: Container for connection properties specific to Azure.
exactly_one_of:
- cloud_sql
- aws
- azure
- cloud_spanner
- cloud_resource
properties:
- !ruby/object:Api::Type::String
name: 'application'
description: The name of the Azure Active Directory Application.
output: true
- !ruby/object:Api::Type::String
name: 'clientId'
output: true
description: The client id of the Azure Active Directory Application.
- !ruby/object:Api::Type::String
name: 'objectId'
output: true
description: The object id of the Azure Active Directory Application.
- !ruby/object:Api::Type::String
name: 'customerTenantId'
description: The id of customer's directory that host the data.
required: true
- !ruby/object:Api::Type::String
name: 'redirectUri'
output: true
description: The URL user will be redirected to after granting consent during connection setup.
- !ruby/object:Api::Type::NestedObject
name: cloudSpanner
description: Connection properties specific to Cloud Spanner
exactly_one_of:
- cloud_sql
- aws
- azure
- cloud_spanner
- cloud_resource
properties:
- !ruby/object:Api::Type::String
name: 'database'
description: Cloud Spanner database in the form `project/instance/database'
required: true
- !ruby/object:Api::Type::Boolean
name: 'useParallelism'
description: If parallelism should be used when reading from Cloud Spanner
- !ruby/object:Api::Type::NestedObject
name: cloudResource
description: Container for connection properties for delegation of access to GCP resources.
exactly_one_of:
- cloud_sql
- aws
- azure
- cloud_spanner
- cloud_resource
description: Cloud Resource properties.
send_empty_value: true
properties:
- !ruby/object:Api::Type::String
name: serviceAccountId
name: 'serviceAccountId'
description: The account ID of the service created for the purpose of this connection.
output: true
21 changes: 21 additions & 0 deletions mmv1/products/bigqueryconnection/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,27 @@ overrides: !ruby/object:Overrides::ResourceOverrides
primary_resource_id: "connection"
vars:
connection_id: "my-connection"
- !ruby/object:Provider::Terraform::Examples
name: "bigquery_connection_aws"
pull_external: true
primary_resource_id: "connection"
vars:
connection_id: "my-connection"
iam_role_id: "arn:aws:iam::999999999999:role/omnirole"
- !ruby/object:Provider::Terraform::Examples
name: "bigquery_connection_azure"
pull_external: true
primary_resource_id: "connection"
vars:
connection_id: "my-connection"
customer_tenant_id: "customer-tenant-id"
- !ruby/object:Provider::Terraform::Examples
name: "bigquery_connection_cloudspanner"
pull_external: true
primary_resource_id: "connection"
vars:
connection_id: "my-connection"
database: "projects/project/instances/instance/databases/database"
# This is for copying files over
files: !ruby/object:Provider::Config::Files
# These files have templating (ERB) code that will be run.
Expand Down
11 changes: 11 additions & 0 deletions mmv1/templates/terraform/examples/bigquery_connection_aws.tf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
resource "google_bigquery_connection" "<%= ctx[:primary_resource_id] %>" {
connection_id = "<%= ctx[:vars]['connection_id'] %>"
location = "aws-us-east-1"
friendly_name = "👋"
description = "a riveting description"
aws {
access_role {
iam_role_id = "<%= ctx[:vars]['iam_role_id'] %>"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
resource "google_bigquery_connection" "<%= ctx[:primary_resource_id] %>" {
connection_id = "<%= ctx[:vars]['connection_id'] %>"
location = "azure-eastus2"
friendly_name = "👋"
description = "a riveting description"
azure {
customer_tenant_id = "<%= ctx[:vars]['customer_tenant_id'] %>"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ resource "google_sql_user" "user" {
resource "google_bigquery_connection" "<%= ctx[:primary_resource_id] %>" {
friendly_name = "👋"
description = "a riveting description"
location = "US"
cloud_sql {
instance_id = google_sql_database_instance.instance.connection_name
database = google_sql_database.db.name
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
resource "google_bigquery_connection" "<%= ctx[:primary_resource_id] %>" {
connection_id = "<%= ctx[:vars]['connection_id'] %>"
location = "US"
friendly_name = "👋"
description = "a riveting description"
cloud_spanner {
database = "<%= ctx[:vars]['database'] %>"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<% autogen_exception -%>
package google
<% unless version == 'ga' -%>

import (
"testing"
Expand All @@ -18,9 +16,9 @@ func TestAccBigqueryConnectionConnection_bigqueryConnectionBasic(t *testing.T) {
}

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProvidersOiCS,
CheckDestroy: testAccCheckBigqueryConnectionConnectionDestroyProducer(t),
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckBigqueryConnectionConnectionDestroyProducer(t),
ExternalProviders: map[string]resource.ExternalProvider{
"random": {},
},
Expand All @@ -31,7 +29,7 @@ func TestAccBigqueryConnectionConnection_bigqueryConnectionBasic(t *testing.T) {
{
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"cloud_sql.0.credential.0.password", "cloud_sql.0.credential.0.username"},
ImportStateVerifyIgnore: []string{"cloud_sql.0.credential.0.password", "cloud_sql.0.credential.0.username"},
ResourceName: "google_bigquery_connection.connection",
},
{
Expand All @@ -40,7 +38,7 @@ func TestAccBigqueryConnectionConnection_bigqueryConnectionBasic(t *testing.T) {
{
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"cloud_sql.0.credential.0.password", "cloud_sql.0.credential.0.username"},
ImportStateVerifyIgnore: []string{"cloud_sql.0.credential.0.password", "cloud_sql.0.credential.0.username"},
ResourceName: "google_bigquery_connection.connection",
},
},
Expand All @@ -50,7 +48,6 @@ func TestAccBigqueryConnectionConnection_bigqueryConnectionBasic(t *testing.T) {
func testAccBigqueryConnectionConnection_bigqueryConnectionBasic(context map[string]interface{}) string {
return Nprintf(`
resource "google_sql_database_instance" "instance" {
provider = google-beta
name = "tf-test-pg-database-instance%{random_suffix}"
database_version = "POSTGRES_11"
region = "us-central1"
Expand All @@ -62,7 +59,6 @@ resource "google_sql_database_instance" "instance" {
}

resource "google_sql_database" "db" {
provider = google-beta
instance = google_sql_database_instance.instance.name
name = "db"
}
Expand All @@ -73,14 +69,12 @@ resource "random_password" "pwd" {
}

resource "google_sql_user" "user" {
provider = google-beta
name = "username"
instance = google_sql_database_instance.instance.name
password = random_password.pwd.result
}

resource "google_bigquery_connection" "connection" {
provider = google-beta
connection_id = "tf-test-my-connection%{random_suffix}"
location = "US"
friendly_name = "👋"
Expand All @@ -101,7 +95,6 @@ resource "google_bigquery_connection" "connection" {
func testAccBigqueryConnectionConnection_bigqueryConnectionBasicUpdate(context map[string]interface{}) string {
return Nprintf(`
resource "google_sql_database_instance" "instance" {
provider = google-beta
name = "tf-test-mysql-database-instance%{random_suffix}"
database_version = "MYSQL_5_6"
region = "us-central1"
Expand Down Expand Up @@ -148,6 +141,3 @@ resource "google_bigquery_connection" "connection" {
}
`, context)
}
<% else %>
// Magic Modules doesn't let us remove files - blank out beta-only common-compile files for now.
<% end -%>