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

Added private connectivity field to datastream_connection_profile #12844

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/6651.txt
@@ -0,0 +1,3 @@
```release-note:enhancement
datastream: added `private_connectivity` field to `google_datastream_connection_profile`
```
76 changes: 76 additions & 0 deletions google/resource_datastream_connection_profile.go
Expand Up @@ -110,6 +110,7 @@ func resourceDatastreamConnectionProfile() *schema.Resource {
},
},
},
ConflictsWith: []string{"private_connectivity"},
},
"gcs_profile": {
Type: schema.TypeList,
Expand Down Expand Up @@ -306,6 +307,22 @@ If this field is used then the 'client_certificate' and the
},
ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "bigquery_profile", "postgresql_profile"},
},
"private_connectivity": {
Type: schema.TypeList,
Optional: true,
Description: `Private connectivity.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"private_connection": {
Type: schema.TypeString,
Required: true,
Description: `A reference to a private connection resource. Format: 'projects/{project}/locations/{location}/privateConnections/{name}'`,
},
},
},
ConflictsWith: []string{"forward_ssh_connectivity"},
},
"name": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -378,6 +395,12 @@ func resourceDatastreamConnectionProfileCreate(d *schema.ResourceData, meta inte
} else if v, ok := d.GetOkExists("forward_ssh_connectivity"); !isEmptyValue(reflect.ValueOf(forwardSshConnectivityProp)) && (ok || !reflect.DeepEqual(v, forwardSshConnectivityProp)) {
obj["forwardSshConnectivity"] = forwardSshConnectivityProp
}
privateConnectivityProp, err := expandDatastreamConnectionProfilePrivateConnectivity(d.Get("private_connectivity"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("private_connectivity"); !isEmptyValue(reflect.ValueOf(privateConnectivityProp)) && (ok || !reflect.DeepEqual(v, privateConnectivityProp)) {
obj["privateConnectivity"] = privateConnectivityProp
}

url, err := replaceVars(d, config, "{{DatastreamBasePath}}projects/{{project}}/locations/{{location}}/connectionProfiles?connectionProfileId={{connection_profile_id}}")
if err != nil {
Expand Down Expand Up @@ -500,6 +523,9 @@ func resourceDatastreamConnectionProfileRead(d *schema.ResourceData, meta interf
if err := d.Set("forward_ssh_connectivity", flattenDatastreamConnectionProfileForwardSshConnectivity(res["forwardSshConnectivity"], d, config)); err != nil {
return fmt.Errorf("Error reading ConnectionProfile: %s", err)
}
if err := d.Set("private_connectivity", flattenDatastreamConnectionProfilePrivateConnectivity(res["privateConnectivity"], d, config)); err != nil {
return fmt.Errorf("Error reading ConnectionProfile: %s", err)
}

return nil
}
Expand Down Expand Up @@ -568,6 +594,12 @@ func resourceDatastreamConnectionProfileUpdate(d *schema.ResourceData, meta inte
} else if v, ok := d.GetOkExists("forward_ssh_connectivity"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, forwardSshConnectivityProp)) {
obj["forwardSshConnectivity"] = forwardSshConnectivityProp
}
privateConnectivityProp, err := expandDatastreamConnectionProfilePrivateConnectivity(d.Get("private_connectivity"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("private_connectivity"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, privateConnectivityProp)) {
obj["privateConnectivity"] = privateConnectivityProp
}

url, err := replaceVars(d, config, "{{DatastreamBasePath}}projects/{{project}}/locations/{{location}}/connectionProfiles/{{connection_profile_id}}")
if err != nil {
Expand Down Expand Up @@ -608,6 +640,10 @@ func resourceDatastreamConnectionProfileUpdate(d *schema.ResourceData, meta inte
if d.HasChange("forward_ssh_connectivity") {
updateMask = append(updateMask, "forwardSshConnectivity")
}

if d.HasChange("private_connectivity") {
updateMask = append(updateMask, "privateConnectivity")
}
// updateMask is a URL parameter but not present in the schema, so replaceVars
// won't set it
url, err = addQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
Expand Down Expand Up @@ -1013,6 +1049,23 @@ func flattenDatastreamConnectionProfileForwardSshConnectivityPrivateKey(v interf
return d.Get("forward_ssh_connectivity.0.private_key")
}

func flattenDatastreamConnectionProfilePrivateConnectivity(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
return nil
}
original := v.(map[string]interface{})
if len(original) == 0 {
return nil
}
transformed := make(map[string]interface{})
transformed["private_connection"] =
flattenDatastreamConnectionProfilePrivateConnectivityPrivateConnection(original["privateConnection"], d, config)
return []interface{}{transformed}
}
func flattenDatastreamConnectionProfilePrivateConnectivityPrivateConnection(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func expandDatastreamConnectionProfileLabels(v interface{}, d TerraformResourceData, config *Config) (map[string]string, error) {
if v == nil {
return map[string]string{}, nil
Expand Down Expand Up @@ -1436,3 +1489,26 @@ func expandDatastreamConnectionProfileForwardSshConnectivityPassword(v interface
func expandDatastreamConnectionProfileForwardSshConnectivityPrivateKey(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandDatastreamConnectionProfilePrivateConnectivity(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
return nil, nil
}
raw := l[0]
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})

transformedPrivateConnection, err := expandDatastreamConnectionProfilePrivateConnectivityPrivateConnection(original["private_connection"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedPrivateConnection); val.IsValid() && !isEmptyValue(val) {
transformed["privateConnection"] = transformedPrivateConnection
}

return transformed, nil
}

func expandDatastreamConnectionProfilePrivateConnectivityPrivateConnection(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}
29 changes: 26 additions & 3 deletions google/resource_datastream_connection_profile_generated_test.go
Expand Up @@ -63,7 +63,7 @@ resource "google_datastream_connection_profile" "default" {
`, context)
}

func TestAccDatastreamConnectionProfile_datastreamConnectionProfileBigqueryExample(t *testing.T) {
func TestAccDatastreamConnectionProfile_datastreamConnectionProfileBigqueryPrivateConnectionExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
Expand All @@ -76,7 +76,7 @@ func TestAccDatastreamConnectionProfile_datastreamConnectionProfileBigqueryExamp
CheckDestroy: testAccCheckDatastreamConnectionProfileDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccDatastreamConnectionProfile_datastreamConnectionProfileBigqueryExample(context),
Config: testAccDatastreamConnectionProfile_datastreamConnectionProfileBigqueryPrivateConnectionExample(context),
},
{
ResourceName: "google_datastream_connection_profile.default",
Expand All @@ -88,14 +88,37 @@ func TestAccDatastreamConnectionProfile_datastreamConnectionProfileBigqueryExamp
})
}

func testAccDatastreamConnectionProfile_datastreamConnectionProfileBigqueryExample(context map[string]interface{}) string {
func testAccDatastreamConnectionProfile_datastreamConnectionProfileBigqueryPrivateConnectionExample(context map[string]interface{}) string {
return Nprintf(`
resource "google_datastream_private_connection" "private_connection" {
display_name = "Connection profile"
location = "us-central1"
private_connection_id = "tf-test-my-connection%{random_suffix}"

labels = {
key = "value"
}

vpc_peering_config {
vpc = google_compute_network.default.id
subnet = "10.0.0.0/29"
}
}

resource "google_compute_network" "default" {
name = "tf-test-my-network%{random_suffix}"
}

resource "google_datastream_connection_profile" "default" {
display_name = "Connection profile"
location = "us-central1"
connection_profile_id = "tf-test-my-profile%{random_suffix}"

bigquery_profile {}

private_connectivity {
private_connection = google_datastream_private_connection.private_connection.id
}
}
`, context)
}
Expand Down
38 changes: 36 additions & 2 deletions website/docs/r/datastream_connection_profile.html.markdown
Expand Up @@ -53,20 +53,43 @@ resource "google_datastream_connection_profile" "default" {
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=datastream_connection_profile_bigquery&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=datastream_connection_profile_bigquery_private_connection&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Datastream Connection Profile Bigquery
## Example Usage - Datastream Connection Profile Bigquery Private Connection


```hcl
resource "google_datastream_private_connection" "private_connection" {
display_name = "Connection profile"
location = "us-central1"
private_connection_id = "my-connection"

labels = {
key = "value"
}

vpc_peering_config {
vpc = google_compute_network.default.id
subnet = "10.0.0.0/29"
}
}

resource "google_compute_network" "default" {
name = "my-network"
}

resource "google_datastream_connection_profile" "default" {
display_name = "Connection profile"
location = "us-central1"
connection_profile_id = "my-profile"

bigquery_profile {}

private_connectivity {
private_connection = google_datastream_private_connection.private_connection.id
}
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
Expand Down Expand Up @@ -219,6 +242,11 @@ The following arguments are supported:
Forward SSH tunnel connectivity.
Structure is [documented below](#nested_forward_ssh_connectivity).

* `private_connectivity` -
(Optional)
Private connectivity.
Structure is [documented below](#nested_private_connectivity).

* `project` - (Optional) The ID of the project in which the resource belongs.
If it is not provided, the provider project is used.

Expand Down Expand Up @@ -364,6 +392,12 @@ The following arguments are supported:
SSH private key.
**Note**: This property is sensitive and will not be displayed in the plan.

<a name="nested_private_connectivity"></a>The `private_connectivity` block supports:

* `private_connection` -
(Required)
A reference to a private connection resource. Format: `projects/{project}/locations/{location}/privateConnections/{name}`

## Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:
Expand Down