How to find latest backup files in OCI to create Volumes

Hi Guys,

I really need some guidance here…
I have created the DC environment for an application. Now I have a DR region which is getting everyday volume backups copied from the DC region automatically. I am retaining the last 5 backups for every boot and block Volume.

Now I am working on to create some tf scripts for DR region which when run, should:
1- First create all the boot and block volumes using the latest respective backup files.
2- Use them in order to create the new VMs.

The part where I need guidance is “1” above. I can’t seem to find a way to refer to the right backup files using Data Source: oci_core_boot_volume_backup and oci_core_boot_volume_backups.
I think the solution may lie in using data source or locals and some regex filtering, but my knowledge is limited on those areas.

The cloud is OCI however I think the terraform logic in broader sense should be same as any other cloud.

Please share your thoughts.

To be precise

The name of Volume or Tags are not copied along with backup files in the destination region when using cross region backup.

And there is no attribute I see that can be used to filter the right backup file in the code below…


data "oci_core_boot_volume_backups" "test_boot_volume_backups" {

    #Required

    compartment_id = var.compartment_id

    #Optional

    boot_volume_id = oci_core_boot_volume.test_boot_volume.id

    display_name = var.boot_volume_backup_display_name

    source_boot_volume_backup_id = oci_core_boot_volume_backup.test_boot_volume_backup.id

    state = var.boot_volume_backup_state

}

When tried using boot_volume_id

terraform plan shows that that source details are found but the apply fails… both snippets below…

terraform plan


+ source_details {

          + id   = "ocid1.bootvolume.oc1.uk-london-1.abwgiljr2y44ssfsokein7v7kgku3x6n7mpvugbwxxxxxxxxxxxxxxxxxxxx"

          + type = "bootVolumeBackup"

terraform apply


oci_core_boot_volume.test_boot_volume: Still creating... [2m0s elapsed]

Error: Service error:NotAuthorizedOrNotFound. Authorization failed or requested resource not found.. http status code: 404. Opc request id: 77c95b4cc7494a22b284558c37b9f277/2F538776FBBA341FBEE69BA2710B9273/09A381E6BEF64107234CB6296D07D6

  on zvolume.tf line 2, in resource "oci_core_boot_volume" "test_boot_volume":

   2: resource "oci_core_boot_volume" "test_boot_volume" {

PS: The source region is london and the destination region is frankfurt

Sorry for the delay. First quick question, you have the providers right with the different regions?

Yes I would use boot_volume_backups. Regex wise I have not done this with backups, I have done some with Images. I do think regex is right because when it transfers the backup over, it does have a standard naming convention if i remember right.

For example this pulls the latest Oracle Linux image. Maybe that regex will help?
data “oci_core_images” “ol7” {

#Required

compartment_id = var.tenancy_ocid

#Optional

operating_system         = "Oracle Linux"

operating_system_version = "7.8"

//shape                    = "VM.Standard2.16"

# Exclude GPU Specific Images

filter {

    name   = "display_name"

    values = ["Oracle-Linux-[0-9].[0-9]{1,2}-[0-9]{4}.[0-9]{2}.[0-9]{2}"]

    regex  = true

}

}

Filtering the backup files using defined tags did the trick. I wish Oracle documentation were better!

1 Like

I agree. I once filed a bug on better documentation but I don’t know how to get it better. Except document my module better

1 Like