Skip to content

Commit

Permalink
Change authorized_networks to set (#733)
Browse files Browse the repository at this point in the history
  • Loading branch information
rosbo authored Nov 13, 2017
1 parent 182f878 commit 6adbdcf
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions google/resource_sql_database_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@ import (
"google.golang.org/api/sqladmin/v1beta4"
)

var sqlDatabaseAuthorizedNetWorkSchemaElem *schema.Resource = &schema.Resource{
Schema: map[string]*schema.Schema{
"expiration_time": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"name": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"value": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
},
}

func resourceSqlDatabaseInstance() *schema.Resource {
return &schema.Resource{
Create: resourceSqlDatabaseInstanceCreate,
Expand Down Expand Up @@ -128,24 +145,10 @@ func resourceSqlDatabaseInstance() *schema.Resource {
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"authorized_networks": &schema.Schema{
Type: schema.TypeList,
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"expiration_time": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"name": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"value": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
},
},
Set: schema.HashResource(sqlDatabaseAuthorizedNetWorkSchemaElem),
Elem: sqlDatabaseAuthorizedNetWorkSchemaElem,
},
"ipv4_enabled": &schema.Schema{
Type: schema.TypeBool,
Expand Down Expand Up @@ -458,7 +461,7 @@ func resourceSqlDatabaseInstanceCreate(d *schema.ResourceData, meta interface{})

if vp, okp := _ipConfiguration["authorized_networks"]; okp {
settings.IpConfiguration.AuthorizedNetworks = make([]*sqladmin.AclEntry, 0)
_authorizedNetworksList := vp.([]interface{})
_authorizedNetworksList := vp.(*schema.Set).List()
for _, _acl := range _authorizedNetworksList {
_entry := _acl.(map[string]interface{})
entry := &sqladmin.AclEntry{}
Expand Down Expand Up @@ -835,7 +838,7 @@ func resourceSqlDatabaseInstanceUpdate(d *schema.ResourceData, meta interface{})
if len(_oldIpConfList) > 0 {
_oldIpConf := _oldIpConfList[0].(map[string]interface{})
if ovp, ookp := _oldIpConf["authorized_networks"]; ookp {
_oldAuthorizedNetworkList = ovp.([]interface{})
_oldAuthorizedNetworkList = ovp.(*schema.Set).List()
}
}
}
Expand All @@ -846,7 +849,7 @@ func resourceSqlDatabaseInstanceUpdate(d *schema.ResourceData, meta interface{})

_authorizedNetworksList := make([]interface{}, 0)
if vp != nil {
_authorizedNetworksList = vp.([]interface{})
_authorizedNetworksList = vp.(*schema.Set).List()
}
_oipc_map := make(map[string]interface{})
for _, _ipc := range _oldAuthorizedNetworkList {
Expand Down Expand Up @@ -1050,7 +1053,7 @@ func flattenIpConfiguration(ipConfiguration *sqladmin.IpConfiguration) interface
}

func flattenAuthorizedNetworks(entries []*sqladmin.AclEntry) interface{} {
networks := make([]map[string]interface{}, 0, len(entries))
networks := schema.NewSet(schema.HashResource(sqlDatabaseAuthorizedNetWorkSchemaElem), []interface{}{})

for _, entry := range entries {
data := map[string]interface{}{
Expand All @@ -1059,7 +1062,7 @@ func flattenAuthorizedNetworks(entries []*sqladmin.AclEntry) interface{} {
"value": entry.Value,
}

networks = append(networks, data)
networks.Add(data)
}

return networks
Expand Down

0 comments on commit 6adbdcf

Please sign in to comment.