Skip to content

Commit

Permalink
Update branch
Browse files Browse the repository at this point in the history
  • Loading branch information
slevenick committed Mar 9, 2022
1 parent 6de47df commit 626025e
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
Empty file.
86 changes: 86 additions & 0 deletions tpgtools/serialization.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
apikeysBeta "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/apikeys/beta"
assuredworkloads "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/assuredworkloads"
assuredworkloadsBeta "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/assuredworkloads/beta"
bigqueryreservation "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/bigqueryreservation"
bigqueryreservationBeta "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/bigqueryreservation/beta"
cloudbuild "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/cloudbuild"
cloudbuildBeta "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/cloudbuild/beta"
cloudresourcemanager "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/cloudresourcemanager"
Expand Down Expand Up @@ -67,6 +69,8 @@ func DCLToTerraformReference(product DCLPackageName, resource miscellaneousNameS
return "google_apikeys_key", nil
case "assuredworkloads/workload":
return "google_assured_workloads_workload", nil
case "bigqueryreservation/assignment":
return "google_bigquery_reservation_assignment", nil
case "cloudbuild/worker_pool":
return "google_cloudbuild_worker_pool", nil
case "cloudresourcemanager/folder":
Expand Down Expand Up @@ -123,6 +127,8 @@ func DCLToTerraformReference(product DCLPackageName, resource miscellaneousNameS
return "google_apikeys_key", nil
case "assuredworkloads/workload":
return "google_assured_workloads_workload", nil
case "bigqueryreservation/assignment":
return "google_bigquery_reservation_assignment", nil
case "cloudbuild/worker_pool":
return "google_cloudbuild_worker_pool", nil
case "cloudresourcemanager/folder":
Expand Down Expand Up @@ -191,6 +197,12 @@ func ConvertSampleJSONToHCL(product DCLPackageName, resource miscellaneousNameSn
return "", err
}
return AssuredWorkloadsWorkloadBetaAsHCL(*r, hasGAEquivalent)
case "bigqueryreservation/assignment":
r := &bigqueryreservationBeta.Assignment{}
if err := json.Unmarshal(b, r); err != nil {
return "", err
}
return BigqueryReservationAssignmentBetaAsHCL(*r, hasGAEquivalent)
case "cloudbuild/worker_pool":
r := &cloudbuildBeta.WorkerPool{}
if err := json.Unmarshal(b, r); err != nil {
Expand Down Expand Up @@ -351,6 +363,12 @@ func ConvertSampleJSONToHCL(product DCLPackageName, resource miscellaneousNameSn
return "", err
}
return AssuredWorkloadsWorkloadAsHCL(*r, hasGAEquivalent)
case "bigqueryreservation/assignment":
r := &bigqueryreservation.Assignment{}
if err := json.Unmarshal(b, r); err != nil {
return "", err
}
return BigqueryReservationAssignmentAsHCL(*r, hasGAEquivalent)
case "cloudbuild/worker_pool":
r := &cloudbuild.WorkerPool{}
if err := json.Unmarshal(b, r); err != nil {
Expand Down Expand Up @@ -715,6 +733,40 @@ func convertAssuredWorkloadsWorkloadBetaResourcesToHCL(r *assuredworkloadsBeta.W
return outputConfig + "}"
}

// BigqueryReservationAssignmentBetaAsHCL returns a string representation of the specified resource in HCL.
// The generated HCL will include every settable field as a literal - that is, no
// variables, no references. This may not be the best possible representation, but
// the crucial point is that `terraform import; terraform apply` will not produce
// any changes. We do not validate that the resource specified will pass terraform
// validation unless is an object returned from the API after an Apply.
func BigqueryReservationAssignmentBetaAsHCL(r bigqueryreservationBeta.Assignment, hasGAEquivalent bool) (string, error) {
outputConfig := "resource \"google_bigquery_reservation_assignment\" \"output\" {\n"
if r.Assignee != nil {
outputConfig += fmt.Sprintf("\tassignee = %#v\n", *r.Assignee)
}
if r.JobType != nil {
outputConfig += fmt.Sprintf("\tjob_type = %#v\n", *r.JobType)
}
if r.Reservation != nil {
outputConfig += fmt.Sprintf("\treservation = %#v\n", *r.Reservation)
}
if r.Location != nil {
outputConfig += fmt.Sprintf("\tlocation = %#v\n", *r.Location)
}
if r.Project != nil {
outputConfig += fmt.Sprintf("\tproject = %#v\n", *r.Project)
}
formatted, err := formatHCL(outputConfig + "}")
if err != nil {
return "", err
}
if !hasGAEquivalent {
// The formatter will not accept the google-beta symbol because it is injected during testing.
return withProviderLine(formatted), nil
}
return formatted, nil
}

// CloudbuildWorkerPoolBetaAsHCL returns a string representation of the specified resource in HCL.
// The generated HCL will include every settable field as a literal - that is, no
// variables, no references. This may not be the best possible representation, but
Expand Down Expand Up @@ -5423,6 +5475,40 @@ func convertAssuredWorkloadsWorkloadResourcesToHCL(r *assuredworkloads.WorkloadR
return outputConfig + "}"
}

// BigqueryReservationAssignmentAsHCL returns a string representation of the specified resource in HCL.
// The generated HCL will include every settable field as a literal - that is, no
// variables, no references. This may not be the best possible representation, but
// the crucial point is that `terraform import; terraform apply` will not produce
// any changes. We do not validate that the resource specified will pass terraform
// validation unless is an object returned from the API after an Apply.
func BigqueryReservationAssignmentAsHCL(r bigqueryreservation.Assignment, hasGAEquivalent bool) (string, error) {
outputConfig := "resource \"google_bigquery_reservation_assignment\" \"output\" {\n"
if r.Assignee != nil {
outputConfig += fmt.Sprintf("\tassignee = %#v\n", *r.Assignee)
}
if r.JobType != nil {
outputConfig += fmt.Sprintf("\tjob_type = %#v\n", *r.JobType)
}
if r.Reservation != nil {
outputConfig += fmt.Sprintf("\treservation = %#v\n", *r.Reservation)
}
if r.Location != nil {
outputConfig += fmt.Sprintf("\tlocation = %#v\n", *r.Location)
}
if r.Project != nil {
outputConfig += fmt.Sprintf("\tproject = %#v\n", *r.Project)
}
formatted, err := formatHCL(outputConfig + "}")
if err != nil {
return "", err
}
if !hasGAEquivalent {
// The formatter will not accept the google-beta symbol because it is injected during testing.
return withProviderLine(formatted), nil
}
return formatted, nil
}

// CloudbuildWorkerPoolAsHCL returns a string representation of the specified resource in HCL.
// The generated HCL will include every settable field as a literal - that is, no
// variables, no references. This may not be the best possible representation, but
Expand Down

0 comments on commit 626025e

Please sign in to comment.