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

Shared reservation #5547

Merged
merged 13 commits into from
Jan 12, 2022
32 changes: 29 additions & 3 deletions mmv1/products/compute/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2748,7 +2748,7 @@ objects:
name: 'idleTimeoutSec'
description: |
Specifies how long to keep a Connection Tracking entry while there is
no matching traffic (in seconds).
no matching traffic (in seconds).

For L4 ILB the minimum(default) is 10 minutes and maximum is 16 hours.

Expand All @@ -2759,7 +2759,7 @@ objects:
Specifies the key used for connection tracking. There are two options:
`PER_CONNECTION`: The Connection Tracking is performed as per the
Connection Key (default Hash Method) for the specific protocol.

`PER_SESSION`: The Connection Tracking is performed as per the
configured Session Affinity. It matches the configured Session Affinity.
default_value: :PER_CONNECTION
Expand Down Expand Up @@ -14214,6 +14214,32 @@ objects:
output: true
description: |
The status of the reservation.
- !ruby/object:Api::Type::NestedObject
name: 'shareSettings'
description: |
The share setting for reservations.
properties:
- !ruby/object:Api::Type::Enum
name: 'shareType'
values:
- :LOCAL
- :SPECIFIC_PROJECTS
description: |
Type of sharing for this shared-reservation
- !ruby/object:Api::Type::Map
name: 'projectMap'
description: |
A map of project number and project config. This is only valid when shareType's value is SPECIFIC_PROJECTS.
key_name: id
key_description: |
The project id/number which is deleting or adding to the project list. Only project number is acceptable.
value_type: !ruby/object:Api::Type::NestedObject
name: projectConfig
properties:
- !ruby/object:Api::Type::String
name: 'projectId'
description: |
The project id/number, should be same as the key of this project config in the project map.
- !ruby/object:Api::Type::NestedObject
name: 'specificReservation'
required: true
Expand Down Expand Up @@ -14656,7 +14682,7 @@ objects:
description: |
The purpose of the resource. A subnetwork with purpose set to
INTERNAL_HTTPS_LOAD_BALANCER is a user-created subnetwork that is
reserved for Internal HTTP(S) Load Balancing.
reserved for Internal HTTP(S) Load Balancing.

If set to INTERNAL_HTTPS_LOAD_BALANCER you must also set the `role` field.
- !ruby/object:Api::Type::Enum
Expand Down
23 changes: 23 additions & 0 deletions mmv1/products/compute/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2237,6 +2237,18 @@ overrides: !ruby/object:Overrides::ResourceOverrides
primary_resource_id: "gce_reservation"
vars:
reservation_name: "gce-reservation"
- !ruby/object:Provider::Terraform::Examples
name: "shared_reservation_basic"
primary_resource_id: "gce_reservation"
test_env_vars:
project: :PROJECT_NAME
org_id: :ORG_ID
billing_account: :BILLING_ACCT
vars:
reservation_name: "gce-shared-reservation"
skip_docs: true
# Resource creation race
skip_vcr: true
custom_code: !ruby/object:Provider::Terraform::CustomCode
update_encoder: templates/terraform/update_encoder/reservation.go.erb
properties:
Expand All @@ -2247,6 +2259,17 @@ overrides: !ruby/object:Overrides::ResourceOverrides
specificReservation.count: !ruby/object:Overrides::Terraform::PropertyOverride
validation: !ruby/object:Provider::Terraform::Validation
function: 'validation.IntAtLeast(1)'
shareSettings: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
ignore_read: true
shareSettings.shareType: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
shareSettings.projectMap: !ruby/object:Overrides::Terraform::PropertyOverride
key_description: |
The project id/number which is deleting or adding to the project list.
shareSettings.projectMap.projectId: !ruby/object:Overrides::Terraform::PropertyOverride
description: |
The project id/number, should be same as the key of this project config in the project map.
Route: !ruby/object:Overrides::Terraform::ResourceOverride
# Route cannot be added while a peering is on progress on the network
mutex: 'projects/{{project}}/global/networks/{{network}}/peerings'
Expand Down
51 changes: 51 additions & 0 deletions mmv1/templates/terraform/examples/shared_reservation_basic.tf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
resource "google_project" "owner_project" {
project_id = "tf-test%{random_suffix}"
name = "tf-test%{random_suffix}"
org_id = "<%= ctx[:test_env_vars]['org_id'] %>"
billing_account = "<%= ctx[:test_env_vars]['billing_account'] %>"
}


resource "google_project_service" "compute" {
project = google_project.owner_project.project_id
service = "compute.googleapis.com"
disable_on_destroy = false
}

resource "google_project" "guest_project" {
project_id = "tf-test-2%{random_suffix}"
name = "tf-test-2%{random_suffix}"
org_id = "<%= ctx[:test_env_vars]['org_id'] %>"
}

resource "google_organization_policy" "shared_reservation_org_policy" {
org_id = "<%= ctx[:test_env_vars]['org_id'] %>"
constraint = "constraints/compute.sharedReservationsOwnerProjects"
list_policy {
allow {
values = ["projects/${google_project.owner_project.number}"]
}
}
}

resource "google_compute_reservation" "<%= ctx[:primary_resource_id] %>" {
project = google_project.owner_project.project_id
name = "<%= ctx[:vars]['reservation_name'] %>"
zone = "us-central1-a"

specific_reservation {
count = 1
instance_properties {
min_cpu_platform = "Intel Cascade Lake"
machine_type = "n2-standard-2"
}
}
share_settings {
share_type = "SPECIFIC_PROJECTS"
project_map {
id = google_project.guest_project.project_id
project_id = google_project.guest_project.project_id
}
}
depends_on = [google_organization_policy.shared_reservation_org_policy,google_project_service.compute]
}
2 changes: 1 addition & 1 deletion mmv1/templates/terraform/update_encoder/reservation.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
newObj := make(map[string]interface{})
newObj["specificSkuCount"] = obj["specificReservation"].(map[string]interface{})["count"]

return newObj, nil
return newObj, nil
Original file line number Diff line number Diff line change
Expand Up @@ -5691,7 +5691,6 @@ resource "google_compute_reservation" "reservation" {
machine_type = "n1-standard-1"
}
}

specific_reservation_required = true
}

Expand Down