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: support new output-only field dns_names for Cloud SQL instances #13542

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -998,8 +998,30 @@ is set to true. Defaults to ZONAL.`,
"dns_name": {
Type: schema.TypeString,
Computed: true,
Description: `The dns name of the instance.`,
Description: `The instance-level dns name of the instance for PSC instances or public IP CAS instances.`,
},
"dns_names": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
},
"connection_type": {
Type: schema.TypeString,
Computed: true,
},
"dns_scope": {
Type: schema.TypeString,
Computed: true,
},

},
},
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.`,
},
"restore_backup_context": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -1794,6 +1816,9 @@ func resourceSqlDatabaseInstanceRead(d *schema.ResourceData, meta interface{}) e
if err := d.Set("dns_name", instance.DnsName); err != nil {
return fmt.Errorf("Error setting dns_name: %s", err)
}
if err := d.Set("dns_names", flattenDnsNames(instance.DnsNames)); err != nil {
return fmt.Errorf("Error setting dns_names: %s", err)
}
d.SetId(instance.Name)

return nil
Expand Down Expand Up @@ -2554,6 +2579,23 @@ func flattenIpAddresses(ipAddresses []*sqladmin.IpMapping) []map[string]interfac
return ips
}


func flattenDnsNames(dnsNames []*sqladmin.DnsNameMapping) []map[string]interface{} {
var dns []map[string]interface{}

for _, mapping := range dnsNames {
data := map[string]interface{}{
"name": mapping.Name,
"connection_type": mapping.ConnectionType,
"dns_scope": mapping.DnsScope,
}

dns = append(dns, data)
}

return dns
}

func flattenServerCaCerts(caCerts []*sqladmin.SslCert) []map[string]interface{} {
var certs []map[string]interface{}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ fields:
- field: 'database_version'
- field: 'deletion_protection'
- field: 'dns_name'
- field: 'dns_names'
- field: 'encryption_key_name'
- field: 'first_ip_address'
- field: 'instance_type'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2853,6 +2853,9 @@ func TestAccSqlDatabaseInstance_useCasBasedServerCa(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "settings.0.ip_configuration.0.server_ca_mode", "GOOGLE_MANAGED_CAS_CA"),
resource.TestCheckResourceAttr(resourceName, "settings.0.ip_configuration.0.server_ca_pool", ""),
resource.TestCheckResourceAttr(resourceName, "dns_names.#", "1"),
resource.TestCheckResourceAttr(resourceName, "dns_names.0.connection_type", "PUBLIC"),
resource.TestCheckResourceAttr(resourceName, "dns_names.0.dns_scope", "INSTANCE"),
),
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,16 @@ connection strings. For example, when connecting with [Cloud SQL Proxy](https://

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

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

* `dns_names.0.name` - The DNS name.

* `dns_names.0.connection_type` - The connection type of the DNS name. Can be either `PUBLIC`, `PRIVATE_SERVICES_ACCESS`, or `PRIVATE_SERVICE_CONNECT`.

* `dns_names.0.dns_scope` - The scope that the DNS name applies to.

* An `INSTANCE` DNS name applies to an individual Cloud SQL instance.

* `service_account_email_address` - The service account email address assigned to the
instance.

Expand Down