Skip to content

Commit

Permalink
Add Backup for GKE BackupPlan Resource (beta) (hashicorp#6845)
Browse files Browse the repository at this point in the history
Fixes hashicorp/terraform-provider-google#12634

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Dec 5, 2022
1 parent 9a8e9f8 commit f9ecb5e
Show file tree
Hide file tree
Showing 9 changed files with 2,089 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/6845.txt
@@ -0,0 +1,3 @@
```release-note:new-resource
`google_gke_backup_backup_plan` (beta)
```
4 changes: 4 additions & 0 deletions google-beta/config.go
Expand Up @@ -223,6 +223,7 @@ type Config struct {
FirebaseHostingBasePath string
FirestoreBasePath string
GameServicesBasePath string
GKEBackupBasePath string
GKEHubBasePath string
HealthcareBasePath string
IAM2BasePath string
Expand Down Expand Up @@ -334,6 +335,7 @@ const FirebaseBasePathKey = "Firebase"
const FirebaseHostingBasePathKey = "FirebaseHosting"
const FirestoreBasePathKey = "Firestore"
const GameServicesBasePathKey = "GameServices"
const GKEBackupBasePathKey = "GKEBackup"
const GKEHubBasePathKey = "GKEHub"
const HealthcareBasePathKey = "Healthcare"
const IAM2BasePathKey = "IAM2"
Expand Down Expand Up @@ -439,6 +441,7 @@ var DefaultBasePaths = map[string]string{
FirebaseHostingBasePathKey: "https://firebasehosting.googleapis.com/v1beta1/",
FirestoreBasePathKey: "https://firestore.googleapis.com/v1/",
GameServicesBasePathKey: "https://gameservices.googleapis.com/v1beta/",
GKEBackupBasePathKey: "https://gkebackup.googleapis.com/v1/",
GKEHubBasePathKey: "https://gkehub.googleapis.com/v1beta1/",
HealthcareBasePathKey: "https://healthcare.googleapis.com/v1beta1/",
IAM2BasePathKey: "https://iam.googleapis.com/v2beta/",
Expand Down Expand Up @@ -1320,6 +1323,7 @@ func ConfigureBasePaths(c *Config) {
c.FirebaseHostingBasePath = DefaultBasePaths[FirebaseHostingBasePathKey]
c.FirestoreBasePath = DefaultBasePaths[FirestoreBasePathKey]
c.GameServicesBasePath = DefaultBasePaths[GameServicesBasePathKey]
c.GKEBackupBasePath = DefaultBasePaths[GKEBackupBasePathKey]
c.GKEHubBasePath = DefaultBasePaths[GKEHubBasePathKey]
c.HealthcareBasePath = DefaultBasePaths[HealthcareBasePathKey]
c.IAM2BasePath = DefaultBasePaths[IAM2BasePathKey]
Expand Down
1 change: 1 addition & 0 deletions google-beta/config_test_utils.go
Expand Up @@ -69,6 +69,7 @@ func configureTestBasePaths(c *Config, url string) {
c.FirebaseHostingBasePath = url
c.FirestoreBasePath = url
c.GameServicesBasePath = url
c.GKEBackupBasePath = url
c.GKEHubBasePath = url
c.HealthcareBasePath = url
c.IAM2BasePath = url
Expand Down
75 changes: 75 additions & 0 deletions google-beta/gke_backup_operation.go
@@ -0,0 +1,75 @@
// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** Type: MMv1 ***
//
// ----------------------------------------------------------------------------
//
// This file is automatically generated by Magic Modules and manual
// changes will be clobbered when the file is regenerated.
//
// Please read more about how to change this file in
// .github/CONTRIBUTING.md.
//
// ----------------------------------------------------------------------------

package google

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

type GKEBackupOperationWaiter struct {
Config *Config
UserAgent string
Project string
CommonOperationWaiter
}

func (w *GKEBackupOperationWaiter) 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.GKEBackupBasePath, w.CommonOperationWaiter.Op.Name)

return sendRequest(w.Config, "GET", w.Project, url, w.UserAgent, nil)
}

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

// nolint: deadcode,unused
func gKEBackupOperationWaitTimeWithResponse(config *Config, op map[string]interface{}, response *map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error {
w, err := createGKEBackupWaiter(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.CommonOperationWaiter.Op.Response), response)
}

func gKEBackupOperationWaitTime(config *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 := createGKEBackupWaiter(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)
}
14 changes: 12 additions & 2 deletions google-beta/provider.go
Expand Up @@ -557,6 +557,14 @@ func Provider() *schema.Provider {
"GOOGLE_GAME_SERVICES_CUSTOM_ENDPOINT",
}, DefaultBasePaths[GameServicesBasePathKey]),
},
"gke_backup_custom_endpoint": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateCustomEndpoint,
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
"GOOGLE_GKE_BACKUP_CUSTOM_ENDPOINT",
}, DefaultBasePaths[GKEBackupBasePathKey]),
},
"gke_hub_custom_endpoint": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -1039,9 +1047,9 @@ func Provider() *schema.Provider {
return provider
}

// Generated resources: 287
// Generated resources: 288
// Generated IAM resources: 189
// Total generated resources: 476
// Total generated resources: 477
func ResourceMap() map[string]*schema.Resource {
resourceMap, _ := ResourceMapWithErrors()
return resourceMap
Expand Down Expand Up @@ -1348,6 +1356,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
"google_game_services_game_server_deployment": resourceGameServicesGameServerDeployment(),
"google_game_services_game_server_config": resourceGameServicesGameServerConfig(),
"google_game_services_game_server_deployment_rollout": resourceGameServicesGameServerDeploymentRollout(),
"google_gke_backup_backup_plan": resourceGKEBackupBackupPlan(),
"google_gke_hub_membership": resourceGKEHubMembership(),
"google_gke_hub_membership_iam_binding": ResourceIamBinding(GKEHubMembershipIamSchema, GKEHubMembershipIamUpdaterProducer, GKEHubMembershipIdParseFunc),
"google_gke_hub_membership_iam_member": ResourceIamMember(GKEHubMembershipIamSchema, GKEHubMembershipIamUpdaterProducer, GKEHubMembershipIdParseFunc),
Expand Down Expand Up @@ -1807,6 +1816,7 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Pr
config.FirebaseHostingBasePath = d.Get("firebase_hosting_custom_endpoint").(string)
config.FirestoreBasePath = d.Get("firestore_custom_endpoint").(string)
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.HealthcareBasePath = d.Get("healthcare_custom_endpoint").(string)
config.IAM2BasePath = d.Get("iam2_custom_endpoint").(string)
Expand Down

0 comments on commit f9ecb5e

Please sign in to comment.