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 the service name on the service/role metadata causes duplication of metadata #231

Open
tosuke opened this issue Aug 7, 2024 · 0 comments

Comments

@tosuke
Copy link
Contributor

tosuke commented Aug 7, 2024

Problem

After applying changes on the service attribute in the service/role metadata, the metadata on the previous service remains same.

Steps to reproduce

Here are steps for the service metadata. The steps for the role metadata is almost the same.

  1. Apply the config to init
resource "mackerel_service" "svc1" {
  name = "tf-svc1"
}

resource "mackerel_service" "svc2" {
  name = "tf-svc2"
}

resource "mackerel_service_metadata" "metadata" {
  service   = mackerel_service.svc1.name
  namespace = "tf"
  metadata_json = jsonencode({
    value : 1
  })
}
  1. Apply the updates
--- main.tf
+++ main.tf
@@ -16,7 +16,7 @@
 }
 
 resource "mackerel_service_metadata" "metadata" {
-  service   = mackerel_service.svc1.name
+  service   = mackerel_service.svc2.name
   namespace = "tf"
   metadata_json = jsonencode({
     value : 1

Expected Behaviour

Only tf-svc2/tf is exists.

Actual Behaviour

Both tf-svc1/tf and tf-svc2/tf are exists.

$ curl -H X-Api-Key:$MACKEREL_APIKEY https://api.mackerelio.com/api/v0/services/tf-svc2/metadata/tf
{"value":1}
$ curl -H X-Api-Key:$MACKEREL_APIKEY https://api.mackerelio.com/api/v0/services/tf-svc1/metadata/tf
{"value":1}

Environment

darwin-amd64, version: 0.4.0

Solution

Because the service attribute on service/role metadata is act as a part of the identifier, this change should be treat as replacement.

Schema: map[string]*schema.Schema{
"service": {
Type: schema.TypeString,
Required: true,
},
"namespace": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"metadata_json": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringIsJSON,
},
},

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