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

feat: datastream sql server connection profile/stream from beta to GA #18732

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
6 changes: 6 additions & 0 deletions .changelog/11159.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
```release-note:enhancement
datastream: promoted `sql_server_profile` field in `google_datastream_connection_profile` resource from beta to GA
```
```release-note:enhancement
datastream: promoted `source_config.sql_server_source_config` and `backfill_all.sql_server_excluded_objects` fields in `google_datastream_stream` resource from beta to GA
```
188 changes: 183 additions & 5 deletions google/services/datastream/resource_datastream_connection_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func ResourceDatastreamConnectionProfile() *schema.Resource {
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{},
},
ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "bigquery_profile", "postgresql_profile"},
ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "bigquery_profile", "postgresql_profile", "sql_server_profile"},
},
"create_without_validation": {
Type: schema.TypeBool,
Expand Down Expand Up @@ -151,7 +151,7 @@ func ResourceDatastreamConnectionProfile() *schema.Resource {
},
},
},
ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "bigquery_profile", "postgresql_profile"},
ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "bigquery_profile", "postgresql_profile", "sql_server_profile"},
},
"labels": {
Type: schema.TypeMap,
Expand Down Expand Up @@ -245,7 +245,7 @@ If this field is used then the 'client_certificate' and the
},
},
},
ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "bigquery_profile", "postgresql_profile"},
ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "bigquery_profile", "postgresql_profile", "sql_server_profile"},
},
"oracle_profile": {
Type: schema.TypeList,
Expand Down Expand Up @@ -289,7 +289,7 @@ If this field is used then the 'client_certificate' and the
},
},
},
ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "bigquery_profile", "postgresql_profile"},
ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "bigquery_profile", "postgresql_profile", "sql_server_profile"},
},
"postgresql_profile": {
Type: schema.TypeList,
Expand Down Expand Up @@ -327,7 +327,7 @@ If this field is used then the 'client_certificate' and the
},
},
},
ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "bigquery_profile", "postgresql_profile"},
ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "bigquery_profile", "postgresql_profile", "sql_server_profile"},
},
"private_connectivity": {
Type: schema.TypeList,
Expand All @@ -345,6 +345,44 @@ If this field is used then the 'client_certificate' and the
},
ConflictsWith: []string{"forward_ssh_connectivity"},
},
"sql_server_profile": {
Type: schema.TypeList,
Optional: true,
Description: `SQL Server database profile.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"database": {
Type: schema.TypeString,
Required: true,
Description: `Database for the SQL Server connection.`,
},
"hostname": {
Type: schema.TypeString,
Required: true,
Description: `Hostname for the SQL Server connection.`,
},
"password": {
Type: schema.TypeString,
Required: true,
Description: `Password for the SQL Server connection.`,
Sensitive: true,
},
"username": {
Type: schema.TypeString,
Required: true,
Description: `Username for the SQL Server connection.`,
},
"port": {
Type: schema.TypeInt,
Optional: true,
Description: `Port for the SQL Server connection.`,
Default: 1433,
},
},
},
ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "bigquery_profile", "postgresql_profile", "sql_server_profile"},
},
"effective_labels": {
Type: schema.TypeMap,
Computed: true,
Expand Down Expand Up @@ -418,6 +456,12 @@ func resourceDatastreamConnectionProfileCreate(d *schema.ResourceData, meta inte
} else if v, ok := d.GetOkExists("postgresql_profile"); !tpgresource.IsEmptyValue(reflect.ValueOf(postgresqlProfileProp)) && (ok || !reflect.DeepEqual(v, postgresqlProfileProp)) {
obj["postgresqlProfile"] = postgresqlProfileProp
}
sqlServerProfileProp, err := expandDatastreamConnectionProfileSqlServerProfile(d.Get("sql_server_profile"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("sql_server_profile"); !tpgresource.IsEmptyValue(reflect.ValueOf(sqlServerProfileProp)) && (ok || !reflect.DeepEqual(v, sqlServerProfileProp)) {
obj["sqlServerProfile"] = sqlServerProfileProp
}
forwardSshConnectivityProp, err := expandDatastreamConnectionProfileForwardSshConnectivity(d.Get("forward_ssh_connectivity"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -573,6 +617,9 @@ func resourceDatastreamConnectionProfileRead(d *schema.ResourceData, meta interf
if err := d.Set("postgresql_profile", flattenDatastreamConnectionProfilePostgresqlProfile(res["postgresqlProfile"], d, config)); err != nil {
return fmt.Errorf("Error reading ConnectionProfile: %s", err)
}
if err := d.Set("sql_server_profile", flattenDatastreamConnectionProfileSqlServerProfile(res["sqlServerProfile"], d, config)); err != nil {
return fmt.Errorf("Error reading ConnectionProfile: %s", err)
}
if err := d.Set("forward_ssh_connectivity", flattenDatastreamConnectionProfileForwardSshConnectivity(res["forwardSshConnectivity"], d, config)); err != nil {
return fmt.Errorf("Error reading ConnectionProfile: %s", err)
}
Expand Down Expand Up @@ -641,6 +688,12 @@ func resourceDatastreamConnectionProfileUpdate(d *schema.ResourceData, meta inte
} else if v, ok := d.GetOkExists("postgresql_profile"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, postgresqlProfileProp)) {
obj["postgresqlProfile"] = postgresqlProfileProp
}
sqlServerProfileProp, err := expandDatastreamConnectionProfileSqlServerProfile(d.Get("sql_server_profile"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("sql_server_profile"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, sqlServerProfileProp)) {
obj["sqlServerProfile"] = sqlServerProfileProp
}
forwardSshConnectivityProp, err := expandDatastreamConnectionProfileForwardSshConnectivity(d.Get("forward_ssh_connectivity"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -693,6 +746,10 @@ func resourceDatastreamConnectionProfileUpdate(d *schema.ResourceData, meta inte
updateMask = append(updateMask, "postgresqlProfile")
}

if d.HasChange("sql_server_profile") {
updateMask = append(updateMask, "sqlServerProfile")
}

if d.HasChange("forward_ssh_connectivity") {
updateMask = append(updateMask, "forwardSshConnectivity")
}
Expand Down Expand Up @@ -1089,6 +1146,60 @@ func flattenDatastreamConnectionProfilePostgresqlProfileDatabase(v interface{},
return v
}

func flattenDatastreamConnectionProfileSqlServerProfile(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
}
original := v.(map[string]interface{})
if len(original) == 0 {
return nil
}
transformed := make(map[string]interface{})
transformed["hostname"] =
flattenDatastreamConnectionProfileSqlServerProfileHostname(original["hostname"], d, config)
transformed["port"] =
flattenDatastreamConnectionProfileSqlServerProfilePort(original["port"], d, config)
transformed["username"] =
flattenDatastreamConnectionProfileSqlServerProfileUsername(original["username"], d, config)
transformed["password"] =
flattenDatastreamConnectionProfileSqlServerProfilePassword(original["password"], d, config)
transformed["database"] =
flattenDatastreamConnectionProfileSqlServerProfileDatabase(original["database"], d, config)
return []interface{}{transformed}
}
func flattenDatastreamConnectionProfileSqlServerProfileHostname(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenDatastreamConnectionProfileSqlServerProfilePort(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
if intVal, err := tpgresource.StringToFixed64(strVal); err == nil {
return intVal
}
}

// number values are represented as float64
if floatVal, ok := v.(float64); ok {
intVal := int(floatVal)
return intVal
}

return v // let terraform core handle it otherwise
}

func flattenDatastreamConnectionProfileSqlServerProfileUsername(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenDatastreamConnectionProfileSqlServerProfilePassword(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return d.Get("sql_server_profile.0.password")
}

func flattenDatastreamConnectionProfileSqlServerProfileDatabase(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenDatastreamConnectionProfileForwardSshConnectivity(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
Expand Down Expand Up @@ -1525,6 +1636,73 @@ func expandDatastreamConnectionProfilePostgresqlProfileDatabase(v interface{}, d
return v, nil
}

func expandDatastreamConnectionProfileSqlServerProfile(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.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{})

transformedHostname, err := expandDatastreamConnectionProfileSqlServerProfileHostname(original["hostname"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedHostname); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["hostname"] = transformedHostname
}

transformedPort, err := expandDatastreamConnectionProfileSqlServerProfilePort(original["port"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedPort); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["port"] = transformedPort
}

transformedUsername, err := expandDatastreamConnectionProfileSqlServerProfileUsername(original["username"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedUsername); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["username"] = transformedUsername
}

transformedPassword, err := expandDatastreamConnectionProfileSqlServerProfilePassword(original["password"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedPassword); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["password"] = transformedPassword
}

transformedDatabase, err := expandDatastreamConnectionProfileSqlServerProfileDatabase(original["database"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedDatabase); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["database"] = transformedDatabase
}

return transformed, nil
}

func expandDatastreamConnectionProfileSqlServerProfileHostname(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandDatastreamConnectionProfileSqlServerProfilePort(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandDatastreamConnectionProfileSqlServerProfileUsername(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandDatastreamConnectionProfileSqlServerProfilePassword(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandDatastreamConnectionProfileSqlServerProfileDatabase(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandDatastreamConnectionProfileForwardSshConnectivity(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand Down
Loading