Skip to content

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

@Arthur1

Description

@Arthur1

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions