Skip to content

Commit

Permalink
Attached clusters (#6858) (#13374)
Browse files Browse the repository at this point in the history
* Add support for google_container_attached clusters resource.

- Add support for CRUD operations to attached clusters.
- Add support for data source to retrieve valid attached cluster
  platform versions.
- Add support for data source to pull a manifest for deploying the
  install agent to a cluster before attaching.

* Split attached cluster data sources into a separate PR

* Address review comments.

- Add update test
- Proper handling of update mask for updates
- Changed logging_config handling to explicitly send an empty object if
  missing
- Misc cleanup

* Address more review comments.

- Fix update test formatting
- Prevent destroying containerattached resource during update test
- Remove auto-format for fleet project and validate format instead
- Fix error field structure

Signed-off-by: Modular Magician <magic-modules@google.com>

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Jan 3, 2023
1 parent 71edccc commit 54daef4
Show file tree
Hide file tree
Showing 10 changed files with 2,085 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/6858.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
`google_container_attached_cluster`
```
4 changes: 4 additions & 0 deletions google/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ type Config struct {
CloudTasksBasePath string
ComputeBasePath string
ContainerAnalysisBasePath string
ContainerAttachedBasePath string
DataCatalogBasePath string
DataFusionBasePath string
DataLossPreventionBasePath string
Expand Down Expand Up @@ -301,6 +302,7 @@ const CloudSchedulerBasePathKey = "CloudScheduler"
const CloudTasksBasePathKey = "CloudTasks"
const ComputeBasePathKey = "Compute"
const ContainerAnalysisBasePathKey = "ContainerAnalysis"
const ContainerAttachedBasePathKey = "ContainerAttached"
const DataCatalogBasePathKey = "DataCatalog"
const DataFusionBasePathKey = "DataFusion"
const DataLossPreventionBasePathKey = "DataLossPrevention"
Expand Down Expand Up @@ -396,6 +398,7 @@ var DefaultBasePaths = map[string]string{
CloudTasksBasePathKey: "https://cloudtasks.googleapis.com/v2/",
ComputeBasePathKey: "https://compute.googleapis.com/compute/v1/",
ContainerAnalysisBasePathKey: "https://containeranalysis.googleapis.com/v1/",
ContainerAttachedBasePathKey: "https://{{location}}-gkemulticloud.googleapis.com/v1/",
DataCatalogBasePathKey: "https://datacatalog.googleapis.com/v1/",
DataFusionBasePathKey: "https://datafusion.googleapis.com/v1/",
DataLossPreventionBasePathKey: "https://dlp.googleapis.com/v2/",
Expand Down Expand Up @@ -1253,6 +1256,7 @@ func ConfigureBasePaths(c *Config) {
c.CloudTasksBasePath = DefaultBasePaths[CloudTasksBasePathKey]
c.ComputeBasePath = DefaultBasePaths[ComputeBasePathKey]
c.ContainerAnalysisBasePath = DefaultBasePaths[ContainerAnalysisBasePathKey]
c.ContainerAttachedBasePath = DefaultBasePaths[ContainerAttachedBasePathKey]
c.DataCatalogBasePath = DefaultBasePaths[DataCatalogBasePathKey]
c.DataFusionBasePath = DefaultBasePaths[DataFusionBasePathKey]
c.DataLossPreventionBasePath = DefaultBasePaths[DataLossPreventionBasePathKey]
Expand Down
1 change: 1 addition & 0 deletions google/config_test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func configureTestBasePaths(c *Config, url string) {
c.CloudTasksBasePath = url
c.ComputeBasePath = url
c.ContainerAnalysisBasePath = url
c.ContainerAttachedBasePath = url
c.DataCatalogBasePath = url
c.DataFusionBasePath = url
c.DataLossPreventionBasePath = url
Expand Down
64 changes: 64 additions & 0 deletions google/container_attached_operation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package google

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

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

func (w *ContainerAttachedOperationWaiter) QueryOp() (interface{}, error) {
if w == nil {
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
}

region := GetRegionFromRegionalSelfLink(w.CommonOperationWaiter.Op.Name)

// Returns the proper get.
url := fmt.Sprintf("https://%s-gkemulticloud.googleapis.com/v1/%s", region, w.CommonOperationWaiter.Op.Name)

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

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

// nolint: deadcode,unused
func containerAttachedOperationWaitTimeWithResponse(config *Config, op map[string]interface{}, response *map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error {
w, err := createContainerAttachedWaiter(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 containerAttachedOperationWaitTime(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 := createContainerAttachedWaiter(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/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,14 @@ func Provider() *schema.Provider {
"GOOGLE_CONTAINER_ANALYSIS_CUSTOM_ENDPOINT",
}, DefaultBasePaths[ContainerAnalysisBasePathKey]),
},
"container_attached_custom_endpoint": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateCustomEndpoint,
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
"GOOGLE_CONTAINER_ATTACHED_CUSTOM_ENDPOINT",
}, DefaultBasePaths[ContainerAttachedBasePathKey]),
},
"data_catalog_custom_endpoint": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -956,9 +964,9 @@ func Provider() *schema.Provider {
return provider
}

// Generated resources: 256
// Generated resources: 257
// Generated IAM resources: 159
// Total generated resources: 415
// Total generated resources: 416
func ResourceMap() map[string]*schema.Resource {
resourceMap, _ := ResourceMapWithErrors()
return resourceMap
Expand Down Expand Up @@ -1154,6 +1162,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
"google_compute_target_grpc_proxy": resourceComputeTargetGrpcProxy(),
"google_container_analysis_note": resourceContainerAnalysisNote(),
"google_container_analysis_occurrence": resourceContainerAnalysisOccurrence(),
"google_container_attached_cluster": resourceContainerAttachedCluster(),
"google_data_catalog_entry_group": resourceDataCatalogEntryGroup(),
"google_data_catalog_entry_group_iam_binding": ResourceIamBinding(DataCatalogEntryGroupIamSchema, DataCatalogEntryGroupIamUpdaterProducer, DataCatalogEntryGroupIdParseFunc),
"google_data_catalog_entry_group_iam_member": ResourceIamMember(DataCatalogEntryGroupIamSchema, DataCatalogEntryGroupIamUpdaterProducer, DataCatalogEntryGroupIdParseFunc),
Expand Down Expand Up @@ -1621,6 +1630,7 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Pr
config.CloudTasksBasePath = d.Get("cloud_tasks_custom_endpoint").(string)
config.ComputeBasePath = d.Get("compute_custom_endpoint").(string)
config.ContainerAnalysisBasePath = d.Get("container_analysis_custom_endpoint").(string)
config.ContainerAttachedBasePath = d.Get("container_attached_custom_endpoint").(string)
config.DataCatalogBasePath = d.Get("data_catalog_custom_endpoint").(string)
config.DataFusionBasePath = d.Get("data_fusion_custom_endpoint").(string)
config.DataLossPreventionBasePath = d.Get("data_loss_prevention_custom_endpoint").(string)
Expand Down
Loading

0 comments on commit 54daef4

Please sign in to comment.