-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(alloydb): instance: add support for inbound public ip and author…
…ized networks Fixes hashicorp/terraform-provider-google#17091
- Loading branch information
1 parent
77aabb0
commit 62f4122
Showing
4 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
mmv1/templates/terraform/examples/alloydb_instance_public_ip.tf.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
resource "google_alloydb_instance" "<%= ctx[:primary_resource_id] %>" { | ||
provider = google-beta | ||
|
||
cluster = google_alloydb_cluster.<%= ctx[:primary_resource_id] %>.name | ||
instance_id = "<%= ctx[:vars]['alloydb_instance_name'] %>" | ||
instance_type = "PRIMARY" | ||
|
||
machine_config { | ||
cpu_count = 2 | ||
} | ||
|
||
network_config { | ||
enable_public_ip = true | ||
} | ||
|
||
depends_on = [google_service_networking_connection.vpc_connection] | ||
} | ||
|
||
resource "google_alloydb_cluster" "<%= ctx[:primary_resource_id] %>" { | ||
provider = google-beta | ||
|
||
cluster_id = "<%= ctx[:vars]['alloydb_cluster_name'] %>" | ||
location = "us-central1" | ||
network = google_compute_network.default.id | ||
|
||
initial_user { | ||
password = "<%= ctx[:vars]['alloydb_cluster_name'] %>" | ||
} | ||
} | ||
|
||
data "google_project" "project" { | ||
provider = google-beta | ||
} | ||
|
||
resource "google_compute_network" "default" { | ||
provider = google-beta | ||
name = "<%= ctx[:vars]['network_name'] %>" | ||
} | ||
|
||
resource "google_compute_global_address" "private_ip_alloc" { | ||
provider = google-beta | ||
name = "<%= ctx[:vars]['alloydb_cluster_name'] %>" | ||
address_type = "INTERNAL" | ||
purpose = "VPC_PEERING" | ||
prefix_length = 16 | ||
network = google_compute_network.default.id | ||
} | ||
|
||
resource "google_service_networking_connection" "vpc_connection" { | ||
provider = google-beta | ||
network = google_compute_network.default.id | ||
service = "servicenetworking.googleapis.com" | ||
reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name] | ||
} |
43 changes: 43 additions & 0 deletions
43
mmv1/templates/terraform/post_create/alloydb_instance.go.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<% unless version == 'ga' -%> | ||
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)) { | ||
// an instance cannot be created with public IP addresses, so we need to PATCH the instance | ||
// after its created | ||
url, err := tpgresource.ReplaceVars(d, config, "{{AlloydbBasePath}}{{cluster}}/instances/{{instance_id}}") | ||
if err != nil { | ||
return err | ||
} | ||
log.Printf("[DEBUG] Updating network configuration for alloyDB instance %q", d.Id()) | ||
obj = make(map[string]interface{}) | ||
obj["networkConfig"] = networkConfigProp | ||
|
||
url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": "networkConfig"}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
patchRes, 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 network configuration for alloydb instance %q: %s", d.Id(), err) | ||
} | ||
|
||
err = AlloydbOperationWaitTime( | ||
config, patchRes, project, "Creating Instance", userAgent, | ||
d.Timeout(schema.TimeoutUpdate)) | ||
|
||
if err != nil { | ||
return fmt.Errorf("Error updating network configuration for alloydb instance %q: %s", d.Id(), err) | ||
} | ||
} | ||
<% end -%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters