Skip to content

Commit

Permalink
promote gkeonprem resources to GA (#9214) (#16237)
Browse files Browse the repository at this point in the history
* promote gkeonprem resources to GA

* fix update test
[upstream:4dc1173c6943b348308001f9071b37581aa75e01]

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Oct 12, 2023
1 parent c9fee92 commit be7372e
Show file tree
Hide file tree
Showing 30 changed files with 16,687 additions and 28 deletions.
6 changes: 6 additions & 0 deletions .changelog/9214.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
```release-note:enhancement
gkeonprem: promoted `google_gkeonprem_bare_metal_admin_cluster`, `google_gkeonprem_bare_metal_cluster`, and `google_gkeonprem_bare_metal_node_pool` resources to GA
```
```release-note:enhancement
gkeonprem: promoted `google_gkeonprem_vmware_cluster` and `google_gkeonprem_vmware_node_pool` resources to GA
```
1 change: 1 addition & 0 deletions google/fwmodels/provider_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ type ProviderModel struct {
GKEBackupCustomEndpoint types.String `tfsdk:"gke_backup_custom_endpoint"`
GKEHubCustomEndpoint types.String `tfsdk:"gke_hub_custom_endpoint"`
GKEHub2CustomEndpoint types.String `tfsdk:"gke_hub2_custom_endpoint"`
GkeonpremCustomEndpoint types.String `tfsdk:"gkeonprem_custom_endpoint"`
HealthcareCustomEndpoint types.String `tfsdk:"healthcare_custom_endpoint"`
IAM2CustomEndpoint types.String `tfsdk:"iam2_custom_endpoint"`
IAMBetaCustomEndpoint types.String `tfsdk:"iam_beta_custom_endpoint"`
Expand Down
6 changes: 6 additions & 0 deletions google/fwprovider/framework_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,12 @@ func (p *FrameworkProvider) Schema(_ context.Context, _ provider.SchemaRequest,
transport_tpg.CustomEndpointValidator(),
},
},
"gkeonprem_custom_endpoint": &schema.StringAttribute{
Optional: true,
Validators: []validator.String{
transport_tpg.CustomEndpointValidator(),
},
},
"healthcare_custom_endpoint": &schema.StringAttribute{
Optional: true,
Validators: []validator.String{
Expand Down
10 changes: 10 additions & 0 deletions google/fwtransport/framework_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ type FrameworkProviderConfig struct {
GKEBackupBasePath string
GKEHubBasePath string
GKEHub2BasePath string
GkeonpremBasePath string
HealthcareBasePath string
IAM2BasePath string
IAMBetaBasePath string
Expand Down Expand Up @@ -246,6 +247,7 @@ func (p *FrameworkProviderConfig) LoadAndValidateFramework(ctx context.Context,
p.GKEBackupBasePath = data.GKEBackupCustomEndpoint.ValueString()
p.GKEHubBasePath = data.GKEHubCustomEndpoint.ValueString()
p.GKEHub2BasePath = data.GKEHub2CustomEndpoint.ValueString()
p.GkeonpremBasePath = data.GkeonpremCustomEndpoint.ValueString()
p.HealthcareBasePath = data.HealthcareCustomEndpoint.ValueString()
p.IAM2BasePath = data.IAM2CustomEndpoint.ValueString()
p.IAMBetaBasePath = data.IAMBetaCustomEndpoint.ValueString()
Expand Down Expand Up @@ -876,6 +878,14 @@ func (p *FrameworkProviderConfig) HandleDefaults(ctx context.Context, data *fwmo
data.GKEHub2CustomEndpoint = types.StringValue(customEndpoint.(string))
}
}
if data.GkeonpremCustomEndpoint.IsNull() {
customEndpoint := transport_tpg.MultiEnvDefault([]string{
"GOOGLE_GKEONPREM_CUSTOM_ENDPOINT",
}, transport_tpg.DefaultBasePaths[transport_tpg.GkeonpremBasePathKey])
if customEndpoint != nil {
data.GkeonpremCustomEndpoint = types.StringValue(customEndpoint.(string))
}
}
if data.HealthcareCustomEndpoint.IsNull() {
customEndpoint := transport_tpg.MultiEnvDefault([]string{
"GOOGLE_HEALTHCARE_CUSTOM_ENDPOINT",
Expand Down
16 changes: 14 additions & 2 deletions google/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import (
"github.com/hashicorp/terraform-provider-google/google/services/gkebackup"
"github.com/hashicorp/terraform-provider-google/google/services/gkehub"
"github.com/hashicorp/terraform-provider-google/google/services/gkehub2"
"github.com/hashicorp/terraform-provider-google/google/services/gkeonprem"
"github.com/hashicorp/terraform-provider-google/google/services/healthcare"
"github.com/hashicorp/terraform-provider-google/google/services/iam2"
"github.com/hashicorp/terraform-provider-google/google/services/iambeta"
Expand Down Expand Up @@ -525,6 +526,11 @@ func Provider() *schema.Provider {
Optional: true,
ValidateFunc: transport_tpg.ValidateCustomEndpoint,
},
"gkeonprem_custom_endpoint": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: transport_tpg.ValidateCustomEndpoint,
},
"healthcare_custom_endpoint": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -1003,9 +1009,9 @@ func DatasourceMapWithErrors() (map[string]*schema.Resource, error) {
})
}

// Generated resources: 332
// Generated resources: 337
// Generated IAM resources: 207
// Total generated resources: 539
// Total generated resources: 544
func ResourceMap() map[string]*schema.Resource {
resourceMap, _ := ResourceMapWithErrors()
return resourceMap
Expand Down Expand Up @@ -1364,6 +1370,11 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
"google_gke_hub_scope_iam_member": tpgiamresource.ResourceIamMember(gkehub2.GKEHub2ScopeIamSchema, gkehub2.GKEHub2ScopeIamUpdaterProducer, gkehub2.GKEHub2ScopeIdParseFunc),
"google_gke_hub_scope_iam_policy": tpgiamresource.ResourceIamPolicy(gkehub2.GKEHub2ScopeIamSchema, gkehub2.GKEHub2ScopeIamUpdaterProducer, gkehub2.GKEHub2ScopeIdParseFunc),
"google_gke_hub_scope_rbac_role_binding": gkehub2.ResourceGKEHub2ScopeRBACRoleBinding(),
"google_gkeonprem_bare_metal_admin_cluster": gkeonprem.ResourceGkeonpremBareMetalAdminCluster(),
"google_gkeonprem_bare_metal_cluster": gkeonprem.ResourceGkeonpremBareMetalCluster(),
"google_gkeonprem_bare_metal_node_pool": gkeonprem.ResourceGkeonpremBareMetalNodePool(),
"google_gkeonprem_vmware_cluster": gkeonprem.ResourceGkeonpremVmwareCluster(),
"google_gkeonprem_vmware_node_pool": gkeonprem.ResourceGkeonpremVmwareNodePool(),
"google_healthcare_consent_store": healthcare.ResourceHealthcareConsentStore(),
"google_healthcare_consent_store_iam_binding": tpgiamresource.ResourceIamBinding(healthcare.HealthcareConsentStoreIamSchema, healthcare.HealthcareConsentStoreIamUpdaterProducer, healthcare.HealthcareConsentStoreIdParseFunc),
"google_healthcare_consent_store_iam_member": tpgiamresource.ResourceIamMember(healthcare.HealthcareConsentStoreIamSchema, healthcare.HealthcareConsentStoreIamUpdaterProducer, healthcare.HealthcareConsentStoreIdParseFunc),
Expand Down Expand Up @@ -1841,6 +1852,7 @@ func ProviderConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Pr
config.GKEBackupBasePath = d.Get("gke_backup_custom_endpoint").(string)
config.GKEHubBasePath = d.Get("gke_hub_custom_endpoint").(string)
config.GKEHub2BasePath = d.Get("gke_hub2_custom_endpoint").(string)
config.GkeonpremBasePath = d.Get("gkeonprem_custom_endpoint").(string)
config.HealthcareBasePath = d.Get("healthcare_custom_endpoint").(string)
config.IAM2BasePath = d.Get("iam2_custom_endpoint").(string)
config.IAMBetaBasePath = d.Get("iam_beta_custom_endpoint").(string)
Expand Down
144 changes: 144 additions & 0 deletions google/services/gkeonprem/gkeonprem_operation.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,147 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package gkeonprem

import (
"encoding/json"
"fmt"
"time"

"github.com/hashicorp/terraform-provider-google/google/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"

cloudresourcemanager "google.golang.org/api/cloudresourcemanager/v1"
)

type gkeonpremOpError struct {
*cloudresourcemanager.Status
}

func (e gkeonpremOpError) Error() string {
var validationCheck map[string]interface{}

for _, msg := range e.Details {
detail := make(map[string]interface{})
if err := json.Unmarshal(msg, &detail); err != nil {
continue
}

if _, ok := detail["validationCheck"]; ok {
delete(detail, "@type")
validationCheck = detail
}
}

if validationCheck != nil {
bytes, err := json.MarshalIndent(validationCheck, "", " ")
if err != nil {
return fmt.Sprintf("Error code %v message: %s validation check: %s", e.Code, e.Message, validationCheck)
}

return fmt.Sprintf("Error code %v message: %s\n %s", e.Code, e.Message, bytes)
}

return fmt.Sprintf("Error code %v, message: %s", e.Code, e.Message)
}

type gkeonpremOperationWaiter struct {
Config *transport_tpg.Config
UserAgent string
Project string
Op tpgresource.CommonOperation
}

func (w *gkeonpremOperationWaiter) State() string {
if w == nil {
return fmt.Sprintf("Operation is nil!")
}

return fmt.Sprintf("done: %v", w.Op.Done)
}

func (w *gkeonpremOperationWaiter) Error() error {
if w != nil && w.Op.Error != nil {
return &gkeonpremOpError{w.Op.Error}
}
return nil
}

func (w *gkeonpremOperationWaiter) IsRetryable(error) bool {
return false
}

func (w *gkeonpremOperationWaiter) SetOp(op interface{}) error {
if err := tpgresource.Convert(op, &w.Op); err != nil {
return err
}
return nil
}

func (w *gkeonpremOperationWaiter) OpName() string {
if w == nil {
return "<nil>"
}

return w.Op.Name
}

func (w *gkeonpremOperationWaiter) PendingStates() []string {
return []string{"done: false"}
}

func (w *gkeonpremOperationWaiter) TargetStates() []string {
return []string{"done: true"}
}

func (w *gkeonpremOperationWaiter) QueryOp() (interface{}, error) {
if w == nil {
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
}
// Returns the proper get.
url := fmt.Sprintf("%s%s", w.Config.GkeonpremBasePath, w.Op.Name)

return transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Config: w.Config,
Method: "GET",
Project: w.Project,
RawURL: url,
UserAgent: w.UserAgent,
})
}

func creategkeonpremWaiter(config *transport_tpg.Config, op map[string]interface{}, project, activity, userAgent string) (*gkeonpremOperationWaiter, error) {
w := &gkeonpremOperationWaiter{
Config: config,
UserAgent: userAgent,
Project: project,
}
if err := w.SetOp(op); err != nil {
return nil, err
}
return w, nil
}

// nolint: deadcode,unused
func GkeonpremOperationWaitTimeWithResponse(config *transport_tpg.Config, op map[string]interface{}, response *map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error {
w, err := creategkeonpremWaiter(config, op, project, activity, userAgent)
if err != nil {
return err
}
if err := tpgresource.OperationWait(w, activity, timeout, config.PollInterval); err != nil {
return err
}
return json.Unmarshal([]byte(w.Op.Response), response)
}

func GkeonpremOperationWaitTime(config *transport_tpg.Config, op map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error {
if val, ok := op["name"]; !ok || val == "" {
// This was a synchronous call - there is no operation to wait for.
return nil
}
w, err := creategkeonpremWaiter(config, op, project, activity, userAgent)
if err != nil {
// If w is nil, the op was synchronous.
return err
}
return tpgresource.OperationWait(w, activity, timeout, config.PollInterval)
}
Loading

0 comments on commit be7372e

Please sign in to comment.