Skip to content

Commit 1d46236

Browse files
feat: support new output-only field dns_names for Cloud SQL instances (#13542) (#22502)
[upstream:325ae130e01ca277bba2002f2484ac303b1af748] Signed-off-by: Modular Magician <[email protected]>
1 parent df2e463 commit 1d46236

File tree

5 files changed

+58
-1
lines changed

5 files changed

+58
-1
lines changed

.changelog/13542.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
sql: added output-only field `dns_names` to `google_sql_database_instance` resource
3+
```

google/services/sql/resource_sql_database_instance.go

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,28 @@ is set to true. Defaults to ZONAL.`,
10191019
"dns_name": {
10201020
Type: schema.TypeString,
10211021
Computed: true,
1022-
Description: `The dns name of the instance.`,
1022+
Description: `The instance-level dns name of the instance for PSC instances or public IP CAS instances.`,
1023+
},
1024+
"dns_names": {
1025+
Type: schema.TypeList,
1026+
Computed: true,
1027+
Elem: &schema.Resource{
1028+
Schema: map[string]*schema.Schema{
1029+
"name": {
1030+
Type: schema.TypeString,
1031+
Computed: true,
1032+
},
1033+
"connection_type": {
1034+
Type: schema.TypeString,
1035+
Computed: true,
1036+
},
1037+
"dns_scope": {
1038+
Type: schema.TypeString,
1039+
Computed: true,
1040+
},
1041+
},
1042+
},
1043+
Description: `The list of DNS names used by this instance. Different connection types for an instance may have different DNS names. DNS names can apply to an individual instance or a cluster of instances.`,
10231044
},
10241045
"restore_backup_context": {
10251046
Type: schema.TypeList,
@@ -1817,6 +1838,9 @@ func resourceSqlDatabaseInstanceRead(d *schema.ResourceData, meta interface{}) e
18171838
if err := d.Set("dns_name", instance.DnsName); err != nil {
18181839
return fmt.Errorf("Error setting dns_name: %s", err)
18191840
}
1841+
if err := d.Set("dns_names", flattenDnsNames(instance.DnsNames)); err != nil {
1842+
return fmt.Errorf("Error setting dns_names: %s", err)
1843+
}
18201844
d.SetId(instance.Name)
18211845

18221846
return nil
@@ -2591,6 +2615,22 @@ func flattenIpAddresses(ipAddresses []*sqladmin.IpMapping) []map[string]interfac
25912615
return ips
25922616
}
25932617

2618+
func flattenDnsNames(dnsNames []*sqladmin.DnsNameMapping) []map[string]interface{} {
2619+
var dns []map[string]interface{}
2620+
2621+
for _, mapping := range dnsNames {
2622+
data := map[string]interface{}{
2623+
"name": mapping.Name,
2624+
"connection_type": mapping.ConnectionType,
2625+
"dns_scope": mapping.DnsScope,
2626+
}
2627+
2628+
dns = append(dns, data)
2629+
}
2630+
2631+
return dns
2632+
}
2633+
25942634
func flattenServerCaCerts(caCerts []*sqladmin.SslCert) []map[string]interface{} {
25952635
var certs []map[string]interface{}
25962636

google/services/sql/resource_sql_database_instance_meta.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ fields:
1414
- field: 'database_version'
1515
- field: 'deletion_protection'
1616
- field: 'dns_name'
17+
- field: 'dns_names'
1718
- field: 'encryption_key_name'
1819
- field: 'first_ip_address'
1920
- field: 'instance_type'

google/services/sql/resource_sql_database_instance_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2891,6 +2891,9 @@ func TestAccSqlDatabaseInstance_useCasBasedServerCa(t *testing.T) {
28912891
Check: resource.ComposeTestCheckFunc(
28922892
resource.TestCheckResourceAttr(resourceName, "settings.0.ip_configuration.0.server_ca_mode", "GOOGLE_MANAGED_CAS_CA"),
28932893
resource.TestCheckResourceAttr(resourceName, "settings.0.ip_configuration.0.server_ca_pool", ""),
2894+
resource.TestCheckResourceAttr(resourceName, "dns_names.#", "1"),
2895+
resource.TestCheckResourceAttr(resourceName, "dns_names.0.connection_type", "PUBLIC"),
2896+
resource.TestCheckResourceAttr(resourceName, "dns_names.0.dns_scope", "INSTANCE"),
28942897
),
28952898
},
28962899
{

website/docs/r/sql_database_instance.html.markdown

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,16 @@ connection strings. For example, when connecting with [Cloud SQL Proxy](https://
583583

584584
* `dns_name` - The DNS name of the instance. See [Connect to an instance using Private Service Connect](https://cloud.google.com/sql/docs/mysql/configure-private-service-connect#view-summary-information-cloud-sql-instances-psc-enabled) for more details.
585585

586+
* `dns_names` - The list of DNS names used by this instance. Different connection types for an instance may have different DNS names. DNS names can apply to an individual instance or a cluster of instances.
587+
588+
* `dns_names.0.name` - The DNS name.
589+
590+
* `dns_names.0.connection_type` - The connection type of the DNS name. Can be either `PUBLIC`, `PRIVATE_SERVICES_ACCESS`, or `PRIVATE_SERVICE_CONNECT`.
591+
592+
* `dns_names.0.dns_scope` - The scope that the DNS name applies to.
593+
594+
* An `INSTANCE` DNS name applies to an individual Cloud SQL instance.
595+
586596
* `service_account_email_address` - The service account email address assigned to the
587597
instance.
588598

0 commit comments

Comments
 (0)