Skip to content

Commit e3c4113

Browse files
committed
feat: support new output-only field dns_names for Cloud SQL instances
1 parent d0f8dc4 commit e3c4113

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

mmv1/third_party/terraform/services/sql/resource_sql_database_instance.go.tmpl

+42
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,28 @@ is set to true. Defaults to ZONAL.`,
10001000
Computed: true,
10011001
Description: `The dns name of the instance.`,
10021002
},
1003+
"dns_names": {
1004+
Type: schema.TypeList,
1005+
Computed: true,
1006+
Elem: &schema.Resource{
1007+
Schema: map[string]*schema.Schema{
1008+
"name": {
1009+
Type: schema.TypeString,
1010+
Computed: true,
1011+
},
1012+
"connection_type": {
1013+
Type: schema.TypeString,
1014+
Computed: true,
1015+
},
1016+
"dns_scope": {
1017+
Type: schema.TypeString,
1018+
Computed: true,
1019+
},
1020+
1021+
},
1022+
},
1023+
Description: `The list of DNS names used by this instance.`,
1024+
},
10031025
"restore_backup_context": {
10041026
Type: schema.TypeList,
10051027
Optional: true,
@@ -1794,6 +1816,9 @@ func resourceSqlDatabaseInstanceRead(d *schema.ResourceData, meta interface{}) e
17941816
if err := d.Set("dns_name", instance.DnsName); err != nil {
17951817
return fmt.Errorf("Error setting dns_name: %s", err)
17961818
}
1819+
if err := d.Set("dns_names", flattenDnsNames(instance.DnsNames)); err != nil {
1820+
return fmt.Errorf("Error setting dns_names: %s", err)
1821+
}
17971822
d.SetId(instance.Name)
17981823

17991824
return nil
@@ -2554,6 +2579,23 @@ func flattenIpAddresses(ipAddresses []*sqladmin.IpMapping) []map[string]interfac
25542579
return ips
25552580
}
25562581

2582+
2583+
func flattenDnsNames(dnsNames []*sqladmin.DnsNameMapping) []map[string]interface{} {
2584+
var dns []map[string]interface{}
2585+
2586+
for _, mapping := range dnsNames {
2587+
data := map[string]interface{}{
2588+
"name": mapping.Name,
2589+
"connection_type": mapping.ConnectionType,
2590+
"dns_scope": mapping.DnsScope,
2591+
}
2592+
2593+
dns = append(dns, data)
2594+
}
2595+
2596+
return dns
2597+
}
2598+
25572599
func flattenServerCaCerts(caCerts []*sqladmin.SslCert) []map[string]interface{} {
25582600
var certs []map[string]interface{}
25592601

mmv1/third_party/terraform/services/sql/resource_sql_database_instance_meta.yaml

+1
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'

mmv1/third_party/terraform/services/sql/resource_sql_database_instance_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -2853,6 +2853,9 @@ func TestAccSqlDatabaseInstance_useCasBasedServerCa(t *testing.T) {
28532853
Check: resource.ComposeTestCheckFunc(
28542854
resource.TestCheckResourceAttr(resourceName, "settings.0.ip_configuration.0.server_ca_mode", "GOOGLE_MANAGED_CAS_CA"),
28552855
resource.TestCheckResourceAttr(resourceName, "settings.0.ip_configuration.0.server_ca_pool", ""),
2856+
resource.TestCheckResourceAttr(resourceName, "dns_names.#", "1"),
2857+
resource.TestCheckResourceAttr(resourceName, "dns_names.0.connection_type", "PUBLIC"),
2858+
resource.TestCheckResourceAttr(resourceName, "dns_names.0.dns_scope", "INSTANCE"),
28562859
),
28572860
},
28582861
{

mmv1/third_party/terraform/website/docs/r/sql_database_instance.html.markdown

+2
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,8 @@ connection strings. For example, when connecting with [Cloud SQL Proxy](https://
575575

576576
* `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.
577577

578+
* `dns_names` - The list of DNS names used by this instance.
579+
578580
* `service_account_email_address` - The service account email address assigned to the
579581
instance.
580582

0 commit comments

Comments
 (0)