zitadel / terraform-provider-zitadel

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

Update to `zitadel_smtp_config` fails #180

Open cimnine opened 1 month ago

cimnine commented 1 month ago

Preflight Checklist

Version

provider registry.terraform.io/zitadel/zitadel v1.2.0

ZITADEL Version

cloud

Describe the problem caused by this bug

╷
│ Error: failed to update smtp config: rpc error: code = InvalidArgument desc = invalid UpdateSMTPConfigRequest.Id: value length must be between 1 and 100 runes, inclusive
│ 
│   with zitadel_smtp_config.brevo,
│   on auth.tf line 92, in resource "zitadel_smtp_config" "brevo":
│   92: resource "zitadel_smtp_config" "brevo" {
│ 
╵

To reproduce

I'm not sure.

Screenshots

No response

Expected behavior

As a user of the terraform provider and the zitadel_smtp_config resource, I want to change any property that is within the specs and that isn't documented as read-only without any error.

Relevant Configuration

resource "zitadel_smtp_config" "brevo" {
  sender_address = "${var.mail_sender_userpart}@${data.cloudflare_zone.main.name}"
  sender_name    = var.mail_sender_name
  host           = var.brevo_smtp_host
  tls            = true
  user           = var.brevo_smtp_user
  password       = var.brevo_zitadel_smtp_key
}

Additional Context

To me, it looks like the API changed and that there is now more than one SMTP configuration supported at a time, which it wasn't before. The terraform resource still only knows how to deal with just one SMTP configuration, not many.

njlaw commented 2 weeks ago

Currently, the Terraform provider sets the Id of the resource to be the resource owner (org) of the SMTPConfig config instead of the Id (since this is new, I believe):

https://github.com/zitadel/terraform-provider-zitadel/blob/58870232d880cd4e4aecc61f7558dce5d23174cc/zitadel/smtp_config/funcs.go#L61

I thought I would try to open a pull request to change

-   d.SetId(resp.Details.ResourceOwner)
+   d.SetId(resp.Id)

but, it looks like the version (v2.1.8) of github.com/zitadel/zitadel-go/v2 that's used by the provider doesn't yet have the Id property in AddSMTPConfigResponse. v2.2.4 has it, but when I updated the package in go.mod, a number of acceptance tests failed, so I think I'm out of my league as someone without any Go experience.

I'm still happy to try any open a PR if someone wants to point me in the right direction.

cimnine commented 17 hours ago

I've created an MR but I am facing a roadblock in the acceptance tests. https://github.com/zitadel/terraform-provider-zitadel/pull/185