oracle / terraform-provider-oci

Terraform Oracle Cloud Infrastructure provider
https://www.terraform.io/docs/providers/oci/
Mozilla Public License 2.0
751 stars 672 forks source link

400-InvalidParameter, Invalid sourceDetails.imageId: null (Image ID must not be null) when use instance_source_image_filter_details #2102

Open ngochieu642 opened 4 months ago

ngochieu642 commented 4 months ago

Terraform Version and Provider Version

$ terraform --version
Terraform v1.5.7
on linux_amd64
+ provider registry.terraform.io/oracle/oci v5.38.0

Affected Resource(s)

"oci_core_instance"

Terraform Configuration Files


resource "oci_core_instance" "my_vm" {
  availability_domain = local.ad
  compartment_id      = local.compartment_id
  shape               = var.vm_shape["shape"]

  shape_config {
    ocpus         = var.vm_shape["ocpus"]
    memory_in_gbs = var.vm_shape["memory"]
  }

  source_details {
    source_type             = "image"
    boot_volume_size_in_gbs = var.vm_shape["boot_volume_size"]
    instance_source_image_filter_details {
      compartment_id = var.tenancy_ocid
      operating_system = "Oracle Linux"
      operating_system_version = "7.9"
    }
  }

  create_vnic_details {
    assign_public_ip = false
    subnet_id        = oci_core_subnet.my_private_subnet.id
  }

  metadata = {
    ssh_authorized_keys = join("\n", local.authorized_keys)
  }
}
# Copy-paste your Terraform configurations here - for large Terraform configs,
# please use a service like Dropbox and share a link to the ZIP file. 
# Please remove any sensitive information from configuration files before sharing them. 

Debug Output

Panic Output

Expected Behavior

Actual Behavior

Steps to Reproduce

  1. terraform apply

Important Factoids

References

qm3ster commented 1 month ago

I'm not great at Go, but it seems that while the instance_source_image_filter_details get validated and serialized and sent to the server, the server does not care about them. InstanceSourceViaImageDetails (in InstanceSourceDetails) (in LaunchInstanceDetails::sourceDetails) doesn't mention them at all for instance.

And I don't see the provider in this repository doing anything to search the image itself.

So, it seems you'd have to do an

oci compute image list --all \
    --shape "VM.Standard.A1.Flex" \
    --operating-system "Canonical Ubuntu" \
    --operating-system-version "22.04" \
    | jq -r '.data|sort_by(."time-created")|.[-1].id'

of your own and provide that as source_id (I have my compartment_id set in my ~/.oci/oci_cli_rc)