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

Duplicate IDs via API #114

Open
craigmoyle opened this issue Oct 13, 2024 · 0 comments
Open

Duplicate IDs via API #114

craigmoyle opened this issue Oct 13, 2024 · 0 comments

Comments

@craigmoyle
Copy link

craigmoyle commented Oct 13, 2024

Tool version
V4.2.1

Describe the bug
We're trying to integrate the naming tool into our sub vending process and we're seeing it issue duplicate IDs for names generated during the process

We're using Terraform and the Mastercard RestApi provider to manage the names as resources. We've tried rate limiting the provider to 1 per second but we're still seeing a handful of duplicates, even when increasing the App Service Plan resources.

To Reproduce
Using the rest provider we ask for resource names for each subscription, resulting in up to 500 names being requested.

Some of the names produced have the same ID making it impossible to manage via Terraform.

Expected behavior
Each name produced by the API should have a unique ID

Installation Method
App Service - Windows

Terraform log with one ID produced for two names
IMG-20241013-WA0004

ASP
image

Here is the provider configuration

provider "restapi" {
  alias                = "namingtool"
  uri                  = "https://app-mgt-prd-aue-01.azurewebsites.net"
  write_returns_object = true
  debug                = true
  rate_limit           = 1
  headers = {
    "APIKey"        = data.external.get_apikey.result.value
    "AdminPassword" = data.external.get_naming_tool_admin_pass.result.value
    "Authorization" = "Bearer ${data.external.get_naming_tool_access_token.result.accessToken}"
    "Content-Type"  = "application/json"
  }
}

Provider information

terraform {
  required_providers {
    restapi = {
      source                = "Mastercard/restapi"
      version               = "1.20.0"
      configuration_aliases = [restapi.namingtool]
    }
  }
}

and the module I'm using to call the naming tool

resource "restapi_object" "resource_name" {
  provider     = restapi.namingtool
  id_attribute = "resourceNameDetails/id"
  path         = "/api/ResourceNamingRequests/RequestName"
  read_path    = "/api/Admin/GetGeneratedName/{id}"
  destroy_path = "/api/Admin/DeleteGeneratedName/{id}"
  data = jsonencode({
    ResourceType        = var.ResourceType
    ResourceProjAppSvc  = var.ResourceProjAppSvc
    ResourceFunction    = var.ResourceFunction
    ResourceEnvironment = var.ResourceEnvironment
    ResourceLocation    = var.ResourceLocation
    ResourceInstance    = var.ResourceInstance
  })
}

and finally how I call the module

module "rg_name_aue_1" {
  source              = "../naming_tool"
  ResourceProjAppSvc  = var.workload
  ResourceEnvironment = var.environment
  ResourceInstance    = "01"
  ResourceLocation    = "aue"
  ResourceType        = "rg"
  ResourceFunction    = ""
  providers = {
    restapi.namingtool = restapi.namingtool
  }
}
@craigmoyle craigmoyle changed the title Duplicate IDs Duplicate IDs via API Oct 14, 2024
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