shebang-labs / terraform-provider-postmark

Terraform Provider for postmark
https://postmarkapp.com/
MIT License
13 stars 3 forks source link

Incorrect server name change detected #4

Closed phillipuniverse closed 1 year ago

phillipuniverse commented 1 year ago

My terraform:

variable "postmark_account_token" {
  description = "Account token for Postmark"
}

provider "postmark" {
  account_token = var.postmark_account_token
}

resource "postmark_server" "myserver" {
  name          = "myserver-${var.environment}"
  delivery_type = var.environment == "prod" ? "live" : "Sandbox"
}

Where var.environment can be dev, demo, sandbox, or prod.

This correctly created the myserver-dev Postmark server. But on subsequent terraform plan I always get back a change to update the name of the server even though it is not truly changed:

  Terraform used the selected providers to generate the following execution
  plan. Resource actions are indicated with the following symbols:
    ~ update in-place

  Terraform will perform the following actions:

    # postmark_server.myserver will be updated in-place
    ~ resource "postmark_server" "myserver" {
          id            = "0"
        + name          = "myserver-dev"
          # (3 unchanged attributes hidden)
      }

I had to ignore the changes on the name for it to stop prompting me in the plan:

resource "postmark_server" "myserver" {
  name          = "myserver-${var.environment}"
  delivery_type = var.environment == "prod" ? "live" : "Sandbox"
  lifecycle {
    ignore_changes = [
      name,
    ]
  }
}
MuhammeedAlaa commented 1 year ago

Hello, @phillipuniverse I tried the same configuration as yours and I didn't have this issue at all, You probably changed the var.environment please check this, if you want to create a server for each environment you can use the for_each or copy the resource block and change the name in each one.

phillipuniverse commented 1 year ago

@MuhammeedAlaa just to make sure, I removed the var.environment completely and I still get a dirty terraform plan:

resource "postmark_server" "myserver" {
  name          = "myserver-dev"
  delivery_type = "Sandbox"
}

I am on Terraform v1.3.9 if that makes a difference.

MuhammeedAlaa commented 1 year ago

I check again and I found that this issue happens when you use the wrong token inside account_token. The Account API Token can be found on the API Tokens page in the Account section. Account Owners and Account Admins can see Account API Tokens, while Server Admins and Server Viewers cannot. Check after your first terraform apply that the server is created in your postmark portal.

phillipuniverse commented 1 year ago

Check after your first terraform apply that the server is created in your postmark portal.

Yes it was created, otherwise we would have never seen the dirty terraform plan.

The Account API token is what I was already using, here's the screenshot of the section in the Postmark admin

image
MuhammeedAlaa commented 1 year ago

This is weird because I used the same version of terraform and I didn't face that problem unless I put a wrong account token but it seems like you use the right token from the screen shot so let us see if anyone have the same problem.

MuhammeedAlaa commented 1 year ago

As no one else has the same issue we will close it.