Skip to content

Commit ce5a832

Browse files
Add FutureReservation resource to Compute (#13317) (#10020)
[upstream:e5e181a98c648edc781c49631f9cd8eabba5216a] Signed-off-by: Modular Magician <[email protected]>
1 parent d73c0b3 commit ce5a832

8 files changed

+3694
-2
lines changed

.changelog/13317.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-resource
2+
`google_compute_future_reservation`
3+
```

google-beta/provider/provider_mmv1_resources.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,9 +567,9 @@ var handwrittenIAMDatasources = map[string]*schema.Resource{
567567
}
568568

569569
// Resources
570-
// Generated resources: 658
570+
// Generated resources: 659
571571
// Generated IAM resources: 333
572-
// Total generated resources: 991
572+
// Total generated resources: 992
573573
var generatedResources = map[string]*schema.Resource{
574574
"google_folder_access_approval_settings": accessapproval.ResourceAccessApprovalFolderSettings(),
575575
"google_organization_access_approval_settings": accessapproval.ResourceAccessApprovalOrganizationSettings(),
@@ -812,6 +812,7 @@ var generatedResources = map[string]*schema.Resource{
812812
"google_compute_firewall_policy_rule": compute.ResourceComputeFirewallPolicyRule(),
813813
"google_compute_firewall_policy_with_rules": compute.ResourceComputeFirewallPolicyWithRules(),
814814
"google_compute_forwarding_rule": compute.ResourceComputeForwardingRule(),
815+
"google_compute_future_reservation": compute.ResourceComputeFutureReservation(),
815816
"google_compute_global_address": compute.ResourceComputeGlobalAddress(),
816817
"google_compute_global_forwarding_rule": compute.ResourceComputeGlobalForwardingRule(),
817818
"google_compute_global_network_endpoint": compute.ResourceComputeGlobalNetworkEndpoint(),

google-beta/services/compute/resource_compute_future_reservation.go

Lines changed: 2473 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
resource: 'google_compute_future_reservation'
2+
generation_type: 'mmv1'
3+
source_file: 'products/compute/FutureReservation.yaml'
4+
api_service_name: 'compute.googleapis.com'
5+
api_version: 'beta'
6+
api_resource_type_kind: 'FutureReservation'
7+
fields:
8+
- field: 'auto_created_reservations_delete_time'
9+
- field: 'auto_created_reservations_duration.nanos'
10+
- field: 'auto_created_reservations_duration.seconds'
11+
- field: 'auto_delete_auto_created_reservations'
12+
- field: 'commitment_info.commitment_name'
13+
- field: 'commitment_info.commitment_plan'
14+
- field: 'commitment_info.previous_commitment_terms'
15+
- field: 'creation_timestamp'
16+
- field: 'deployment_type'
17+
- field: 'description'
18+
- field: 'name'
19+
- field: 'name_prefix'
20+
- field: 'planning_status'
21+
- field: 'reservation_mode'
22+
- field: 'reservation_name'
23+
- field: 'scheduling_type'
24+
- field: 'self_link_with_id'
25+
- field: 'share_settings.project_map.project_config.project_id'
26+
- field: 'share_settings.projects'
27+
- field: 'share_settings.share_type'
28+
- field: 'specific_reservation_required'
29+
- field: 'specific_sku_properties.instance_properties.guest_accelerators.accelerator_count'
30+
- field: 'specific_sku_properties.instance_properties.guest_accelerators.accelerator_type'
31+
- field: 'specific_sku_properties.instance_properties.local_ssds.disk_size_gb'
32+
- field: 'specific_sku_properties.instance_properties.local_ssds.interface'
33+
- field: 'specific_sku_properties.instance_properties.location_hint'
34+
- field: 'specific_sku_properties.instance_properties.machine_type'
35+
- field: 'specific_sku_properties.instance_properties.maintenance_freeze_duration_hours'
36+
- field: 'specific_sku_properties.instance_properties.maintenance_interval'
37+
- field: 'specific_sku_properties.instance_properties.min_cpu_platform'
38+
- field: 'specific_sku_properties.source_instance_template'
39+
- field: 'specific_sku_properties.total_count'
40+
- field: 'status.amendment_status'
41+
- field: 'status.auto_created_reservations'
42+
- field: 'status.fulfilled_count'
43+
- field: 'status.last_known_good_state.description'
44+
- field: 'status.last_known_good_state.existing_matching_usage_info.count'
45+
- field: 'status.last_known_good_state.existing_matching_usage_info.time_stamp'
46+
- field: 'status.last_known_good_state.future_reservation_specs.share_settings.project_map.project_config.project_id'
47+
- field: 'status.last_known_good_state.future_reservation_specs.share_settings.projects'
48+
- field: 'status.last_known_good_state.future_reservation_specs.share_settings.share_type'
49+
- field: 'status.last_known_good_state.future_reservation_specs.specific_sku_properties.instance_properties.guest_accelerators.accelerator_count'
50+
- field: 'status.last_known_good_state.future_reservation_specs.specific_sku_properties.instance_properties.guest_accelerators.accelerator_type'
51+
- field: 'status.last_known_good_state.future_reservation_specs.specific_sku_properties.instance_properties.local_ssds.disk_size_gb'
52+
- field: 'status.last_known_good_state.future_reservation_specs.specific_sku_properties.instance_properties.local_ssds.interface'
53+
- field: 'status.last_known_good_state.future_reservation_specs.specific_sku_properties.instance_properties.location_hint'
54+
- field: 'status.last_known_good_state.future_reservation_specs.specific_sku_properties.instance_properties.machine_type'
55+
- field: 'status.last_known_good_state.future_reservation_specs.specific_sku_properties.instance_properties.maintenance_freeze_duration_hours'
56+
- field: 'status.last_known_good_state.future_reservation_specs.specific_sku_properties.instance_properties.maintenance_interval'
57+
- field: 'status.last_known_good_state.future_reservation_specs.specific_sku_properties.instance_properties.min_cpu_platform'
58+
- field: 'status.last_known_good_state.future_reservation_specs.specific_sku_properties.source_instance_template'
59+
- field: 'status.last_known_good_state.future_reservation_specs.specific_sku_properties.total_count'
60+
- field: 'status.last_known_good_state.future_reservation_specs.time_window.duration.nanos'
61+
- field: 'status.last_known_good_state.future_reservation_specs.time_window.duration.seconds'
62+
- field: 'status.last_known_good_state.future_reservation_specs.time_window.end_time'
63+
- field: 'status.last_known_good_state.future_reservation_specs.time_window.start_time'
64+
- field: 'status.last_known_good_state.lock_time'
65+
- field: 'status.last_known_good_state.name_prefix'
66+
- field: 'status.last_known_good_state.procurement_status'
67+
- field: 'status.lock_time'
68+
- field: 'status.procurement_status'
69+
- field: 'status.specific_sku_properties.source_instance_template_id'
70+
- field: 'time_window.duration.nanos'
71+
- field: 'time_window.duration.seconds'
72+
- field: 'time_window.end_time'
73+
- field: 'time_window.start_time'
74+
- field: 'zone'
Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
// ----------------------------------------------------------------------------
5+
//
6+
// *** AUTO GENERATED CODE *** Type: MMv1 ***
7+
//
8+
// ----------------------------------------------------------------------------
9+
//
10+
// This file is automatically generated by Magic Modules and manual
11+
// changes will be clobbered when the file is regenerated.
12+
//
13+
// Please read more about how to change this file in
14+
// .github/CONTRIBUTING.md.
15+
//
16+
// ----------------------------------------------------------------------------
17+
18+
package compute_test
19+
20+
import (
21+
"fmt"
22+
"strings"
23+
"testing"
24+
25+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
26+
"github.com/hashicorp/terraform-plugin-testing/terraform"
27+
28+
"github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest"
29+
"github.com/hashicorp/terraform-provider-google-beta/google-beta/envvar"
30+
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
31+
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
32+
)
33+
34+
func TestAccComputeFutureReservation_futureReservationBasicExample(t *testing.T) {
35+
t.Parallel()
36+
37+
context := map[string]interface{}{
38+
"billing_account": envvar.GetTestBillingAccountFromEnv(t),
39+
"org_id": envvar.GetTestOrgFromEnv(t),
40+
"project": envvar.GetTestProjectFromEnv(),
41+
"random_suffix": acctest.RandString(t, 10),
42+
}
43+
44+
acctest.VcrTest(t, resource.TestCase{
45+
PreCheck: func() { acctest.AccTestPreCheck(t) },
46+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
47+
CheckDestroy: testAccCheckComputeFutureReservationDestroyProducer(t),
48+
Steps: []resource.TestStep{
49+
{
50+
Config: testAccComputeFutureReservation_futureReservationBasicExample(context),
51+
},
52+
{
53+
ResourceName: "google_compute_future_reservation.gce_future_reservation",
54+
ImportState: true,
55+
ImportStateVerify: true,
56+
ImportStateVerifyIgnore: []string{"auto_created_reservations_delete_time", "auto_delete_auto_created_reservations"},
57+
},
58+
},
59+
})
60+
}
61+
62+
func testAccComputeFutureReservation_futureReservationBasicExample(context map[string]interface{}) string {
63+
return acctest.Nprintf(`
64+
resource "google_compute_future_reservation" "gce_future_reservation" {
65+
provider = google-beta
66+
name = "tf-test-gce-future-reservation%{random_suffix}"
67+
project = "%{project}"
68+
auto_delete_auto_created_reservations = true
69+
planning_status = "DRAFT"
70+
name_prefix = "fr-basic"
71+
time_window {
72+
start_time = "2025-11-01T00:00:00Z"
73+
end_time = "2025-11-02T00:00:00Z"
74+
}
75+
specific_sku_properties {
76+
total_count = "1"
77+
78+
instance_properties {
79+
machine_type = "e2-standard-2"
80+
}
81+
}
82+
}
83+
`, context)
84+
}
85+
86+
func TestAccComputeFutureReservation_sharedFutureReservationExample(t *testing.T) {
87+
acctest.SkipIfVcr(t)
88+
t.Parallel()
89+
90+
context := map[string]interface{}{
91+
"billing_account": envvar.GetTestBillingAccountFromEnv(t),
92+
"org_id": envvar.GetTestOrgFromEnv(t),
93+
"project": envvar.GetTestProjectFromEnv(),
94+
"random_suffix": acctest.RandString(t, 10),
95+
}
96+
97+
acctest.VcrTest(t, resource.TestCase{
98+
PreCheck: func() { acctest.AccTestPreCheck(t) },
99+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
100+
CheckDestroy: testAccCheckComputeFutureReservationDestroyProducer(t),
101+
Steps: []resource.TestStep{
102+
{
103+
Config: testAccComputeFutureReservation_sharedFutureReservationExample(context),
104+
},
105+
{
106+
ResourceName: "google_compute_future_reservation.gce_future_reservation",
107+
ImportState: true,
108+
ImportStateVerify: true,
109+
ImportStateVerifyIgnore: []string{"auto_created_reservations_delete_time", "auto_delete_auto_created_reservations"},
110+
},
111+
},
112+
})
113+
}
114+
115+
func testAccComputeFutureReservation_sharedFutureReservationExample(context map[string]interface{}) string {
116+
return acctest.Nprintf(`
117+
resource "google_project" "owner_project" {
118+
project_id = "tf-test%{random_suffix}"
119+
name = "tf-test%{random_suffix}"
120+
org_id = "%{org_id}"
121+
billing_account = "%{billing_account}"
122+
deletion_policy = "DELETE"
123+
}
124+
125+
resource "google_project_service" "compute" {
126+
project = google_project.owner_project.project_id
127+
service = "compute.googleapis.com"
128+
disable_on_destroy = false
129+
}
130+
131+
resource "google_project" "guest_project" {
132+
project_id = "tf-test-2%{random_suffix}"
133+
name = "tf-test-2%{random_suffix}"
134+
org_id = "%{org_id}"
135+
deletion_policy = "DELETE"
136+
}
137+
138+
resource "google_organization_policy" "shared_future_reservation_org_policy" {
139+
org_id = "%{org_id}"
140+
constraint = "constraints/compute.sharedReservationsOwnerProjects"
141+
list_policy {
142+
allow {
143+
values = ["projects/${google_project.owner_project.number}"]
144+
}
145+
}
146+
}
147+
148+
resource "google_compute_future_reservation" "gce_future_reservation" {
149+
project = google_project.owner_project.project_id
150+
name = "tf-test-gce-shared-future-reservation%{random_suffix}"
151+
time_window {
152+
start_time = "2025-08-01T00:00:00Z"
153+
end_time = "2025-08-02T00:00:00Z"
154+
}
155+
156+
share_settings {
157+
share_type = "SPECIFIC_PROJECTS"
158+
project_map {
159+
id = google_project.guest_project.project_id
160+
project_id = google_project.guest_project.project_id
161+
}
162+
}
163+
164+
165+
depends_on = [
166+
google_organization_policy.shared_future_reservation_org_policy,
167+
google_project_service.compute
168+
]
169+
}
170+
`, context)
171+
}
172+
173+
func testAccCheckComputeFutureReservationDestroyProducer(t *testing.T) func(s *terraform.State) error {
174+
return func(s *terraform.State) error {
175+
for name, rs := range s.RootModule().Resources {
176+
if rs.Type != "google_compute_future_reservation" {
177+
continue
178+
}
179+
if strings.HasPrefix(name, "data.") {
180+
continue
181+
}
182+
183+
config := acctest.GoogleProviderConfig(t)
184+
185+
url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{ComputeBasePath}}projects/{{project}}/zones/{{zone}}/futureReservations/{{name}}")
186+
if err != nil {
187+
return err
188+
}
189+
190+
billingProject := ""
191+
192+
if config.BillingProject != "" {
193+
billingProject = config.BillingProject
194+
}
195+
196+
_, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
197+
Config: config,
198+
Method: "GET",
199+
Project: billingProject,
200+
RawURL: url,
201+
UserAgent: config.UserAgent,
202+
})
203+
if err == nil {
204+
return fmt.Errorf("ComputeFutureReservation still exists at %s", url)
205+
}
206+
}
207+
208+
return nil
209+
}
210+
}

0 commit comments

Comments
 (0)