gavinbunney / terraform-provider-bitbucketserver

Terraform provider for Bitbucket Server Management
https://registry.terraform.io/providers/gavinbunney/bitbucketserver/latest
Mozilla Public License 2.0
29 stars 33 forks source link

Plugin configuration management #2

Closed hgontijo closed 4 years ago

hgontijo commented 4 years ago

Could you release a new version as well? Thanks 👍

hgontijo commented 4 years ago

Thanks for the quick turnaround. I squashed into a single commit to remove the corp URLs. :D Could you try to remove your comment so sensitive data is also deleted? Thanks!

gavinbunney commented 4 years ago

@hgontijo Tests failed on CI 😢 https://travis-ci.org/gavinbunney/terraform-provider-bitbucketserver

You can run them locally with:

make testacc-bitbucket
hgontijo commented 4 years ago

I'm running the data plugin config resource test with this:

    config := `
        resource "bitbucketserver_plugin" "config_test" {
            key     = "de.codecentric.atlassian.oidc.bitbucket-oidc-plugin"
            version = "1.5.1"
        }

        data "bitbucketserver_plugin_config" "config_test" {
            key = "oidc"
            depends_on = [ bitbucketserver_plugin.config_test ]
        }
    `

And getting this error:

--- FAIL: TestAccBitbucketPluginConfig_basic (3.67s)
    testing.go:568: Step 0 error: After applying this step and refreshing, the plan was not empty:

        DIFF:

        UPDATE: data.bitbucketserver_plugin_config.config_test
          id:           "" => "<computed>"
          key:          "" => "oidc"
          validlicense: "" => "<computed>"
          values:       "" => "<computed>"

        STATE:

        bitbucketserver_plugin.config_test:
          ID = de.codecentric.atlassian.oidc.bitbucket-oidc-plugin
          provider = provider.bitbucketserver
          applied_license.# = 1
          applied_license.0.active = false
          applied_license.0.auto_renewal = false
          applied_license.0.contact_email = 
          applied_license.0.crossgradeable = false
          applied_license.0.data_center = false
          applied_license.0.enterprise = false
          applied_license.0.evaluation = false
          applied_license.0.expiry_date = 0001-01-01 00:00:00 +0000 UTC
          applied_license.0.license_type = 
          applied_license.0.maintenance_expired = false
          applied_license.0.maintenance_expiry_date = 0001-01-01 00:00:00 +0000 UTC
          applied_license.0.nearly_expired = false
          applied_license.0.organization_name = 
          applied_license.0.purchase_past_server_cutoff_date = false
          applied_license.0.raw_license = 
          applied_license.0.renewable = false
          applied_license.0.subscription = false
          applied_license.0.support_entitlement_number = 
          applied_license.0.upgradable = false
          applied_license.0.valid = false
          description = Plugin to add OpenID Connect Single-Sign-On support to Bitbucket.
          enabled = true
          enabled_by_default = true
          key = de.codecentric.atlassian.oidc.bitbucket-oidc-plugin
          name = Bitbucket Enterprise SSO with Keycloak
          optional = true
          user_installed = true
          vendor.link = https://www.codecentric.de/
          vendor.marketplace_link = https://www.codecentric.de/
          vendor.name = codecentric
          version = 1.5.1

The data schema looks like:

        Schema: map[string]*schema.Schema{
            "key": {
                Type:     schema.TypeString,
                Required: true,
            },
            "validlicense": {
                Type:     schema.TypeBool,
                Computed: true,
            },
            "values": {
                Type:     schema.TypeString,
                Computed: true,
            },
        },

Some idea of could be causing this issue?

gavinbunney commented 4 years ago

Dug a little bit deeper into your changes.... some thoughts:

It's failing as the "odic" endpoint you're hitting is updating the validlisense field in the resource from false to true; so terraform thinks there will be a change. The test framework makes sure that nothing changes during an update. Fix for that is to make the validlicense field a computed one and it will be fine after that.

What is validlicense field actually used for? Again, sounds specific to the plugin, so would need to remove it. You can get license details from the data.plugin stanza as it already talks to the marketplace APIs

However... thinking about it more, I'm not sure if this is a generic feature that the provider should have? As it's for a specific plugin. We could generalize it a bit more, and rather than key have a config_endpoint parameter in which the user's can specify the URL to post the JSON payloads to. Would be more generic than the existing one and likely still fit your use-case.

So think it needs to:

  1. Change key to config_endpoint, and accept the entire /rest/blah URL from that
  2. Remove validlisense field entirely
  3. Profit
hgontijo commented 4 years ago

Good thoughts. I actually don't see a need for managing the validLicense. This Rest API I'm using in here is actually not documented so I think it makes sense to keep it explicit by letting the user set the config endpoint.

gavinbunney commented 4 years ago

I'll wait for a new PR then 👯‍♂