Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing only memo of a service/role causes recreation of itself #230

Open
Arthur1 opened this issue Aug 5, 2024 · 0 comments
Open

Changing only memo of a service/role causes recreation of itself #230

Arthur1 opened this issue Aug 5, 2024 · 0 comments

Comments

@Arthur1
Copy link
Member

Arthur1 commented Aug 5, 2024

Problem

If you change memo attribute of a service, it is destroyed and recreated.

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with
the following symbols:
-/+ destroy and then create replacement

Terraform will perform the following actions:

  # mackerel_service.foo must be replaced
-/+ resource "mackerel_service" "foo" {
      ~ id   = "foo" -> (known after apply)
      + memo = "aa" # forces replacement
        name = "foo"
    }

Plan: 1 to add, 0 to change, 1 to destroy.

At this time, information associated with the service such as roles and monitor rule options will be lost. This specification is almost always inconvenient.

Role memo has the same problem.

-/+ destroy and then create replacement

Terraform will perform the following actions:

  # mackerel_role.bar must be replaced
-/+ resource "mackerel_role" "bar" {
      ~ id      = "foo:bar" -> (known after apply)
      ~ memo    = "foo:bar is managed by Terraform" -> "foo:bar is managed by Terraform 2" # forces replacement
        name    = "bar"
        # (1 unchanged attribute hidden)
    }

Plan: 1 to add, 0 to change, 1 to destroy.

Solution

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.All(
validation.StringLenBetween(2, 63),
validation.StringMatch(regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9-_]+$`),
"must include only alphabets, numbers, hyphen and underscore, and it can not begin a hyphen or underscore"),
),
},
"memo": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
},

It would seem that erasing ForceNew: true in memo would solve the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant