terraform-provider-opsgenie icon indicating copy to clipboard operation
terraform-provider-opsgenie copied to clipboard

[BUG] opsgenie_api_integration api_key provide a null value

Open nissessenap opened this issue 3 years ago • 3 comments

Hi, first of all thanks for creating this provider. It really makes me feel much safer then clicking around in the ui. It seems to me opsgenie_api_integration.example.api_key provides a null value.

Terraform Version

Terraform v1.1.7

Affected Resource(s)

Please list the resources as a list, for example:

  • prometheus_integration_api_key

Terraform Configuration Files

resource "opsgenie_team" "devops" {
  name        = "DevOps"
  description = ""
}

resource "opsgenie_api_integration" "prometheus" {
  name = "Prometheus"
  type = "Prometheus"

  enabled       = true
  owner_team_id = opsgenie_team.devops.id
}

resource "azurerm_key_vault_secret" "prometheus_integration_api_key" {
  name         = "opsgenie-api-key"
  value        = opsgenie_api_integration.prometheus.api_key
  key_vault_id = data.azurerm_key_vault.monitor.id
}

Debug Output

│ Error: Missing required argument │ │ with azurerm_key_vault_secret.prometheus_integration_api_key, │ on main.tf line 164, in resource "azurerm_key_vault_secret" "prometheus_integration_api_key": │ 164: value = opsgenie_api_integration.prometheus.api_key │ │ The argument "value" is required, but no definition was found.

Expected Behavior

The output of opsgenie_api_integration should provide me with the attribute api_key as described in: https://registry.terraform.io/providers/opsgenie/opsgenie/latest/docs/resources/api_integration#attributes-reference

I should then be able to use this value, in this case I want to send it to azure_key_vault. The error that shows is thanks to the value is null.

If I manually curl the integrations API i don't get the API key in the response body and that is why I think this doesn't work. At the same time you provide the API Key in the UI so somewhere you have access to it :)

curl -X GET 'https://api.opsgenie.com/v2/integrations/my-integrations-id' --header "Authorization: GenieKey $OPSGENIE_API_KEY"

Actual Behavior

The return value of calling opsgenie_api_integration.prometheus.api_key is null.

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform plan

nissessenap avatar May 03 '22 07:05 nissessenap

In create https://github.com/opsgenie/terraform-provider-opsgenie/blob/3c33b06c2d40c89967987707f0bdcfdaf2345bdf/opsgenie/resource_opsgenie_api_integration.go#L213 there is d.Set("api_key", result.ApiKey)

But in the get function this isn't defined and that is why this don't work. https://github.com/opsgenie/terraform-provider-opsgenie/blob/3c33b06c2d40c89967987707f0bdcfdaf2345bdf/opsgenie/resource_opsgenie_api_integration.go#L228

Reading through and testing https://docs.opsgenie.com/docs/integration-api#get-integration the ApiKey isn't provided when using GET. As pointed out in the issue i can obviously see the API KEY in the UI, so you have to have a API where this is possible. I guess the question is if this API is public or not.

I'm happy to provide a PR but I would need some pointer where to find this data.

I would really love to get this bug fixed as quickly as possible. It would be amazing to not have to manually handle API Keys for my integrations and instead of terraform to do it for me.

nissessenap avatar May 03 '22 07:05 nissessenap

Also see https://github.com/opsgenie/terraform-provider-opsgenie/issues/269

davidkarlsen avatar May 03 '22 18:05 davidkarlsen

Thanks @davidkarlsen , apparently i didn't make a good enough search when creating this issue.

nissessenap avatar May 03 '22 18:05 nissessenap

I opened a support ticket and Atlassian created an issue to track this bug, you can vote here to increase the visibility: https://jira.atlassian.com/browse/OPSGENIE-1345

BapRx avatar Mar 13 '23 09:03 BapRx

I will close this issue due to the answer in #269 In short the API will never support getting the API key after creation.

nissessenap avatar Jun 07 '23 04:06 nissessenap