terraform-provider-oci icon indicating copy to clipboard operation
terraform-provider-oci copied to clipboard

oci_objectstorage_object

Open sprat opened this issue 1 year ago • 5 comments

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version and Provider Version

Terraform v1.6.4
on linux_amd64
+ provider registry.terraform.io/oracle/oci v5.20.0

Affected Resource(s)

oci_objectstorage_object

Terraform Configuration Files

data "oci_objectstorage_namespace" "main" {
  compartment_id = oci_identity_compartment.main.id
}

resource "oci_objectstorage_bucket" "os_images" {
  compartment_id = oci_identity_compartment.main.id
  name           = "os-images"
  namespace      = data.oci_objectstorage_namespace.main.namespace
}

resource "oci_objectstorage_object" "talos_image" {
  bucket    = oci_objectstorage_bucket.os_images.name
  namespace = data.oci_objectstorage_namespace.main.namespace
  object    = "talos.qcow2"
  source    = abspath("assets/talos.qcow2")
}

Debug Output

NA

Panic Output

NA

Expected Behavior

The source file should only be uploaded if its content changes

Actual Behavior

The source file is uploaded whenever the file date change

Steps to Reproduce

  1. terraform apply

Important Factoids

I understand that it's easier to detect changes by comparing the file dates. However, when many developers are working on the same code-base, or when we have a CI, each workstation has a source file with a different date and the object is always replaced! Would it be possible to compare the file content instead, for example by comparing the computed md5?

Also, I can't find a workaround. I can't use data.local_file of hashicorp/local because the resource don't support content_base64 (used in a couple of other providers), I can't pass the direct HTTP URL from where I downloaded the image file either (which may have an ETAG or something to determine if there are changes, ...). Maybe someone can suggest an idea how to overcome the problem?

References

NA

sprat avatar Nov 16 '23 20:11 sprat

Thank you for reporting the issue. We have raised an internal ticket to track this. Our service engineers will get back to you.

tf-oci-pub avatar Nov 17 '23 06:11 tf-oci-pub

I've found a way to workaround the issue:

resource "terraform_data" "talos_image_hash" {
  input = filesha512("assets/talos.qcow2")
}

resource "oci_objectstorage_object" "talos_image" {
  bucket    = oci_objectstorage_bucket.os_images.name
  namespace = data.oci_objectstorage_namespace.main.namespace
  object    = "talos.qcow2"
  source    = abspath("assets/talos.qcow2")

  lifecycle {
    ignore_changes = [source]
    replace_triggered_by = [
      terraform_data.talos_image_hash
    ]
  }
}

sprat avatar Nov 19 '23 11:11 sprat

@sprat I can see you were able to found a way to workaround the issue , can we close this issue now or anything else is required?

alokrai-teraform-test avatar Nov 30 '23 08:11 alokrai-teraform-test

My workaround works properly for my use-case, so nothing else is really required. However, I would suggest implementing something that does not trigger a resource replacement when the file data changes, maybe a content_base64 field? But ultimately, it's up to you to decide what to do to improve the situation, I don't know terraform enough to suggest a solution. Anyway, you can probably change the "bug" label to "feature request" since it's not a problem anymore.

sprat avatar Nov 30 '23 09:11 sprat

Thank you for reporting the issue. We have raised an internal ticket to track this. Our service engineers will get back to you.

tf-oci-pub avatar Mar 21 '24 06:03 tf-oci-pub

@sprat Attribute "content" already exists. Along with this attribute we also provide attributes to support content upload. eg. content_type content_md5 content_length content_language content_encoding content_disposition

NOTE: "content" attribute cannot be defined if source or source_uri_details is defined.

public documentation regarding these attributes can be found here :https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/objectstorage_object#source_object_if_match_etag

anuragbisht avatar Jul 03 '24 15:07 anuragbisht

@anuragbisht Yes, the "content" field exists, but only textual content is accepted in it, because Terraform tries to parse it as an utf-8 encoded string. In my case, I want to upload an OS image, so arbitrary binary data, and I didn't find a way to do that using the content field. If you think there's a way to make it work, can you provide a working example please?

sprat avatar Jul 03 '24 17:07 sprat

In fact, that's why I suggested to implement a content_base64 field in the first place.

sprat avatar Jul 03 '24 17:07 sprat

If you want the resource to trigger the upload of the image the right way would be to use a lifecycle block with "ignore_changes" and "replace_triggered_by" since that is already being done, I will close this issue If you are still experiencing any problems, please create a new issue.

anuragbisht avatar Jul 10 '24 13:07 anuragbisht