You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've created two instances using "count =2" and I'm looking to apply a backup policy to both the boot volumes. Solution I came up with was to get a attached boot volume data source and filter for the instance OCID. I manage to get it working when I look for only one instance but when I look for two. I get the following error below. Can anyone provide some assistance?
Example below:
Error
oci_core_volume_backup_policy_assignment.policy[0]: Resource data.oci_core_boot_volume_attachments.boot_volume' not found for variable 'data.oci_core_boot_volume_attachments.boot_volume.boot_volume_attachments'
oci_core_volume_backup_policy_assignment.policy[1]: Resource 'data.oci_core_boot_volume_attachments.boot_volume' not found for variable 'data.oci_core_boot_volume_attachments.boot_volume.boot_volume_attachments'
However, this kind of access is not supported via the lookup operation as noted in hashicorp/terraform#8047 (will work on flat lists only). We can try to combine element and lookup (as done in hashicorp/terraform#13905 (comment)) -- but it is not recommended because it might cause unnecessary force new behavior (because TF treats element syntax for cases where results are not known beforehand and might treat it as a diff).
We are looking to add support for a "singular" datasource for boot_volume_attachments that returns a single boot_volume_attachment (rather than a list) which will help in using the count syntax easily. Till that time, you'd need to repeat the resource.
Separately, terraform v0.12.0 promises better syntax and may solve this, but that is yet to be tested by us.
Terraform Version
Terraform v0.11.7
OCI Provider Version
terraform-provider-oci_v2.1.17
Description:
Hi All,
I've created two instances using "count =2" and I'm looking to apply a backup policy to both the boot volumes. Solution I came up with was to get a attached boot volume data source and filter for the instance OCID. I manage to get it working when I look for only one instance but when I look for two. I get the following error below. Can anyone provide some assistance?
Example below:
Error
oci_core_volume_backup_policy_assignment.policy[0]: Resource data.oci_core_boot_volume_attachments.boot_volume' not found for variable 'data.oci_core_boot_volume_attachments.boot_volume.boot_volume_attachments'
oci_core_volume_backup_policy_assignment.policy[1]: Resource 'data.oci_core_boot_volume_attachments.boot_volume' not found for variable 'data.oci_core_boot_volume_attachments.boot_volume.boot_volume_attachments'
Terraform Plan
resource "oci_core_instance" "instance" {
count = 2
availability_domain = "${lookup(data.oci_identity_availability_domains.ad.availability_domains[0],"name")}"
compartment_id = "${var.compartment_ocid}"
shape = "VM.Standard2.2"
display_name = "instance${count.index}"
hostname_label = "instance${count.index}"
metadata = {
ssh_authorized_keys = "${file(var.ssh_public_key)}"
}
source_details {
source_type = "image"
source_id = "${lookup(data.oci_core_images.image.images[0],"id")}"
boot_volume_size_in_gbs = "50"
}
create_vnic_details {
assign_public_ip = "False"
private_ip = ""
subnet_id = "${lookup(data.oci_core_subnets.subnet.subnets[0],"id")}"
}
}
resource "oci_core_volume_backup_policy_assignment" "policy" {
count = 2
asset_id = "${lookup(data.oci_core_boot_volume_attachments.boot_volume.boot_volume_attachments[count.index],"boot_volume_id")}"
policy_id = "${lookup(data.oci_core_volume_backup_policies.gold_policy.volume_backup_policies[0],"id")}"
}
data "oci_core_boot_volume_attachments" "boot_volume" {
count = 2
availability_domain = "${lookup(data.oci_identity_availability_domains.ad.availability_domains[0],"name")}"
compartment_id = "${var.compartment_ocid}"
instance_id = "${oci_core_instance.instance.*.id[count.index]}"
}
The text was updated successfully, but these errors were encountered: