terraform-provider-bitbucketserver icon indicating copy to clipboard operation
terraform-provider-bitbucketserver copied to clipboard

terraform plan fails for bitbucketserver_plugin_config & bitbucketserver_plugin when plugin is uninstalled using bitbucket UI

Open rvnyk opened this issue 2 years ago • 0 comments

Steps to reproduce the bug :

  • Install any plugin using bitbucketserver_plugin and configuration for the plugin using bitbucketserver_plugin_config
  • From the Bitbucket UI , under admin options> managed apps , uninstall the plugin

Issue :

  • Running terraform plan tries to refresh the state for bitbucketserver_plugin and fails with failed to get plugin com.my.oauth.bitbucket-oauth from bitbucket: API Error: 404 /rest/plugins/1.0/com.my.oauth.bitbucket-oauth-key . The expectation was the resource should be marked to be created again and address the drift.

  • If we manually delete the module module.bitbucket.bitbucketserver_plugin.my_auth_plugin from the terraform state and try terraform plan we get a different error now from bitbucketserver_plugin_config ie Error: API Error: 405 /plugins/servlet/oauth/configure. This might be because bitbucketserver_plugin_config is trying to refresh the state of the config even if the plugin is uninstalled. The expectation was it should try to GET the resource if plugin doesnt exist (is this by design ? )

Following are the resource config :

resource "bitbucketserver_plugin" "my_auth_plugin" {
  count   = local.my_resource_count
  key     = "com.my.oauth.bitbucket-oauth"
  version = var.my_auth_plugin_version
  license = replace(var.my_auth_plugin_license, "\n", "\r\n")

  depends_on = [
    null_resource.bitbucket_validate, # validate if the bitbucket server is running
  ]
} 

resource "bitbucketserver_plugin_config" "my_pluginconfig" {
  config_endpoint = "/plugins/servlet/oauth/configure"
  values          = local.my_sso_config
  depends_on = [
   bitbucketserver_plugin.my_auth_plugin,
   null_resource.wait_for_mo_auth_plugin_endpoint # wait for the plugin to be installed
  ]
}
 

rvnyk avatar Aug 23 '23 20:08 rvnyk