Skip to content

Commit c19193b

Browse files
feat: datastream sql server connection profile/stream from beta to GA (#11159) (#18732)
[upstream:877e85c8656cc0bc2d4866c65f571dc5db76edda] Signed-off-by: Modular Magician <[email protected]>
1 parent da78acd commit c19193b

File tree

5 files changed

+2433
-772
lines changed

5 files changed

+2433
-772
lines changed

.changelog/11159.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
```release-note:enhancement
2+
datastream: promoted `sql_server_profile` field in `google_datastream_connection_profile` resource from beta to GA
3+
```
4+
```release-note:enhancement
5+
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
6+
```

google/services/datastream/resource_datastream_connection_profile.go

+183-5
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func ResourceDatastreamConnectionProfile() *schema.Resource {
8080
Elem: &schema.Resource{
8181
Schema: map[string]*schema.Schema{},
8282
},
83-
ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "bigquery_profile", "postgresql_profile"},
83+
ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "bigquery_profile", "postgresql_profile", "sql_server_profile"},
8484
},
8585
"create_without_validation": {
8686
Type: schema.TypeBool,
@@ -151,7 +151,7 @@ func ResourceDatastreamConnectionProfile() *schema.Resource {
151151
},
152152
},
153153
},
154-
ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "bigquery_profile", "postgresql_profile"},
154+
ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "bigquery_profile", "postgresql_profile", "sql_server_profile"},
155155
},
156156
"labels": {
157157
Type: schema.TypeMap,
@@ -245,7 +245,7 @@ If this field is used then the 'client_certificate' and the
245245
},
246246
},
247247
},
248-
ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "bigquery_profile", "postgresql_profile"},
248+
ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "bigquery_profile", "postgresql_profile", "sql_server_profile"},
249249
},
250250
"oracle_profile": {
251251
Type: schema.TypeList,
@@ -289,7 +289,7 @@ If this field is used then the 'client_certificate' and the
289289
},
290290
},
291291
},
292-
ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "bigquery_profile", "postgresql_profile"},
292+
ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "bigquery_profile", "postgresql_profile", "sql_server_profile"},
293293
},
294294
"postgresql_profile": {
295295
Type: schema.TypeList,
@@ -327,7 +327,7 @@ If this field is used then the 'client_certificate' and the
327327
},
328328
},
329329
},
330-
ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "bigquery_profile", "postgresql_profile"},
330+
ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "bigquery_profile", "postgresql_profile", "sql_server_profile"},
331331
},
332332
"private_connectivity": {
333333
Type: schema.TypeList,
@@ -345,6 +345,44 @@ If this field is used then the 'client_certificate' and the
345345
},
346346
ConflictsWith: []string{"forward_ssh_connectivity"},
347347
},
348+
"sql_server_profile": {
349+
Type: schema.TypeList,
350+
Optional: true,
351+
Description: `SQL Server database profile.`,
352+
MaxItems: 1,
353+
Elem: &schema.Resource{
354+
Schema: map[string]*schema.Schema{
355+
"database": {
356+
Type: schema.TypeString,
357+
Required: true,
358+
Description: `Database for the SQL Server connection.`,
359+
},
360+
"hostname": {
361+
Type: schema.TypeString,
362+
Required: true,
363+
Description: `Hostname for the SQL Server connection.`,
364+
},
365+
"password": {
366+
Type: schema.TypeString,
367+
Required: true,
368+
Description: `Password for the SQL Server connection.`,
369+
Sensitive: true,
370+
},
371+
"username": {
372+
Type: schema.TypeString,
373+
Required: true,
374+
Description: `Username for the SQL Server connection.`,
375+
},
376+
"port": {
377+
Type: schema.TypeInt,
378+
Optional: true,
379+
Description: `Port for the SQL Server connection.`,
380+
Default: 1433,
381+
},
382+
},
383+
},
384+
ExactlyOneOf: []string{"oracle_profile", "gcs_profile", "mysql_profile", "bigquery_profile", "postgresql_profile", "sql_server_profile"},
385+
},
348386
"effective_labels": {
349387
Type: schema.TypeMap,
350388
Computed: true,
@@ -418,6 +456,12 @@ func resourceDatastreamConnectionProfileCreate(d *schema.ResourceData, meta inte
418456
} else if v, ok := d.GetOkExists("postgresql_profile"); !tpgresource.IsEmptyValue(reflect.ValueOf(postgresqlProfileProp)) && (ok || !reflect.DeepEqual(v, postgresqlProfileProp)) {
419457
obj["postgresqlProfile"] = postgresqlProfileProp
420458
}
459+
sqlServerProfileProp, err := expandDatastreamConnectionProfileSqlServerProfile(d.Get("sql_server_profile"), d, config)
460+
if err != nil {
461+
return err
462+
} else if v, ok := d.GetOkExists("sql_server_profile"); !tpgresource.IsEmptyValue(reflect.ValueOf(sqlServerProfileProp)) && (ok || !reflect.DeepEqual(v, sqlServerProfileProp)) {
463+
obj["sqlServerProfile"] = sqlServerProfileProp
464+
}
421465
forwardSshConnectivityProp, err := expandDatastreamConnectionProfileForwardSshConnectivity(d.Get("forward_ssh_connectivity"), d, config)
422466
if err != nil {
423467
return err
@@ -573,6 +617,9 @@ func resourceDatastreamConnectionProfileRead(d *schema.ResourceData, meta interf
573617
if err := d.Set("postgresql_profile", flattenDatastreamConnectionProfilePostgresqlProfile(res["postgresqlProfile"], d, config)); err != nil {
574618
return fmt.Errorf("Error reading ConnectionProfile: %s", err)
575619
}
620+
if err := d.Set("sql_server_profile", flattenDatastreamConnectionProfileSqlServerProfile(res["sqlServerProfile"], d, config)); err != nil {
621+
return fmt.Errorf("Error reading ConnectionProfile: %s", err)
622+
}
576623
if err := d.Set("forward_ssh_connectivity", flattenDatastreamConnectionProfileForwardSshConnectivity(res["forwardSshConnectivity"], d, config)); err != nil {
577624
return fmt.Errorf("Error reading ConnectionProfile: %s", err)
578625
}
@@ -641,6 +688,12 @@ func resourceDatastreamConnectionProfileUpdate(d *schema.ResourceData, meta inte
641688
} else if v, ok := d.GetOkExists("postgresql_profile"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, postgresqlProfileProp)) {
642689
obj["postgresqlProfile"] = postgresqlProfileProp
643690
}
691+
sqlServerProfileProp, err := expandDatastreamConnectionProfileSqlServerProfile(d.Get("sql_server_profile"), d, config)
692+
if err != nil {
693+
return err
694+
} else if v, ok := d.GetOkExists("sql_server_profile"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, sqlServerProfileProp)) {
695+
obj["sqlServerProfile"] = sqlServerProfileProp
696+
}
644697
forwardSshConnectivityProp, err := expandDatastreamConnectionProfileForwardSshConnectivity(d.Get("forward_ssh_connectivity"), d, config)
645698
if err != nil {
646699
return err
@@ -693,6 +746,10 @@ func resourceDatastreamConnectionProfileUpdate(d *schema.ResourceData, meta inte
693746
updateMask = append(updateMask, "postgresqlProfile")
694747
}
695748

749+
if d.HasChange("sql_server_profile") {
750+
updateMask = append(updateMask, "sqlServerProfile")
751+
}
752+
696753
if d.HasChange("forward_ssh_connectivity") {
697754
updateMask = append(updateMask, "forwardSshConnectivity")
698755
}
@@ -1089,6 +1146,60 @@ func flattenDatastreamConnectionProfilePostgresqlProfileDatabase(v interface{},
10891146
return v
10901147
}
10911148

1149+
func flattenDatastreamConnectionProfileSqlServerProfile(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1150+
if v == nil {
1151+
return nil
1152+
}
1153+
original := v.(map[string]interface{})
1154+
if len(original) == 0 {
1155+
return nil
1156+
}
1157+
transformed := make(map[string]interface{})
1158+
transformed["hostname"] =
1159+
flattenDatastreamConnectionProfileSqlServerProfileHostname(original["hostname"], d, config)
1160+
transformed["port"] =
1161+
flattenDatastreamConnectionProfileSqlServerProfilePort(original["port"], d, config)
1162+
transformed["username"] =
1163+
flattenDatastreamConnectionProfileSqlServerProfileUsername(original["username"], d, config)
1164+
transformed["password"] =
1165+
flattenDatastreamConnectionProfileSqlServerProfilePassword(original["password"], d, config)
1166+
transformed["database"] =
1167+
flattenDatastreamConnectionProfileSqlServerProfileDatabase(original["database"], d, config)
1168+
return []interface{}{transformed}
1169+
}
1170+
func flattenDatastreamConnectionProfileSqlServerProfileHostname(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1171+
return v
1172+
}
1173+
1174+
func flattenDatastreamConnectionProfileSqlServerProfilePort(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1175+
// Handles the string fixed64 format
1176+
if strVal, ok := v.(string); ok {
1177+
if intVal, err := tpgresource.StringToFixed64(strVal); err == nil {
1178+
return intVal
1179+
}
1180+
}
1181+
1182+
// number values are represented as float64
1183+
if floatVal, ok := v.(float64); ok {
1184+
intVal := int(floatVal)
1185+
return intVal
1186+
}
1187+
1188+
return v // let terraform core handle it otherwise
1189+
}
1190+
1191+
func flattenDatastreamConnectionProfileSqlServerProfileUsername(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1192+
return v
1193+
}
1194+
1195+
func flattenDatastreamConnectionProfileSqlServerProfilePassword(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1196+
return d.Get("sql_server_profile.0.password")
1197+
}
1198+
1199+
func flattenDatastreamConnectionProfileSqlServerProfileDatabase(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1200+
return v
1201+
}
1202+
10921203
func flattenDatastreamConnectionProfileForwardSshConnectivity(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
10931204
if v == nil {
10941205
return nil
@@ -1525,6 +1636,73 @@ func expandDatastreamConnectionProfilePostgresqlProfileDatabase(v interface{}, d
15251636
return v, nil
15261637
}
15271638

1639+
func expandDatastreamConnectionProfileSqlServerProfile(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1640+
l := v.([]interface{})
1641+
if len(l) == 0 || l[0] == nil {
1642+
return nil, nil
1643+
}
1644+
raw := l[0]
1645+
original := raw.(map[string]interface{})
1646+
transformed := make(map[string]interface{})
1647+
1648+
transformedHostname, err := expandDatastreamConnectionProfileSqlServerProfileHostname(original["hostname"], d, config)
1649+
if err != nil {
1650+
return nil, err
1651+
} else if val := reflect.ValueOf(transformedHostname); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1652+
transformed["hostname"] = transformedHostname
1653+
}
1654+
1655+
transformedPort, err := expandDatastreamConnectionProfileSqlServerProfilePort(original["port"], d, config)
1656+
if err != nil {
1657+
return nil, err
1658+
} else if val := reflect.ValueOf(transformedPort); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1659+
transformed["port"] = transformedPort
1660+
}
1661+
1662+
transformedUsername, err := expandDatastreamConnectionProfileSqlServerProfileUsername(original["username"], d, config)
1663+
if err != nil {
1664+
return nil, err
1665+
} else if val := reflect.ValueOf(transformedUsername); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1666+
transformed["username"] = transformedUsername
1667+
}
1668+
1669+
transformedPassword, err := expandDatastreamConnectionProfileSqlServerProfilePassword(original["password"], d, config)
1670+
if err != nil {
1671+
return nil, err
1672+
} else if val := reflect.ValueOf(transformedPassword); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1673+
transformed["password"] = transformedPassword
1674+
}
1675+
1676+
transformedDatabase, err := expandDatastreamConnectionProfileSqlServerProfileDatabase(original["database"], d, config)
1677+
if err != nil {
1678+
return nil, err
1679+
} else if val := reflect.ValueOf(transformedDatabase); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1680+
transformed["database"] = transformedDatabase
1681+
}
1682+
1683+
return transformed, nil
1684+
}
1685+
1686+
func expandDatastreamConnectionProfileSqlServerProfileHostname(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1687+
return v, nil
1688+
}
1689+
1690+
func expandDatastreamConnectionProfileSqlServerProfilePort(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1691+
return v, nil
1692+
}
1693+
1694+
func expandDatastreamConnectionProfileSqlServerProfileUsername(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1695+
return v, nil
1696+
}
1697+
1698+
func expandDatastreamConnectionProfileSqlServerProfilePassword(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1699+
return v, nil
1700+
}
1701+
1702+
func expandDatastreamConnectionProfileSqlServerProfileDatabase(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1703+
return v, nil
1704+
}
1705+
15281706
func expandDatastreamConnectionProfileForwardSshConnectivity(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
15291707
l := v.([]interface{})
15301708
if len(l) == 0 || l[0] == nil {

0 commit comments

Comments
 (0)