Skip to content

Commit

Permalink
Add support for Deployment Manager (#1498)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored and emilymye committed Dec 12, 2019
1 parent 4fa78ca commit bded034
Show file tree
Hide file tree
Showing 15 changed files with 1,535 additions and 74 deletions.
3 changes: 3 additions & 0 deletions google-beta/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ type Config struct {
ContainerAnalysisBasePath string
DataFusionBasePath string
DataprocBasePath string
DeploymentManagerBasePath string
DNSBasePath string
FilestoreBasePath string
FirestoreBasePath string
Expand Down Expand Up @@ -228,6 +229,7 @@ var ComputeDefaultBasePath = "https://www.googleapis.com/compute/beta/"
var ContainerAnalysisDefaultBasePath = "https://containeranalysis.googleapis.com/v1beta1/"
var DataFusionDefaultBasePath = "https://datafusion.googleapis.com/v1beta1/"
var DataprocDefaultBasePath = "https://dataproc.googleapis.com/v1beta2/"
var DeploymentManagerDefaultBasePath = "https://www.googleapis.com/deploymentmanager/v2/"
var DNSDefaultBasePath = "https://www.googleapis.com/dns/v1beta2/"
var FilestoreDefaultBasePath = "https://file.googleapis.com/v1/"
var FirestoreDefaultBasePath = "https://firestore.googleapis.com/v1/"
Expand Down Expand Up @@ -725,6 +727,7 @@ func ConfigureBasePaths(c *Config) {
c.ContainerAnalysisBasePath = ContainerAnalysisDefaultBasePath
c.DataFusionBasePath = DataFusionDefaultBasePath
c.DataprocBasePath = DataprocDefaultBasePath
c.DeploymentManagerBasePath = DeploymentManagerDefaultBasePath
c.DNSBasePath = DNSDefaultBasePath
c.FilestoreBasePath = FilestoreDefaultBasePath
c.FirestoreBasePath = FirestoreDefaultBasePath
Expand Down
84 changes: 84 additions & 0 deletions google-beta/deployment_manager_operation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package google

import (
"bytes"
"fmt"
"google.golang.org/api/compute/v1"
)

type DeploymentManagerOperationWaiter struct {
Config *Config
Project string
OperationUrl string
ComputeOperationWaiter
}

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

func (w *DeploymentManagerOperationWaiter) QueryOp() (interface{}, error) {
if w == nil || w.Op == nil || w.Op.SelfLink == "" {
return nil, fmt.Errorf("cannot query unset/nil operation")
}
resp, err := sendRequest(w.Config, "GET", w.Project, w.Op.SelfLink, nil)
if err != nil {
return nil, err
}
op := &compute.Operation{}
if err := Convert(resp, op); err != nil {
return nil, fmt.Errorf("could not convert response to operation: %v", err)
}
return op, nil
}

func deploymentManagerOperationWaitTime(config *Config, resp interface{}, project, activity string, timeoutMinutes int) error {
op := &compute.Operation{}
err := Convert(resp, op)
if err != nil {
return err
}

w := &DeploymentManagerOperationWaiter{
Config: config,
OperationUrl: op.SelfLink,
ComputeOperationWaiter: ComputeOperationWaiter{
Project: project,
},
}
if err := w.SetOp(op); err != nil {
return err
}

return OperationWait(w, activity, timeoutMinutes)
}

func (w *DeploymentManagerOperationWaiter) Error() error {
if w != nil && w.Op != nil && w.Op.Error != nil {
return DeploymentManagerOperationError{
HTTPStatusCode: w.Op.HttpErrorStatusCode,
HTTPMessage: w.Op.HttpErrorMessage,
OperationError: *w.Op.Error,
}
}
return nil
}

// DeploymentManagerOperationError wraps information from the compute.Operation
// in an implementation of Error.
type DeploymentManagerOperationError struct {
HTTPStatusCode int64
HTTPMessage string
compute.OperationError
}

func (e DeploymentManagerOperationError) Error() string {
var buf bytes.Buffer
buf.WriteString("Deployment Manager returned errors for this operation, likely due to invalid configuration.")
buf.WriteString(fmt.Sprintf("Operation failed with HTTP error %d: %s.", e.HTTPStatusCode, e.HTTPMessage))
buf.WriteString("Errors returned: \n")
for _, err := range e.Errors {
buf.WriteString(err.Message + "\n")
}
return buf.String()
}
14 changes: 12 additions & 2 deletions google-beta/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,14 @@ func Provider() terraform.ResourceProvider {
"GOOGLE_DATAPROC_CUSTOM_ENDPOINT",
}, DataprocDefaultBasePath),
},
"deployment_manager_custom_endpoint": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateCustomEndpoint,
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
"GOOGLE_DEPLOYMENT_MANAGER_CUSTOM_ENDPOINT",
}, DeploymentManagerDefaultBasePath),
},
"dns_custom_endpoint": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -504,9 +512,9 @@ func Provider() terraform.ResourceProvider {
return provider
}

// Generated resources: 103
// Generated resources: 104
// Generated IAM resources: 42
// Total generated resources: 145
// Total generated resources: 146
func ResourceMap() map[string]*schema.Resource {
resourceMap, _ := ResourceMapWithErrors()
return resourceMap
Expand Down Expand Up @@ -602,6 +610,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
"google_container_analysis_note": resourceContainerAnalysisNote(),
"google_data_fusion_instance": resourceDataFusionInstance(),
"google_dataproc_autoscaling_policy": resourceDataprocAutoscalingPolicy(),
"google_deployment_manager_deployment": resourceDeploymentManagerDeployment(),
"google_dns_managed_zone": resourceDNSManagedZone(),
"google_dns_policy": resourceDNSPolicy(),
"google_filestore_instance": resourceFilestoreInstance(),
Expand Down Expand Up @@ -844,6 +853,7 @@ func providerConfigure(d *schema.ResourceData, terraformVersion string) (interfa
config.ContainerAnalysisBasePath = d.Get("container_analysis_custom_endpoint").(string)
config.DataFusionBasePath = d.Get("data_fusion_custom_endpoint").(string)
config.DataprocBasePath = d.Get("dataproc_custom_endpoint").(string)
config.DeploymentManagerBasePath = d.Get("deployment_manager_custom_endpoint").(string)
config.DNSBasePath = d.Get("dns_custom_endpoint").(string)
config.FilestoreBasePath = d.Get("filestore_custom_endpoint").(string)
config.FirestoreBasePath = d.Get("firestore_custom_endpoint").(string)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestAccAppEngineStandardAppVersion_appEngineStandardAppVersionExample(t *te
ResourceName: "google_app_engine_standard_app_version.myapp_v1",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"threadsafe", "env_variables", "deployment", "entrypoint", "instance_class", "delete_service_on_destroy"},
ImportStateVerifyIgnore: []string{"threadsafe", "env_variables", "deployment", "entrypoint", "instance_class", "service", "delete_service_on_destroy"},
},
},
})
Expand Down
4 changes: 2 additions & 2 deletions google-beta/resource_bigtable_app_profile_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestAccBigtableAppProfile_bigtableAppProfileMulticlusterExample(t *testing.
ResourceName: "google_bigtable_app_profile.ap",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"ignore_warnings"},
ImportStateVerifyIgnore: []string{"app_profile_id", "instance", "ignore_warnings", "ignore_warnings"},
},
},
})
Expand Down Expand Up @@ -90,7 +90,7 @@ func TestAccBigtableAppProfile_bigtableAppProfileSingleclusterExample(t *testing
ResourceName: "google_bigtable_app_profile.ap",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"ignore_warnings"},
ImportStateVerifyIgnore: []string{"app_profile_id", "instance", "ignore_warnings", "ignore_warnings"},
},
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ func TestAccCloudRunDomainMapping_cloudRunDomainMappingBasicExample(t *testing.T
Config: testAccCloudRunDomainMapping_cloudRunDomainMappingBasicExample(context),
},
{
ResourceName: "google_cloud_run_domain_mapping.default",
ImportState: true,
ImportStateVerify: true,
ResourceName: "google_cloud_run_domain_mapping.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"name", "location"},
},
},
})
Expand Down
21 changes: 12 additions & 9 deletions google-beta/resource_cloud_run_service_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ func TestAccCloudRunService_cloudRunServiceBasicExample(t *testing.T) {
Config: testAccCloudRunService_cloudRunServiceBasicExample(context),
},
{
ResourceName: "google_cloud_run_service.default",
ImportState: true,
ImportStateVerify: true,
ResourceName: "google_cloud_run_service.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"name", "location"},
},
},
})
Expand Down Expand Up @@ -88,9 +89,10 @@ func TestAccCloudRunService_cloudRunServiceSqlExample(t *testing.T) {
Config: testAccCloudRunService_cloudRunServiceSqlExample(context),
},
{
ResourceName: "google_cloud_run_service.default",
ImportState: true,
ImportStateVerify: true,
ResourceName: "google_cloud_run_service.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"name", "location"},
},
},
})
Expand Down Expand Up @@ -146,9 +148,10 @@ func TestAccCloudRunService_cloudRunServiceNoauthExample(t *testing.T) {
Config: testAccCloudRunService_cloudRunServiceNoauthExample(context),
},
{
ResourceName: "google_cloud_run_service.default",
ImportState: true,
ImportStateVerify: true,
ResourceName: "google_cloud_run_service.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"name", "location"},
},
},
})
Expand Down
7 changes: 4 additions & 3 deletions google-beta/resource_cloud_tasks_queue_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ func TestAccCloudTasksQueue_queueBasicExample(t *testing.T) {
Config: testAccCloudTasksQueue_queueBasicExample(context),
},
{
ResourceName: "google_cloud_tasks_queue.default",
ImportState: true,
ImportStateVerify: true,
ResourceName: "google_cloud_tasks_queue.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"location"},
},
},
})
Expand Down
Loading

0 comments on commit bded034

Please sign in to comment.