Skip to content

Add support for preventDrift field in ConfigManagement Fleet-level default config #18330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions google/services/gkehub2/resource_gke_hub_feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ func ResourceGKEHub2Feature() *schema.Resource {
},
},
},
"prevent_drift": {
Type: schema.TypeBool,
Optional: true,
Description: `Set to true to enable the Config Sync admission webhook to prevent drifts. If set to 'false', disables the Config Sync admission webhook and does not prevent drifts.`,
},
"source_format": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -1349,6 +1354,8 @@ func flattenGKEHub2FeatureFleetDefaultMemberConfigConfigmanagementConfigSync(v i
transformed := make(map[string]interface{})
transformed["source_format"] =
flattenGKEHub2FeatureFleetDefaultMemberConfigConfigmanagementConfigSyncSourceFormat(original["sourceFormat"], d, config)
transformed["prevent_drift"] =
flattenGKEHub2FeatureFleetDefaultMemberConfigConfigmanagementConfigSyncPreventDrift(original["preventDrift"], d, config)
transformed["git"] =
flattenGKEHub2FeatureFleetDefaultMemberConfigConfigmanagementConfigSyncGit(original["git"], d, config)
transformed["oci"] =
Expand All @@ -1359,6 +1366,10 @@ func flattenGKEHub2FeatureFleetDefaultMemberConfigConfigmanagementConfigSyncSour
return v
}

func flattenGKEHub2FeatureFleetDefaultMemberConfigConfigmanagementConfigSyncPreventDrift(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenGKEHub2FeatureFleetDefaultMemberConfigConfigmanagementConfigSyncGit(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
Expand Down Expand Up @@ -2242,6 +2253,13 @@ func expandGKEHub2FeatureFleetDefaultMemberConfigConfigmanagementConfigSync(v in
transformed["sourceFormat"] = transformedSourceFormat
}

transformedPreventDrift, err := expandGKEHub2FeatureFleetDefaultMemberConfigConfigmanagementConfigSyncPreventDrift(original["prevent_drift"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedPreventDrift); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["preventDrift"] = transformedPreventDrift
}

transformedGit, err := expandGKEHub2FeatureFleetDefaultMemberConfigConfigmanagementConfigSyncGit(original["git"], d, config)
if err != nil {
return nil, err
Expand All @@ -2263,6 +2281,10 @@ func expandGKEHub2FeatureFleetDefaultMemberConfigConfigmanagementConfigSyncSourc
return v, nil
}

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

func expandGKEHub2FeatureFleetDefaultMemberConfigConfigmanagementConfigSyncGit(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand Down
3 changes: 2 additions & 1 deletion google/services/gkehub2/resource_gke_hub_feature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,8 @@ resource "google_gke_hub_feature" "feature" {
fleet_default_member_config {
configmanagement {
version = "1.16.1"
config_sync {
config_sync {
prevent_drift = true
source_format = "unstructured"
oci {
sync_repo = "us-central1-docker.pkg.dev/corp-gke-build-artifacts/acm/configs:latest"
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/gke_hub_feature.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,10 @@ The following arguments are supported:
(Optional)
Specifies whether the Config Sync Repo is in hierarchical or unstructured mode

* `prevent_drift` -
(Optional)
Set to true to enable the Config Sync admission webhook to prevent drifts. If set to `false`, disables the Config Sync admission webhook and does not prevent drifts.

* `git` -
(Optional)
Git repo configuration for the cluster
Expand Down