zitadel / terraform-provider-zitadel

Official Terraform provider for ZITADEL
https://zitadel.com
Apache License 2.0
21 stars 13 forks source link

Zitadel provider fails to upload images using resource "zitadel_label_policy" #152

Open akinsella-socrate opened 5 months ago

akinsella-socrate commented 5 months ago

Preflight Checklist

Version

v1.0.5

ZITADEL Version

Any

Describe the problem caused by this bug

When configuring Zitadel provider with the jwt_profile_file parameter, file upload fails for images on zitadel_label_policy resource.

Configuration example of the Zitadel provider:

provider "zitadel" {
  domain           = "dev.example.org"
  port             = "443"
  jwt_profile_file = "./terraform-sa.json"
}

Resource example:

resource "zitadel_label_policy" "label_policy" {
  org_id                 = zitadel_org.org.id

  hide_login_name_suffix = true

  primary_color          = "#578CAC"
  background_color       = "#D2D7DF"
  warn_color             = "#CF2C17"
  font_color             = "#313946"

  primary_color_dark     = "#9FC8E0"
  background_color_dark  = "#434E60"
  warn_color_dark        = "#F2988C"
  font_color_dark        = "#E5EAF0"

  disable_watermark      = true
  set_active             = true

  logo_hash              = filemd5("resources/images/logo-light-square.jpeg")
  logo_path              = "resources/images/logo-light-square.jpeg"

  logo_dark_hash         = filemd5("resources/images/logo-dark-square.jpeg")
  logo_dark_path         = "resources/images/logo-dark-square.jpeg"

  icon_hash              = filemd5("resources/images/logo-light-square.jpeg")
  icon_path              = "resources/images/logo-light-square.jpeg"

  icon_dark_hash         = filemd5("resources/images/logo-dark-square.jpeg")
  icon_dark_path         = "resources/images/logo-dark-square.jpeg"

  # font_hash              = filemd5("resources/fonts/noto-sans.ttf")
  # font_path              = "resources/fonts/noto-sans.ttf"
}

Received error:

 Error: failed to upload logo: [{0 either 'jwt_profile_file' or 'jwt_profile_json' is required  []}]
│ 
│   with module.organizations.zitadel_label_policy.ares_label_policy,
│   on modules/organizations/ares.tf line 147, in resource "zitadel_label_policy" "ares_label_policy":
│  147: resource "zitadel_label_policy" "ares_label_policy" {
│ 

As a result configuration of images (Including their file upload) fails, not the configuration of colors and options.

To reproduce

Execute a terraform apply step with configuration described above

Screenshots

No response

Expected behavior

Should succeed with the file upload and creation/update of the related resource

Relevant Configuration

No response

Additional Context

There is, if not mistaken one line of code to change in file client.go to get it work. The fix has been tested successfully (Replacing official plugin with a compiled one based on the most recent main branch commit).

Following condition :

         else if jwtProfileFile != "" {
        options = append(options, zitadel.WithJWTProfileTokenSource(middleware.JWTProfileFromPath(jwtProfileFile)))
        keyPath = token
    }

should be changed to :

         else if jwtProfileFile != "" {
        options = append(options, zitadel.WithJWTProfileTokenSource(middleware.JWTProfileFromPath(jwtProfileFile)))
        keyPath = jwtProfileFile
    }

With keyPath set to jwtProfileFile, file upload of the image is successful.

akinsella-socrate commented 5 months ago

I opened a pull request with the fix proposal for review: https://github.com/zitadel/terraform-provider-zitadel/pull/153

akinsella-socrate commented 5 months ago

There might be another issue related to zitadel_label_policy as it is not possible to upload font successfully as well, but this one might be related to another issue as it is reproducible for in UI as well (It is not possible to upload font in Brand configuration page at least in version 1.43.4 and 1.43.5).

akinsella-socrate commented 5 months ago

There might be another issue related to zitadel_label_policy as it is not possible to upload font successfully as well, but this one might be related to another issue as it is reproducible for in UI as well (It is not possible to upload font in Brand configuration page at least in version 1.43.4 and 1.43.5).

This one is related to max size that is accepted. Many font have a size bigger than 512kb which is finally unrelated with the rest of the issue.

davidkalosi commented 2 months ago

when can we expect this to be released? the PR is already merged.

steled commented 2 months ago

Hi,

we are running into the same problem. Thx to @akinsella-socrate for the fix but as mentioned in the PR it is closed because the merge of main into your branch was missing.

Maybe you can open a new PR with updated branch, that would be totally helpful

vs-gtadeu commented 1 month ago

We are also affected by this issue and want to know when the fix will be released.