@@ -793,6 +793,20 @@ func TestAccKeycloakOpenidClient_import(t *testing.T) {
793793 })
794794}
795795
796+ func TestAccKeycloakOpenidClient_import_postcondition (t * testing.T ) {
797+ resource .Test (t , resource.TestCase {
798+ ProviderFactories : testAccProviderFactories ,
799+ PreCheck : func () { testAccPreCheck (t ) },
800+ CheckDestroy : testAccCheckKeycloakOpenidClientNotDestroyed (),
801+ Steps : []resource.TestStep {
802+ {
803+ Config : testKeycloakOpenidClient_import_postcondition ("account" , false ),
804+ Check : testAccCheckKeycloakOpenidClientExistsWithEnabledStatus ("keycloak_openid_client.example" , false ),
805+ },
806+ },
807+ })
808+ }
809+
796810func TestAccKeycloakOpenidClient_useRefreshTokens (t * testing.T ) {
797811 t .Parallel ()
798812 clientId := acctest .RandomWithPrefix ("tf-acc" )
@@ -2143,3 +2157,37 @@ resource "keycloak_openid_client" "client" {
21432157}
21442158 ` , testAccRealm .Realm , clientId , clientId , enabled )
21452159}
2160+
2161+ func testKeycloakOpenidClient_import_postcondition (clientId string , enabled bool ) string {
2162+ return fmt .Sprintf (`
2163+ data "keycloak_realm" "realm" {
2164+ realm = "%s"
2165+ }
2166+ locals {
2167+ client_id = "%s"
2168+ enabled = %t
2169+ }
2170+ import {
2171+ id = "${data.keycloak_realm.realm.id}/${local.client_id}"
2172+ to = keycloak_openid_client.example
2173+ }
2174+ resource "keycloak_openid_client" "example" {
2175+ realm_id = data.keycloak_realm.realm.id
2176+ client_id = "${local.client_id}"
2177+ enabled = local.enabled
2178+ access_type = "PUBLIC"
2179+
2180+ lifecycle {
2181+ postcondition {
2182+ condition = self.enabled == local.enabled
2183+ error_message = <<-EOT
2184+ There is a bug with the keycloak provider that causes some fields to be set to unexpected values when 'import = true'.
2185+ See https://github.com/mrparkers/terraform-provider-keycloak/issues/1007
2186+
2187+ This bug has just occurred. You must perform another terraform apply for the expected values to be applied.
2188+ EOT
2189+ }
2190+ }
2191+ }
2192+ ` , testAccRealm .Realm , clientId , enabled )
2193+ }
0 commit comments