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

Update AlloyDB e2e tests and remove custom code for Public-IP feature #18344

Merged
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
59 changes: 0 additions & 59 deletions google/services/alloydb/resource_alloydb_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,20 +462,6 @@ func resourceAlloydbInstanceCreate(d *schema.ResourceData, meta interface{}) err
}

headers := make(http.Header)
// Temporarily remove the enablePublicIp field if it is set to true since the
// API prohibits creating instances with public IP enabled.
var nc map[string]interface{}
if obj["networkConfig"] == nil {
nc = make(map[string]interface{})
} else {
nc = obj["networkConfig"].(map[string]interface{})
}
if nc["enablePublicIp"] == true {
delete(nc, "enablePublicIp")
delete(nc, "authorizedExternalNetworks")
}
obj["networkConfig"] = nc

// Read the config and call createsecondary api if instance_type is SECONDARY

if instanceType := d.Get("instance_type"); instanceType == "SECONDARY" {
Expand Down Expand Up @@ -512,51 +498,6 @@ func resourceAlloydbInstanceCreate(d *schema.ResourceData, meta interface{}) err
return fmt.Errorf("Error waiting to create Instance: %s", err)
}

// If enablePublicIp is set to true, then we must create the instance first with
// it disabled then update to enable it.
networkConfigProp, err = expandAlloydbInstanceNetworkConfig(d.Get("network_config"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("network_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(networkConfigProp)) && (ok || !reflect.DeepEqual(v, networkConfigProp)) {
nc := networkConfigProp.(map[string]interface{})
if nc["enablePublicIp"] == true {
obj["networkConfig"] = networkConfigProp

updateMask := []string{}
updateMask = append(updateMask, "networkConfig")
url, err := tpgresource.ReplaceVars(d, config, "{{AlloydbBasePath}}{{cluster}}/instances/{{instance_id}}")
if err != nil {
return err
}
url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
if err != nil {
return err
}

updateRes, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Config: config,
Method: "PATCH",
Project: billingProject,
RawURL: url,
UserAgent: userAgent,
Body: obj,
Timeout: d.Timeout(schema.TimeoutUpdate),
})
if err != nil {
return fmt.Errorf("Error updating the Instance to enable public ip: %s", err)
} else {
log.Printf("[DEBUG] Finished updating Instance to enable public ip %q: %#v", d.Id(), updateRes)
}
err = AlloydbOperationWaitTime(
config, updateRes, project, "Updating Instance", userAgent,
d.Timeout(schema.TimeoutUpdate))

if err != nil {
return err
}
}
}

log.Printf("[DEBUG] Finished creating Instance %q: %#v", d.Id(), res)

return resourceAlloydbInstanceRead(d, meta)
Expand Down
12 changes: 12 additions & 0 deletions google/services/alloydb/resource_alloydb_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,9 @@ resource "google_alloydb_instance" "default" {
cluster = google_alloydb_cluster.default.name
instance_id = "tf-test-alloydb-instance%{random_suffix}"
instance_type = "PRIMARY"
database_flags = {
"password.enforce_complexity" = "on"
}

network_config {
enable_public_ip = %{enable_public_ip}
Expand All @@ -668,6 +671,9 @@ resource "google_alloydb_cluster" "default" {
cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
location = "us-central1"
network = data.google_compute_network.default.id
initial_user {
password = "tf-test-alloydb-cluster%{random_suffix}"
}
}

data "google_project" "project" {}
Expand All @@ -684,6 +690,9 @@ resource "google_alloydb_instance" "default" {
cluster = google_alloydb_cluster.default.name
instance_id = "tf-test-alloydb-instance%{random_suffix}"
instance_type = "PRIMARY"
database_flags = {
"password.enforce_complexity" = "on"
}

network_config {
enable_public_ip = %{enable_public_ip}
Expand All @@ -697,6 +706,9 @@ resource "google_alloydb_cluster" "default" {
cluster_id = "tf-test-alloydb-cluster%{random_suffix}"
location = "us-central1"
network = data.google_compute_network.default.id
initial_user {
password = "tf-test-alloydb-cluster%{random_suffix}"
}
}

data "google_project" "project" {}
Expand Down