Skip to content

Commit

Permalink
Merge branch 'GoogleCloudPlatform:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
niharika-98 authored Oct 16, 2024
2 parents e3643e7 + a8e718b commit c39a9ce
Show file tree
Hide file tree
Showing 133 changed files with 8,327 additions and 762 deletions.
6 changes: 3 additions & 3 deletions .ci/magician/cmd/templates/vcr/non_exercised_tests.tmpl
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{{- if or (gt (len .NotRunBetaTests) 0) (gt (len .NotRunGATests) 0) -}}
{{- if or (gt (len .NotRunBetaTests) 0) (gt (len .NotRunGATests) 0)}}
#### Non-exercised tests

{{if gt (len .NotRunBetaTests) 0 -}}
Tests were added that are skipped in VCR:
{{color "red" "Tests were added that are skipped in VCR:"}}
{{range .NotRunBetaTests}}{{. | printf "- %s\n"}}{{end}}
{{end}}

{{if gt (len .NotRunGATests) 0 -}}
Tests were added that are GA-only additions and require manual runs:
{{color "red" "Tests were added that are GA-only additions and require manual runs:"}}
{{range .NotRunGATests}}{{. | printf "- %s\n"}}{{end}}
{{end}}
{{end}}
8 changes: 4 additions & 4 deletions .ci/magician/cmd/test_terraform_vcr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ func TestNonExercisedTestsComment(t *testing.T) {
[]string{
"#### Non-exercised tests",
"",
"Tests were added that are skipped in VCR:",
color("red", "Tests were added that are skipped in VCR:"),
"- beta-1",
"- beta-2",
},
Expand All @@ -374,7 +374,7 @@ func TestNonExercisedTestsComment(t *testing.T) {
"",
"",
"",
"Tests were added that are GA-only additions and require manual runs:",
color("red", "Tests were added that are GA-only additions and require manual runs:"),
"- ga-1",
"- ga-2",
},
Expand All @@ -391,13 +391,13 @@ func TestNonExercisedTestsComment(t *testing.T) {
[]string{
"#### Non-exercised tests",
"",
"Tests were added that are skipped in VCR:",
color("red", "Tests were added that are skipped in VCR:"),
"- beta-1",
"- beta-2",
"",
"",
"",
"Tests were added that are GA-only additions and require manual runs:",
color("red", "Tests were added that are GA-only additions and require manual runs:"),
"- ga-1",
"- ga-2",
},
Expand Down
40 changes: 34 additions & 6 deletions docs/content/develop/permadiff.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,29 @@ Add a [custom flattener]({{< ref "/develop/custom-code#custom_flatten" >}}) for
```go
func flatten{{$.GetPrefix}}{{$.TitlelizeProperty}}(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
configValue := d.Get("path.0.to.0.parent_field.0.nested_field").([]string)
rawConfigValue := d.Get("path.0.to.0.parent_field.0.nested_field")
sorted, err := tpgresource.SortStringsByConfigOrder(configValue, v.([]string))
// Convert config value to []string
configValue, err := tpgresource.InterfaceSliceToStringSlice(rawConfigValue)
if err != nil {
log.Printf("[ERROR] Failed to convert config value: %s", err)
return v
}
// Convert v to []string
apiStringValue, err := tpgresource.InterfaceSliceToStringSlice(v)
if err != nil {
log.Printf("[ERROR] Failed to convert API value: %s", err)
return v
}
sortedStrings, err := tpgresource.SortStringsByConfigOrder(configValue, apiStringValue)
if err != nil {
log.Printf("[ERROR] Could not sort API response value: %s", err)
return v
}
return sorted.(interface{})
return sortedStrings
}
```
{{< /tab >}}
Expand All @@ -251,15 +265,29 @@ Define resource-specific functions in your service package, for example at the t

```go
func flattenResourceNameFieldName(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
configValue := d.Get("path.0.to.0.parent_field.0.nested_field").([]string)
rawConfigValue := d.Get("path.0.to.0.parent_field.0.nested_field")

// Convert config value to []string
configValue, err := tpgresource.InterfaceSliceToStringSlice(rawConfigValue)
if err != nil {
log.Printf("[ERROR] Failed to convert config value: %s", err)
return v
}

// Convert v to []string
apiStringValue, err := tpgresource.InterfaceSliceToStringSlice(v)
if err != nil {
log.Printf("[ERROR] Failed to convert API value: %s", err)
return v
}

sorted, err := tpgresource.SortStringsByConfigOrder(configValue, v.([]string))
sortedStrings, err := tpgresource.SortStringsByConfigOrder(configValue, apiStringValue)
if err != nil {
log.Printf("[ERROR] Could not sort API response value: %s", err)
return v
}

return sorted.(interface{})
return sortedStrings
}
```
{{< /tab >}}
Expand Down
16 changes: 8 additions & 8 deletions mmv1/api/product.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ type Product struct {

// original value of :name before the provider override happens
// same as :name if not overridden in provider
ApiName string `yaml:"api_name"`
ApiName string `yaml:"api_name,omitempty"`

// Display Name: The full name of the GCP product; eg "Cloud Bigtable"
DisplayName string `yaml:"display_name"`
DisplayName string `yaml:"display_name,omitempty"`

Objects []*Resource
Objects []*Resource `yaml:"objects,omitempty"`

// The list of permission scopes available for the service
// For example: `https://www.googleapis.com/auth/compute`
Expand All @@ -50,19 +50,19 @@ type Product struct {

// The base URL for the service API endpoint
// For example: `https://www.googleapis.com/compute/v1/`
BaseUrl string `yaml:"base_url"`
BaseUrl string `yaml:"base_url,omitempty"`

// A function reference designed for the rare case where you
// need to use retries in operation calls. Used for the service api
// as it enables itself (self referential) and can result in occasional
// failures on operation_get. see github.com/hashicorp/terraform-provider-google/issues/9489
OperationRetry string `yaml:"operation_retry"`
OperationRetry string `yaml:"operation_retry,omitempty"`

Async *Async
Async *Async `yaml:"async,omitempty"`

LegacyName string `yaml:"legacy_name"`
LegacyName string `yaml:"legacy_name,omitempty"`

ClientName string `yaml:"client_name"`
ClientName string `yaml:"client_name,omitempty"`
}

func (p *Product) UnmarshalYAML(unmarshal func(any) error) error {
Expand Down
2 changes: 1 addition & 1 deletion mmv1/api/product/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var ORDER = []string{"ga", "beta", "alpha", "private"}
// a superset of beta, and beta a superset of GA. Each version will have a
// different version url.
type Version struct {
CaiBaseUrl string `yaml:"cai_base_url"`
CaiBaseUrl string `yaml:"cai_base_url,omitempty"`
BaseUrl string `yaml:"base_url"`
Name string
}
Expand Down
13 changes: 12 additions & 1 deletion mmv1/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,15 @@ require github.com/golang/glog v1.2.0

require github.com/otiai10/copy v1.9.0

require golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
require (
github.com/getkin/kin-openapi v0.127.0 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/invopop/yaml v0.3.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/perimeterx/marshmallow v1.1.5 // indirect
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
18 changes: 18 additions & 0 deletions mmv1/go.sum
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
github.com/getkin/kin-openapi v0.127.0 h1:Mghqi3Dhryf3F8vR370nN67pAERW+3a95vomb3MAREY=
github.com/getkin/kin-openapi v0.127.0/go.mod h1:OZrfXzUfGrNbsKj+xmFBx6E5c6yH3At/tAKSc2UszXM=
github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
github.com/golang/glog v1.2.0 h1:uCdmnmatrKCgMBlM4rMuJZWOkPDqdbZPnrMXDY4gI68=
github.com/golang/glog v1.2.0/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/invopop/yaml v0.3.1 h1:f0+ZpmhfBSS4MhG+4HYseMdJhoeeopbSKbq5Rpeelso=
github.com/invopop/yaml v0.3.1/go.mod h1:PMOp3nn4/12yEZUFfmOuNHJsZToEEOwoWsT+D81KkeA=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/otiai10/copy v1.9.0 h1:7KFNiCgZ91Ru4qW4CWPf/7jqtxLagGRmIxWldPP9VY4=
github.com/otiai10/copy v1.9.0/go.mod h1:hsfX19wcn0UWIHUQ3/4fHuehhk2UyArQ9dVFAn3FczI=
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs=
github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo=
github.com/otiai10/mint v1.4.0/go.mod h1:gifjb2MYOoULtKLqUAEILUG/9KONW6f7YsJ6vQLTlFI=
github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s=
github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw=
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 h1:LfspQV/FYTatPTr/3HzIcmiUFH7PGP+OQ6mgDYo3yuQ=
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
Expand All @@ -16,3 +32,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
9 changes: 9 additions & 0 deletions mmv1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"golang.org/x/exp/slices"

"github.com/GoogleCloudPlatform/magic-modules/mmv1/api"
"github.com/GoogleCloudPlatform/magic-modules/mmv1/openapi_generate"
"github.com/GoogleCloudPlatform/magic-modules/mmv1/provider"
)

Expand All @@ -42,6 +43,8 @@ var doNotGenerateDocs = flag.Bool("no-docs", false, "do not generate docs")

var forceProvider = flag.String("provider", "", "optional provider name. If specified, a non-default provider will be used.")

var openapiGenerate = flag.Bool("openapi-generate", false, "Generate MMv1 YAML from openapi directory (Experimental)")

// Example usage: --yaml
var yamlMode = flag.Bool("yaml", false, "copy text over from ruby yaml to go yaml")

Expand All @@ -62,6 +65,12 @@ func main() {

flag.Parse()

if *openapiGenerate {
parser := openapi_generate.NewOpenapiParser("openapi_generate/openapi", "products")
parser.Run()
return
}

if *yamlMode || *yamlTempMode {
CopyAllDescriptions(*yamlTempMode)
}
Expand Down
Loading

0 comments on commit c39a9ce

Please sign in to comment.