IBM-Cloud / terraform-provider-ibm

https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs
Mozilla Public License 2.0
341 stars 670 forks source link

data "ibm_resource_key" is not able to retrieve key for instance #2650

Open dprosper opened 3 years ago

dprosper commented 3 years ago

Community Note

Terraform CLI and Terraform IBM Provider Version

$ terraform -v
Terraform v0.15.1
on windows_amd64
+ provider registry.terraform.io/hashicorp/external v2.1.0
+ provider registry.terraform.io/hashicorp/helm v2.1.2
+ provider registry.terraform.io/hashicorp/kubernetes v2.2.0
+ provider registry.terraform.io/hashicorp/null v3.1.0
+ provider registry.terraform.io/hashicorp/time v0.7.1
+ provider registry.terraform.io/ibm-cloud/ibm v1.25.0
+ provider registry.terraform.io/sysdiglabs/sysdig v0.5.14

Your version of Terraform is out of date! The latest version
is 0.15.3. You can update by downloading from https://www.terraform.io/downloads.html

Affected Resource(s)

Terraform Configuration Files

Please include all Terraform configurations required to reproduce the bug. Bug reports without a functional reproduction may be closed without investigation.

# Copy-paste your Terraform configurations here - for large Terraform configs,
# please share a link to the ZIP file.
data "ibm_resource_instance" "activity_tracker" {
  name              = var.activity_tracker_instance_name
  location          = var.region
  resource_group_id = data.ibm_resource_group.group.id
  service           = "logdnaat"
}

data "ibm_resource_key" "activity_tracker" {
  resource_instance_id  = data.ibm_resource_instance.activity_tracker.id
}

Debug Output

 Error: Missing required argument
β”‚
β”‚   on instance_config.tf line 288, in data "ibm_resource_key" "activity_tracker":
β”‚  288: data "ibm_resource_key" "activity_tracker" {
β”‚
β”‚ The argument "name" is required, but no definition was found.

Expected Behavior

The issue is an existing Activity Tracker instance that already has a resource key created, in Terraform I am trying to obtain the name of the resource key, the ibm_resource_key requires you to know the name of the resource_key. In the CLI I can obtain the name of the resource key by running the following command:

ibmcloud resource service-keys --instance-name "<activity_tracker_instance_name>"

the data source for ibm_resource_key does provide the ability to specify the name of the instance, i.e. similar to the CLI by including a resource_instance_id, however the name of the resource key is still required in Terraform, it is not required in the CLI.

I am filling as a bug, as I don't see the use of this data source if you have to specify the name of the resource_key, I believe the behavior should be that it allows you to obtain the name of the resource key(s).

Actual Behavior

The provider does not allow me to capture the name of the resource key when I don't know what it is, I need to have the same functionality in Terraform as I have in the CLI, i.e. determine the name of the key when I don't know what it is.

Steps to Reproduce

  1. Create a template with the above snippet and
  2. terraform apply
kavya498 commented 3 years ago

@dprosper , The current datasource is equivalent to ibmcloud resource service-key (NAME | ID) [-g RESOURCE_GROUP] [--id] We would need a new datasource ibm_resource_keys for this ibmcloud resource service-keys --instance-name "<activity_tracker_instance_name>"

Thanks.

dprosper commented 3 years ago

@kavya498 thank you that makes sense.