Skip to content

Commit 6a6032a

Browse files
joekrMaxrovr
authored andcommitted
Bug Fix - Check OIDC is enabled in state to prevent drift
1 parent 0738843 commit 6a6032a

File tree

2 files changed

+44
-13
lines changed

2 files changed

+44
-13
lines changed

examples/container_engine/oidc_authn_token_config_multi_issuers/main.tf

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
11
// Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
22
// Licensed under the Mozilla Public License v2.0
33

4-
variable "tenancy_ocid" {
5-
}
4+
variable "tenancy_ocid" {}
65

7-
variable "user_ocid" {
8-
}
6+
variable "user_ocid" {}
97

10-
variable "compartment_ocid" {
11-
}
8+
variable "compartment_ocid" {}
129

1310
variable "region" {
1411
default = "us-ashburn-1"
1512
}
1613

17-
variable "kms_vault_id" {
18-
}
14+
variable "kms_vault_id" {}
1915

20-
variable "compartment_id" {
21-
}
16+
variable "compartment_id" {}
2217

2318
variable "cluster_cluster_pod_network_options_cni_type" {
2419
default = "OCI_VCN_IP_NATIVE"
@@ -231,6 +226,13 @@ data "oci_containerengine_cluster" "test_cluster_multi_issuer" {
231226
should_include_oidc_config_file = var.cluster_should_include_oidc_config_file
232227
}
233228

229+
output "cluster_id" {
230+
value = data.oci_containerengine_cluster.test_cluster_multi_issuer.cluster_id
231+
}
232+
output "configFile" {
233+
value = data.oci_containerengine_cluster.test_cluster_multi_issuer.should_include_oidc_config_file
234+
}
235+
234236
data "oci_containerengine_clusters" "test_clusters" {
235237
#Required
236238
compartment_id = var.compartment_ocid

internal/service/containerengine/containerengine_cluster_resource.go

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -962,9 +962,10 @@ func (s *ContainerengineClusterResourceCrud) Get() error {
962962
tmp := s.D.Id()
963963
request.ClusterId = &tmp
964964

965-
if shouldIncludeOidcConfigFile, ok := s.D.GetOkExists("should_include_oidc_config_file"); ok {
966-
tmp := shouldIncludeOidcConfigFile.(bool)
967-
request.ShouldIncludeOidcConfigFile = &tmp
965+
if getOIDCEnabledFromState(s.D) {
966+
shouldInclude := true
967+
request.ShouldIncludeOidcConfigFile = &shouldInclude
968+
log.Printf("[DEBUG] Setting ShouldIncludeOidcConfigFile to true based on state.")
968969
}
969970

970971
request.RequestMetadata.RetryPolicy = tfresource.GetRetryPolicy(s.DisableNotFoundRetries, "containerengine")
@@ -2059,3 +2060,31 @@ func ServiceLbConfigDetailsToMap(obj *oci_containerengine.ServiceLbConfigDetails
20592060

20602061
return result
20612062
}
2063+
2064+
func getOIDCEnabledFromState(d *schema.ResourceData) bool {
2065+
isEnabled := false
2066+
2067+
// Check if OIDC is enabled in state
2068+
// location "options.0.open_id_connect_token_authentication_config.0.is_open_id_connect_auth_enabled"
2069+
if options, ok := d.GetOkExists("options"); ok {
2070+
if optionsList := options.([]interface{}); len(optionsList) > 0 {
2071+
// Safe to use [0] since MaxItems: 1, but let's be explicit
2072+
optionsMap := optionsList[0].(map[string]interface{})
2073+
2074+
if oidcConfig, exists := optionsMap["open_id_connect_token_authentication_config"]; exists {
2075+
if oidcList := oidcConfig.([]interface{}); len(oidcList) > 0 {
2076+
// Again, safe to use [0] since MaxItems: 1
2077+
oidcMap := oidcList[0].(map[string]interface{})
2078+
2079+
if enabled, exists := oidcMap["is_open_id_connect_auth_enabled"]; exists {
2080+
if enabledBool, ok := enabled.(bool); ok && enabledBool {
2081+
isEnabled = true
2082+
}
2083+
}
2084+
}
2085+
}
2086+
}
2087+
}
2088+
2089+
return isEnabled
2090+
}

0 commit comments

Comments
 (0)