sbecker59 / terraform-provider-statuspage

Terraform Statuspage provider
https://registry.terraform.io/providers/sbecker59/statuspage/
Mozilla Public License 2.0
8 stars 5 forks source link

Support for Importing Resources #171

Closed jbyardi closed 8 months ago

jbyardi commented 9 months ago

Hi there,

Wondering if you could implement support for importing Statuspage resources. I've got a few components already active and it would be great to not have to recreate them.

Kind Regards, Jonathan B.

sbecker59 commented 8 months ago

Hi @jbyardi

Good news, there is no need to wait for the import to be implemented, it already exists. 🎉 It's only missing from the documentation 😕 Here are examples for import:


terraform import statuspage_component_group.my_group page-id/component-group-id
terraform import statuspage_component.my_component page-id/component-id

terraform {
  required_providers {
    statuspage = {
      source  = "sbecker59/statuspage"
      version = "1.0.0"
    }
  }
}

provider "statuspage" {}

resource "statuspage_component" "my_component" {
  page_id     = "page-id"
  name        = "My Website"
  description = "Status of my Website"
  status      = "operational"

  lifecycle {
      ignore_changes = [
          status
      ]
  }
}

resource "statuspage_component_group" "my_group" {
  page_id     = "page-id"
  name        = "Terraform"
  description = "Created by terraform"
  components  = [ statuspage_component.my_component.id ]
}

import {
    to = statuspage_component_group.my_group
    id = "page-id/component-group-id"
}

import {
    to = statuspage_component.my_component
    id = "page-id/component-id"
}

Don't hesitate if you need more information. Regards.

Sébastien B.

jbyardi commented 8 months ago

Thanks Sébastien!

jbyardi commented 8 months ago

Tried running an import and got an authorization error. Perhaps the authorisation headers required have changed since you created this?

import_error

sbecker59 commented 8 months ago

Have you set the api key? Several possible solutions

provider "statuspage" {
    api_key = "...."
}
export STATUSPAGE_API_KEY=...
export SP_API_KEY=...
jbyardi commented 8 months ago

Okay retrying the import another day worked. Might have been a momentary issue with API calls. Tested a bad api key and got a proper 401 error.