opsgenie / terraform-provider-opsgenie

Terraform OpsGenie provider
https://registry.terraform.io/providers/opsgenie/opsgenie/latest/docs
Mozilla Public License 2.0
104 stars 137 forks source link

API Integration cannot be made team integration after initialized as global #64

Open miroag opened 4 years ago

miroag commented 4 years ago

Hi there,

Terraform Version

Terraform v0.12.9
+ provider.opsgenie v0.2.7

Affected Resource(s)

If this issue appears to affect multiple resources, it may be an issue with Terraform's core, so please ### Terraform Configuration Files

# code to illustrate the issue with Integration not updating the 
# ownerId once It's been made global

provider "opsgenie" {
  version = "~> 0.2"
}

resource "opsgenie_team" "team" {
  name        = "test team"
  description = "tets team"
}

resource "opsgenie_api_integration" "api" {
  name          = "test team API Integration"
  type          = "API"

  owner_team_id = opsgenie_team.team.id
  enabled       = true
  responders {
    type = "team"
    id   = opsgenie_team.team.id
  }
}

Debug Output

Panic Output

Steps to Reproduce

  1. Use the provided script with commented out team owner
    #owner_team_id = opsgenie_team.team.id 
  2. terraform apply
  3. Check that integration is global
  4. Uncomment the line above
  5. terraform apply

Expected Behavior

Once the owner_team_id is set - it will have made the it team Integration

Actual Behavior

In the given conditions, it will not fail, but have no impact, Integration will remain global Creating integration with owner set, will create it properly a team integration

Important Factoids

References

ffahri commented 4 years ago

Currently we cannot remove owner team in Team API. I have created internal ticket and will look further for this issue

igaskin commented 4 years ago

This problem is also present when importing existing opsgenie_api_integration's, since the ownerTeam field can be set as such:

Owner team of the integration, consisting id and/or name of the owner team. https://docs.opsgenie.com/docs/integration-api#section-create-api-based-integration

Since the opsgenie_api_integration resource only accepts owner_team_id there is no way to import an existing opsgenie_api_integration that has the form:

{
    "ownerTeam": {
        "name":"operations_team"
    }
}

or

{
    "ownerTeam": {
        "id":"8418d193-2alp-4490-b331-8c02cdd196b7",
        "name":"operations_team"
    }
}

Not sure if I should create a separate issue for this, since its the same underlying problem.

ffahri commented 4 years ago

Not the same problem we can fix this via allowing name option or give teamid when importing etc @igaskin

igaskin commented 4 years ago

Not the same problem we can fix this via allowing name option or give teamid when importing etc @igaskin

You are correct. Adding team-name does sound like the correct solution for what I was describing. The propagated error is what makes it seem like the same thing.

Error: Error occurred with Status code: 403, Message: You can not assign integration to another team, Took: 0.004000, RequestId: dd56a0dd-1f9c-422c-8ba4-c145ec60a13b

I'll open a separate issue to get the "team name" added to the opsgenie_api_integration resource.