Skip to content

Commit be7372e

Browse files
promote gkeonprem resources to GA (#9214) (#16237)
* promote gkeonprem resources to GA * fix update test [upstream:4dc1173c6943b348308001f9071b37581aa75e01] Signed-off-by: Modular Magician <[email protected]>
1 parent c9fee92 commit be7372e

30 files changed

+16687
-28
lines changed

.changelog/9214.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
```release-note:enhancement
2+
gkeonprem: promoted `google_gkeonprem_bare_metal_admin_cluster`, `google_gkeonprem_bare_metal_cluster`, and `google_gkeonprem_bare_metal_node_pool` resources to GA
3+
```
4+
```release-note:enhancement
5+
gkeonprem: promoted `google_gkeonprem_vmware_cluster` and `google_gkeonprem_vmware_node_pool` resources to GA
6+
```

google/fwmodels/provider_model.go

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ type ProviderModel struct {
8383
GKEBackupCustomEndpoint types.String `tfsdk:"gke_backup_custom_endpoint"`
8484
GKEHubCustomEndpoint types.String `tfsdk:"gke_hub_custom_endpoint"`
8585
GKEHub2CustomEndpoint types.String `tfsdk:"gke_hub2_custom_endpoint"`
86+
GkeonpremCustomEndpoint types.String `tfsdk:"gkeonprem_custom_endpoint"`
8687
HealthcareCustomEndpoint types.String `tfsdk:"healthcare_custom_endpoint"`
8788
IAM2CustomEndpoint types.String `tfsdk:"iam2_custom_endpoint"`
8889
IAMBetaCustomEndpoint types.String `tfsdk:"iam_beta_custom_endpoint"`

google/fwprovider/framework_provider.go

+6
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,12 @@ func (p *FrameworkProvider) Schema(_ context.Context, _ provider.SchemaRequest,
482482
transport_tpg.CustomEndpointValidator(),
483483
},
484484
},
485+
"gkeonprem_custom_endpoint": &schema.StringAttribute{
486+
Optional: true,
487+
Validators: []validator.String{
488+
transport_tpg.CustomEndpointValidator(),
489+
},
490+
},
485491
"healthcare_custom_endpoint": &schema.StringAttribute{
486492
Optional: true,
487493
Validators: []validator.String{

google/fwtransport/framework_config.go

+10
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ type FrameworkProviderConfig struct {
108108
GKEBackupBasePath string
109109
GKEHubBasePath string
110110
GKEHub2BasePath string
111+
GkeonpremBasePath string
111112
HealthcareBasePath string
112113
IAM2BasePath string
113114
IAMBetaBasePath string
@@ -246,6 +247,7 @@ func (p *FrameworkProviderConfig) LoadAndValidateFramework(ctx context.Context,
246247
p.GKEBackupBasePath = data.GKEBackupCustomEndpoint.ValueString()
247248
p.GKEHubBasePath = data.GKEHubCustomEndpoint.ValueString()
248249
p.GKEHub2BasePath = data.GKEHub2CustomEndpoint.ValueString()
250+
p.GkeonpremBasePath = data.GkeonpremCustomEndpoint.ValueString()
249251
p.HealthcareBasePath = data.HealthcareCustomEndpoint.ValueString()
250252
p.IAM2BasePath = data.IAM2CustomEndpoint.ValueString()
251253
p.IAMBetaBasePath = data.IAMBetaCustomEndpoint.ValueString()
@@ -876,6 +878,14 @@ func (p *FrameworkProviderConfig) HandleDefaults(ctx context.Context, data *fwmo
876878
data.GKEHub2CustomEndpoint = types.StringValue(customEndpoint.(string))
877879
}
878880
}
881+
if data.GkeonpremCustomEndpoint.IsNull() {
882+
customEndpoint := transport_tpg.MultiEnvDefault([]string{
883+
"GOOGLE_GKEONPREM_CUSTOM_ENDPOINT",
884+
}, transport_tpg.DefaultBasePaths[transport_tpg.GkeonpremBasePathKey])
885+
if customEndpoint != nil {
886+
data.GkeonpremCustomEndpoint = types.StringValue(customEndpoint.(string))
887+
}
888+
}
879889
if data.HealthcareCustomEndpoint.IsNull() {
880890
customEndpoint := transport_tpg.MultiEnvDefault([]string{
881891
"GOOGLE_HEALTHCARE_CUSTOM_ENDPOINT",

google/provider/provider.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ import (
7070
"github.com/hashicorp/terraform-provider-google/google/services/gkebackup"
7171
"github.com/hashicorp/terraform-provider-google/google/services/gkehub"
7272
"github.com/hashicorp/terraform-provider-google/google/services/gkehub2"
73+
"github.com/hashicorp/terraform-provider-google/google/services/gkeonprem"
7374
"github.com/hashicorp/terraform-provider-google/google/services/healthcare"
7475
"github.com/hashicorp/terraform-provider-google/google/services/iam2"
7576
"github.com/hashicorp/terraform-provider-google/google/services/iambeta"
@@ -525,6 +526,11 @@ func Provider() *schema.Provider {
525526
Optional: true,
526527
ValidateFunc: transport_tpg.ValidateCustomEndpoint,
527528
},
529+
"gkeonprem_custom_endpoint": {
530+
Type: schema.TypeString,
531+
Optional: true,
532+
ValidateFunc: transport_tpg.ValidateCustomEndpoint,
533+
},
528534
"healthcare_custom_endpoint": {
529535
Type: schema.TypeString,
530536
Optional: true,
@@ -1003,9 +1009,9 @@ func DatasourceMapWithErrors() (map[string]*schema.Resource, error) {
10031009
})
10041010
}
10051011

1006-
// Generated resources: 332
1012+
// Generated resources: 337
10071013
// Generated IAM resources: 207
1008-
// Total generated resources: 539
1014+
// Total generated resources: 544
10091015
func ResourceMap() map[string]*schema.Resource {
10101016
resourceMap, _ := ResourceMapWithErrors()
10111017
return resourceMap
@@ -1364,6 +1370,11 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
13641370
"google_gke_hub_scope_iam_member": tpgiamresource.ResourceIamMember(gkehub2.GKEHub2ScopeIamSchema, gkehub2.GKEHub2ScopeIamUpdaterProducer, gkehub2.GKEHub2ScopeIdParseFunc),
13651371
"google_gke_hub_scope_iam_policy": tpgiamresource.ResourceIamPolicy(gkehub2.GKEHub2ScopeIamSchema, gkehub2.GKEHub2ScopeIamUpdaterProducer, gkehub2.GKEHub2ScopeIdParseFunc),
13661372
"google_gke_hub_scope_rbac_role_binding": gkehub2.ResourceGKEHub2ScopeRBACRoleBinding(),
1373+
"google_gkeonprem_bare_metal_admin_cluster": gkeonprem.ResourceGkeonpremBareMetalAdminCluster(),
1374+
"google_gkeonprem_bare_metal_cluster": gkeonprem.ResourceGkeonpremBareMetalCluster(),
1375+
"google_gkeonprem_bare_metal_node_pool": gkeonprem.ResourceGkeonpremBareMetalNodePool(),
1376+
"google_gkeonprem_vmware_cluster": gkeonprem.ResourceGkeonpremVmwareCluster(),
1377+
"google_gkeonprem_vmware_node_pool": gkeonprem.ResourceGkeonpremVmwareNodePool(),
13671378
"google_healthcare_consent_store": healthcare.ResourceHealthcareConsentStore(),
13681379
"google_healthcare_consent_store_iam_binding": tpgiamresource.ResourceIamBinding(healthcare.HealthcareConsentStoreIamSchema, healthcare.HealthcareConsentStoreIamUpdaterProducer, healthcare.HealthcareConsentStoreIdParseFunc),
13691380
"google_healthcare_consent_store_iam_member": tpgiamresource.ResourceIamMember(healthcare.HealthcareConsentStoreIamSchema, healthcare.HealthcareConsentStoreIamUpdaterProducer, healthcare.HealthcareConsentStoreIdParseFunc),
@@ -1841,6 +1852,7 @@ func ProviderConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Pr
18411852
config.GKEBackupBasePath = d.Get("gke_backup_custom_endpoint").(string)
18421853
config.GKEHubBasePath = d.Get("gke_hub_custom_endpoint").(string)
18431854
config.GKEHub2BasePath = d.Get("gke_hub2_custom_endpoint").(string)
1855+
config.GkeonpremBasePath = d.Get("gkeonprem_custom_endpoint").(string)
18441856
config.HealthcareBasePath = d.Get("healthcare_custom_endpoint").(string)
18451857
config.IAM2BasePath = d.Get("iam2_custom_endpoint").(string)
18461858
config.IAMBetaBasePath = d.Get("iam_beta_custom_endpoint").(string)
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,147 @@
11
// Copyright (c) HashiCorp, Inc.
22
// SPDX-License-Identifier: MPL-2.0
33
package gkeonprem
4+
5+
import (
6+
"encoding/json"
7+
"fmt"
8+
"time"
9+
10+
"github.com/hashicorp/terraform-provider-google/google/tpgresource"
11+
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
12+
13+
cloudresourcemanager "google.golang.org/api/cloudresourcemanager/v1"
14+
)
15+
16+
type gkeonpremOpError struct {
17+
*cloudresourcemanager.Status
18+
}
19+
20+
func (e gkeonpremOpError) Error() string {
21+
var validationCheck map[string]interface{}
22+
23+
for _, msg := range e.Details {
24+
detail := make(map[string]interface{})
25+
if err := json.Unmarshal(msg, &detail); err != nil {
26+
continue
27+
}
28+
29+
if _, ok := detail["validationCheck"]; ok {
30+
delete(detail, "@type")
31+
validationCheck = detail
32+
}
33+
}
34+
35+
if validationCheck != nil {
36+
bytes, err := json.MarshalIndent(validationCheck, "", " ")
37+
if err != nil {
38+
return fmt.Sprintf("Error code %v message: %s validation check: %s", e.Code, e.Message, validationCheck)
39+
}
40+
41+
return fmt.Sprintf("Error code %v message: %s\n %s", e.Code, e.Message, bytes)
42+
}
43+
44+
return fmt.Sprintf("Error code %v, message: %s", e.Code, e.Message)
45+
}
46+
47+
type gkeonpremOperationWaiter struct {
48+
Config *transport_tpg.Config
49+
UserAgent string
50+
Project string
51+
Op tpgresource.CommonOperation
52+
}
53+
54+
func (w *gkeonpremOperationWaiter) State() string {
55+
if w == nil {
56+
return fmt.Sprintf("Operation is nil!")
57+
}
58+
59+
return fmt.Sprintf("done: %v", w.Op.Done)
60+
}
61+
62+
func (w *gkeonpremOperationWaiter) Error() error {
63+
if w != nil && w.Op.Error != nil {
64+
return &gkeonpremOpError{w.Op.Error}
65+
}
66+
return nil
67+
}
68+
69+
func (w *gkeonpremOperationWaiter) IsRetryable(error) bool {
70+
return false
71+
}
72+
73+
func (w *gkeonpremOperationWaiter) SetOp(op interface{}) error {
74+
if err := tpgresource.Convert(op, &w.Op); err != nil {
75+
return err
76+
}
77+
return nil
78+
}
79+
80+
func (w *gkeonpremOperationWaiter) OpName() string {
81+
if w == nil {
82+
return "<nil>"
83+
}
84+
85+
return w.Op.Name
86+
}
87+
88+
func (w *gkeonpremOperationWaiter) PendingStates() []string {
89+
return []string{"done: false"}
90+
}
91+
92+
func (w *gkeonpremOperationWaiter) TargetStates() []string {
93+
return []string{"done: true"}
94+
}
95+
96+
func (w *gkeonpremOperationWaiter) QueryOp() (interface{}, error) {
97+
if w == nil {
98+
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
99+
}
100+
// Returns the proper get.
101+
url := fmt.Sprintf("%s%s", w.Config.GkeonpremBasePath, w.Op.Name)
102+
103+
return transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
104+
Config: w.Config,
105+
Method: "GET",
106+
Project: w.Project,
107+
RawURL: url,
108+
UserAgent: w.UserAgent,
109+
})
110+
}
111+
112+
func creategkeonpremWaiter(config *transport_tpg.Config, op map[string]interface{}, project, activity, userAgent string) (*gkeonpremOperationWaiter, error) {
113+
w := &gkeonpremOperationWaiter{
114+
Config: config,
115+
UserAgent: userAgent,
116+
Project: project,
117+
}
118+
if err := w.SetOp(op); err != nil {
119+
return nil, err
120+
}
121+
return w, nil
122+
}
123+
124+
// nolint: deadcode,unused
125+
func GkeonpremOperationWaitTimeWithResponse(config *transport_tpg.Config, op map[string]interface{}, response *map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error {
126+
w, err := creategkeonpremWaiter(config, op, project, activity, userAgent)
127+
if err != nil {
128+
return err
129+
}
130+
if err := tpgresource.OperationWait(w, activity, timeout, config.PollInterval); err != nil {
131+
return err
132+
}
133+
return json.Unmarshal([]byte(w.Op.Response), response)
134+
}
135+
136+
func GkeonpremOperationWaitTime(config *transport_tpg.Config, op map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error {
137+
if val, ok := op["name"]; !ok || val == "" {
138+
// This was a synchronous call - there is no operation to wait for.
139+
return nil
140+
}
141+
w, err := creategkeonpremWaiter(config, op, project, activity, userAgent)
142+
if err != nil {
143+
// If w is nil, the op was synchronous.
144+
return err
145+
}
146+
return tpgresource.OperationWait(w, activity, timeout, config.PollInterval)
147+
}

0 commit comments

Comments
 (0)