cloudamqp / terraform-provider-cloudamqp

Terraform Provider for CloudAMQP
https://registry.terraform.io/providers/cloudamqp/cloudamqp
Mozilla Public License 2.0
35 stars 39 forks source link

Can't Import Existing cloudamqp_integration_metric and cloudamqp_integration_log #90

Closed mphammer closed 3 years ago

mphammer commented 3 years ago

Cannot Import Integration Metric and Integration Log Resources

I am not able to import existing resources forcloudamqp_integration_metric and cloudamqp_integration_log.

Here are the commands I ran:

$ terraform import module.parent.module.rabbitmq.cloudamqp_integration_metric.datadog_v2 datadog_v2,000000

$ terraform import module.parent.module.rabbitmq.cloudamqp_integration_log.datadog datadog,000000

Notes

Both commands gave an error like this (this is for cloudamqp_integration_metric):

...

2021/03/11 13:14:44 [TRACE] [walkImport] Exiting eval tree: provider["registry.terraform.io/hashicorp/null"] (close)
2021/03/11 13:14:44 [TRACE] vertex "provider[\"registry.terraform.io/hashicorp/null\"] (close)": visit complete
2021/03/11 13:14:44 [TRACE] [walkImport] Exiting eval tree: module.parent.module.rabbitmq.cloudamqp_integration_metric.datadog_v2 (import id "datadog_v2,000000")
2021/03/11 13:14:44 [TRACE] vertex "module.parent.module.rabbitmq.cloudamqp_integration_metric.datadog_v2 (import id \"datadog_v2,000000\")": expanding dynamic subgraph
module.parent.module.rabbitmq.cloudamqp_integration_metric.datadog_v2: Import prepared!
  Prepared cloudamqp_integration_metric for import

...

2021/03/11 13:14:44 [TRACE] eval: *terraform.EvalRefresh
2021/03/11 13:14:44 [TRACE] GRPCProvider: ReadResource
module.parent.module.rabbitmq.cloudamqp_integration_metric.datadog_v2: Refreshing state... [id=datadog_v2,000000]
2021/03/11 13:14:44 [ERROR] eval: *terraform.EvalRefresh, err: Missing instance identifier: {instance_id}
2021/03/11 13:14:44 [ERROR] eval: *terraform.EvalSequence, err: Missing instance identifier: {instance_id}

...

2021/03/11 13:14:44 [TRACE] vertex "provider[\"registry.terraform.io/hashicorp/google\"] (close)": visit complete
2021/03/11 13:14:44 [TRACE] dag/walk: upstream of "root" errored, so skipping

Error: Missing instance identifier: {instance_id}

2021-03-11T13:14:44.615-0500 [WARN]  plugin.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = transport is closing"

...

However, I Can Import an Instance Resource

I was able to import an existing cloudamqp_instance instance with the following command:

$ terraform import module.parent.module.rabbitmq.cloudamqp_instance.instance 000000

Configuration

Provider Configuration:

provider "cloudamqp" {
  apikey = var.cloudamqp_api_key
}

Current Resource Configurations:

resource "cloudamqp_integration_metric" "datadog_v2" {
  instance_id = cloudamqp_instance.instance.id
  name        = "datadog_v2"
  api_key     = var.datadog_api_key
  region      = var.datadog_region
  tags        = join(",", ["cluster=${var.cluster_name}", "region=${var.cloudamqp_provider_region}"])
}

resource "cloudamqp_integration_log" "datadog" {
  instance_id = cloudamqp_instance.instance.id
  name = "datadog"
  region = var.datadog_region
  api_key = var.datadog_api_key
  tags = join(",", ["cluster=${var.cluster_name}", "region=${var.cloudamqp_provider_region}"])
}

Thoughts

Could this be a parsing issue for the <name>,<instance_id> value that's passed into the command?

From the documentation: $ terraform import cloudamqp_integration_metric.<resource_name> <name>,<instance_id>

Related Issue: #40

tbroden84 commented 3 years ago

@mphammer correct, there is a parsing error for , for metrics. Seems to have been missed when logs was update. Also found a possible issue in one of our APIs that affect both logs and metrics. Will investigate further.

tbroden84 commented 3 years ago

Not sure what I was thinking before. In order to import the correct integration you would need the resource identifier for the integration and not the name. How to get the correct resource identifier, can be found at https://docs.cloudamqp.com/cloudamqp_api.html#integrations.

Then the import call should be $ terraform import cloudamqp_intergration_log.<resource_name> <resource_id>,<instance_id>

$ terraform import cloudamqp_integration_metric.<resource_name> <resource_id>,<instance_id>

Have some more updates, before making a new release.

mphammer commented 3 years ago

Great! Thank you for looking into this.

dentarg commented 3 years ago

@mphammer still having issues or could this be closed?

mphammer commented 3 years ago

This can be closed. We are no longer going with the approach that needed this.