Skip to content

Commit

Permalink
Add google_gkeonprem_vmware_cluster resource (#7714) (#5533)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
Co-authored-by: Riley Karson <rileykarson@google.com>
  • Loading branch information
modular-magician and rileykarson authored Apr 21, 2023
1 parent e38ae1e commit 5b60f62
Show file tree
Hide file tree
Showing 13 changed files with 5,118 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/7714.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
`google_gkeonprem_vmware_cluster`
```
1 change: 1 addition & 0 deletions google-beta/config_test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func configureTestBasePaths(c *transport_tpg.Config, url string) {
c.GameServicesBasePath = url
c.GKEBackupBasePath = url
c.GKEHubBasePath = url
c.GkeonpremBasePath = url
c.HealthcareBasePath = url
c.IAM2BasePath = url
c.IAMBetaBasePath = url
Expand Down
9 changes: 9 additions & 0 deletions google-beta/framework_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func (p *frameworkProvider) LoadAndValidateFramework(ctx context.Context, data P
p.GameServicesBasePath = data.GameServicesCustomEndpoint.ValueString()
p.GKEBackupBasePath = data.GKEBackupCustomEndpoint.ValueString()
p.GKEHubBasePath = data.GKEHubCustomEndpoint.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 @@ -757,6 +758,14 @@ func (p *frameworkProvider) HandleDefaults(ctx context.Context, data *ProviderMo
data.GKEHubCustomEndpoint = 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
7 changes: 7 additions & 0 deletions google-beta/framework_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ type frameworkProvider struct {
GameServicesBasePath string
GKEBackupBasePath string
GKEHubBasePath string
GkeonpremBasePath string
HealthcareBasePath string
IAM2BasePath string
IAMBetaBasePath string
Expand Down Expand Up @@ -584,6 +585,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
136 changes: 136 additions & 0 deletions google-beta/gkeonprem_operation.go
Original file line number Diff line number Diff line change
@@ -1 +1,137 @@
package google

import (
"encoding/json"
"fmt"
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
"time"

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 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 := 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 SendRequest(w.Config, "GET", w.Project, url, w.UserAgent, nil)
}

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 := 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 OperationWait(w, activity, timeout, config.PollInterval)
}
11 changes: 9 additions & 2 deletions google-beta/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,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 @@ -796,9 +801,9 @@ func Provider() *schema.Provider {
return provider
}

// Generated resources: 327
// Generated resources: 328
// Generated IAM resources: 219
// Total generated resources: 546
// Total generated resources: 547
func ResourceMap() map[string]*schema.Resource {
resourceMap, _ := ResourceMapWithErrors()
return resourceMap
Expand Down Expand Up @@ -1158,6 +1163,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
"google_gke_hub_membership_iam_binding": ResourceIamBinding(GKEHubMembershipIamSchema, GKEHubMembershipIamUpdaterProducer, GKEHubMembershipIdParseFunc),
"google_gke_hub_membership_iam_member": ResourceIamMember(GKEHubMembershipIamSchema, GKEHubMembershipIamUpdaterProducer, GKEHubMembershipIdParseFunc),
"google_gke_hub_membership_iam_policy": ResourceIamPolicy(GKEHubMembershipIamSchema, GKEHubMembershipIamUpdaterProducer, GKEHubMembershipIdParseFunc),
"google_gkeonprem_vmware_cluster": ResourceGkeonpremVmwareCluster(),
"google_healthcare_consent_store": ResourceHealthcareConsentStore(),
"google_healthcare_consent_store_iam_binding": ResourceIamBinding(HealthcareConsentStoreIamSchema, HealthcareConsentStoreIamUpdaterProducer, HealthcareConsentStoreIdParseFunc),
"google_healthcare_consent_store_iam_member": ResourceIamMember(HealthcareConsentStoreIamSchema, HealthcareConsentStoreIamUpdaterProducer, HealthcareConsentStoreIdParseFunc),
Expand Down Expand Up @@ -1656,6 +1662,7 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Pr
config.GameServicesBasePath = d.Get("game_services_custom_endpoint").(string)
config.GKEBackupBasePath = d.Get("gke_backup_custom_endpoint").(string)
config.GKEHubBasePath = d.Get("gke_hub_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
1 change: 1 addition & 0 deletions google-beta/provider_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type ProviderModel struct {
GameServicesCustomEndpoint types.String `tfsdk:"game_services_custom_endpoint"`
GKEBackupCustomEndpoint types.String `tfsdk:"gke_backup_custom_endpoint"`
GKEHubCustomEndpoint types.String `tfsdk:"gke_hub_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
Loading

0 comments on commit 5b60f62

Please sign in to comment.