Skip to content

Commit

Permalink
merge instance with self_link into one field and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chrissng committed Jan 3, 2020
1 parent 5eeaf12 commit 38126d6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,16 @@ func dataSourceGoogleSQLCaCerts() *schema.Resource {

Schema: map[string]*schema.Schema{
"instance": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
Type: schema.TypeString,
Required: true,
DiffSuppressFunc: compareSelfLinkOrResourceName,
},
"project": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
},
"instance_self_link": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
},
"active_version": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -71,22 +64,14 @@ func dataSourceGoogleSQLCaCertsRead(d *schema.ResourceData, meta interface{}) er

var project, instance string
if v, ok := d.GetOk("instance"); ok {
p, err := getProject(d, config)
if err != nil {
return err
}
project = p
instance = v.(string)
} else if selfLink, ok := d.GetOk("instance_self_link"); ok {
fv, err := parseProjectFieldValue("instances", selfLink.(string), "project", d, config, false)
fv, err := parseProjectFieldValue("instances", v.(string), "project", d, config, false)
if err != nil {
return err
}
project = fv.Project
instance = fv.Name
d.Set("instance_self_link", selfLink)
} else {
return fmt.Errorf("one of instance or instance_self_link must be set")
return fmt.Errorf("instance must be set")
}

log.Printf("[DEBUG] Fetching CA certs from instance %s", instance)
Expand All @@ -99,7 +84,6 @@ func dataSourceGoogleSQLCaCertsRead(d *schema.ResourceData, meta interface{}) er
log.Printf("[DEBUG] Fetched CA certs from instance %s", instance)

d.Set("project", project)
d.Set("instance", instance)
d.Set("certs", flattenServerCaCerts(response.Certs))
d.Set("active_version", response.ActiveVersion)
d.SetId(fmt.Sprintf("projects/%s/instance/%s", project, instance))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ data "google_sql_ca_certs" "ca_certs" {
}
data "google_sql_ca_certs" "ca_certs_self_link" {
instance_self_link = google_sql_database_instance.foo.self_link
instance = google_sql_database_instance.foo.self_link
}
`, instanceName)
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,11 @@ output "db_latest_ca_cert" {

The following arguments are supported:

* `instance_self_link` - (Optional) The self link of the instance. One of `name` or `instance_self_link` must be provided.

* `instance` - (Optional) The name of the instance. One of `name` or `instance_self_link` must be provided.
* `instance` - (Required) The name or self link of the instance.

---

* `project` - (Optional) The ID of the project in which the resource belongs.
If `instance_self_link` is provided, this value is ignored. If `project` is not provided, the provider project is used.
* `project` - (Optional) The ID of the project in which the resource belongs. If `project` is not provided, the provider project is used.

## Attributes Reference

Expand Down

0 comments on commit 38126d6

Please sign in to comment.