Skip to content

Commit

Permalink
Add resources for Cloud Logging default settings (#9409) (#1791)
Browse files Browse the repository at this point in the history
* Add folder and organization setting resources

* Try GetTestOrgTargetFromEnv instead of GetTestOrgFromEnv.

* Use correct organization for testing.

* Remove key rotation to fix VCR test.

* Don't specify fields matching default values.

* Specify true instead of yes.

* Use BootstrapKMSKeyInLocation instead of creating new keys.

* Add missing quotes

* Add additional examples to generate additional tests.

* Remove unneeded resources from examples.

* Simplify tests to be one full resource creation and one update.

* Fix typo in test

* Document and cleanup example.
[upstream:5e89b3b459087978b89d3405bd4821d9af1436f3]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Dec 14, 2023
1 parent 47f662e commit 62e777e
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/hashicorp/hcl/v2 v2.19.1
github.com/hashicorp/terraform-json v0.17.1
github.com/hashicorp/terraform-plugin-sdk/v2 v2.29.0
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20231214173619-de9d44dfc615
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20231214195243-744b4294446c
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.8.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ github.com/hashicorp/terraform-plugin-log v0.9.0/go.mod h1:rKL8egZQ/eXSyDqzLUuwU
github.com/hashicorp/terraform-plugin-mux v0.8.0 h1:WCTP66mZ+iIaIrCNJnjPEYnVjawTshnDJu12BcXK1EI=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.29.0 h1:wcOKYwPI9IorAJEBLzgclh3xVolO7ZorYd6U1vnok14=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.29.0/go.mod h1:qH/34G25Ugdj5FcM95cSoXzUgIbgfhVLXCcEcYaMwq8=
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20231214173619-de9d44dfc615 h1:ngdaMU5Ri9AF5hYFig+uxzw8Gx1Yp4JIE4B8lXv0r3Y=
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20231214173619-de9d44dfc615/go.mod h1:dx77gcRRy0m78zTwl0a49dtr3czHIqIZGnT9zMEKEJ0=
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20231214195243-744b4294446c h1:QS+Mvi8oVUSCNzFx0cTn3RZx1qF4RalbnBpQHyMSP/w=
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20231214195243-744b4294446c/go.mod h1:dx77gcRRy0m78zTwl0a49dtr3czHIqIZGnT9zMEKEJ0=
github.com/hashicorp/terraform-registry-address v0.2.2 h1:lPQBg403El8PPicg/qONZJDC6YlgCVbWDtNmmZKtBno=
github.com/hashicorp/terraform-registry-address v0.2.2/go.mod h1:LtwNbCihUoUZ3RYriyS2wF/lGPB6gF9ICLRtuDk7hSo=
github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S52uzrw4x0jKQ=
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// ----------------------------------------------------------------------------
//
// *** 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 logging

import (
"reflect"

"github.com/GoogleCloudPlatform/terraform-google-conversion/v5/tfplan2cai/converters/google/resources/cai"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
)

const LoggingFolderSettingsAssetType string = "logging.googleapis.com/FolderSettings"

func ResourceConverterLoggingFolderSettings() cai.ResourceConverter {
return cai.ResourceConverter{
AssetType: LoggingFolderSettingsAssetType,
Convert: GetLoggingFolderSettingsCaiObject,
}
}

func GetLoggingFolderSettingsCaiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) ([]cai.Asset, error) {
name, err := cai.AssetName(d, config, "//logging.googleapis.com/folders/{{folder}}/settings")
if err != nil {
return []cai.Asset{}, err
}
if obj, err := GetLoggingFolderSettingsApiObject(d, config); err == nil {
return []cai.Asset{{
Name: name,
Type: LoggingFolderSettingsAssetType,
Resource: &cai.AssetResource{
Version: "v2",
DiscoveryDocumentURI: "https://www.googleapis.com/discovery/v1/apis/logging/v2/rest",
DiscoveryName: "FolderSettings",
Data: obj,
},
}}, nil
} else {
return []cai.Asset{}, err
}
}

func GetLoggingFolderSettingsApiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]interface{}, error) {
obj := make(map[string]interface{})
kmsKeyNameProp, err := expandLoggingFolderSettingsKmsKeyName(d.Get("kms_key_name"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("kms_key_name"); !tpgresource.IsEmptyValue(reflect.ValueOf(kmsKeyNameProp)) && (ok || !reflect.DeepEqual(v, kmsKeyNameProp)) {
obj["kmsKeyName"] = kmsKeyNameProp
}
storageLocationProp, err := expandLoggingFolderSettingsStorageLocation(d.Get("storage_location"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("storage_location"); !tpgresource.IsEmptyValue(reflect.ValueOf(storageLocationProp)) && (ok || !reflect.DeepEqual(v, storageLocationProp)) {
obj["storageLocation"] = storageLocationProp
}
disableDefaultSinkProp, err := expandLoggingFolderSettingsDisableDefaultSink(d.Get("disable_default_sink"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("disable_default_sink"); !tpgresource.IsEmptyValue(reflect.ValueOf(disableDefaultSinkProp)) && (ok || !reflect.DeepEqual(v, disableDefaultSinkProp)) {
obj["disableDefaultSink"] = disableDefaultSinkProp
}

return obj, nil
}

func expandLoggingFolderSettingsKmsKeyName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandLoggingFolderSettingsStorageLocation(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandLoggingFolderSettingsDisableDefaultSink(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// ----------------------------------------------------------------------------
//
// *** 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 logging

import (
"reflect"

"github.com/GoogleCloudPlatform/terraform-google-conversion/v5/tfplan2cai/converters/google/resources/cai"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
)

const LoggingOrganizationSettingsAssetType string = "logging.googleapis.com/OrganizationSettings"

func ResourceConverterLoggingOrganizationSettings() cai.ResourceConverter {
return cai.ResourceConverter{
AssetType: LoggingOrganizationSettingsAssetType,
Convert: GetLoggingOrganizationSettingsCaiObject,
}
}

func GetLoggingOrganizationSettingsCaiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) ([]cai.Asset, error) {
name, err := cai.AssetName(d, config, "//logging.googleapis.com/organizations/{{organization}}/settings")
if err != nil {
return []cai.Asset{}, err
}
if obj, err := GetLoggingOrganizationSettingsApiObject(d, config); err == nil {
return []cai.Asset{{
Name: name,
Type: LoggingOrganizationSettingsAssetType,
Resource: &cai.AssetResource{
Version: "v2",
DiscoveryDocumentURI: "https://www.googleapis.com/discovery/v1/apis/logging/v2/rest",
DiscoveryName: "OrganizationSettings",
Data: obj,
},
}}, nil
} else {
return []cai.Asset{}, err
}
}

func GetLoggingOrganizationSettingsApiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]interface{}, error) {
obj := make(map[string]interface{})
kmsKeyNameProp, err := expandLoggingOrganizationSettingsKmsKeyName(d.Get("kms_key_name"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("kms_key_name"); !tpgresource.IsEmptyValue(reflect.ValueOf(kmsKeyNameProp)) && (ok || !reflect.DeepEqual(v, kmsKeyNameProp)) {
obj["kmsKeyName"] = kmsKeyNameProp
}
storageLocationProp, err := expandLoggingOrganizationSettingsStorageLocation(d.Get("storage_location"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("storage_location"); !tpgresource.IsEmptyValue(reflect.ValueOf(storageLocationProp)) && (ok || !reflect.DeepEqual(v, storageLocationProp)) {
obj["storageLocation"] = storageLocationProp
}
disableDefaultSinkProp, err := expandLoggingOrganizationSettingsDisableDefaultSink(d.Get("disable_default_sink"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("disable_default_sink"); !tpgresource.IsEmptyValue(reflect.ValueOf(disableDefaultSinkProp)) && (ok || !reflect.DeepEqual(v, disableDefaultSinkProp)) {
obj["disableDefaultSink"] = disableDefaultSinkProp
}

return obj, nil
}

func expandLoggingOrganizationSettingsKmsKeyName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandLoggingOrganizationSettingsStorageLocation(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandLoggingOrganizationSettingsDisableDefaultSink(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

0 comments on commit 62e777e

Please sign in to comment.