oracle / terraform-provider-oci

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

oci_objectstorage_preauthrequest incorrectly deletes & replaces the resource every time #2092

Open dch opened 7 months ago

dch commented 7 months ago

Community Note

Terraform Version and Provider Version

Terraform v1.7.5-dev on freebsd_amd64
+ provider registry.terraform.io/oracle/oci v5.36.0

Affected Resource(s)

Terraform Configuration Files

resource "oci_objectstorage_preauthrequest" "pkg" {
    access_type = "AnyObjectRead"
    bucket_listing_action = "ListObjects"
    bucket = "pkg"
    name = "pkg_repo_readonly"
    namespace = var.tenancy_namespace
    time_expires = "2038-01-01T12:00:00Z"
}

Debug Output

$ terraform apply
...
  # oci_objectstorage_preauthrequest.pkg must be replaced
-/+ resource "oci_objectstorage_preauthrequest" "pkg" {
      ~ access_uri            = "/p/Iny9Mn_WoSmYcZvSMRVhU-ZMljp4TdYkxLHAbcqNSAQZo4YCenX60Cl_orgioox_/n/axvxsnomswgi/b/pkg/o/" -> (known after apply)
      + bucket_listing_action = "ListObjects" # forces replacement
      ~ full_path             = "https://axvxsnomswgi.objectstorage.eu-amsterdam-1.oci.customer-oci.com/p/.../n/axvxsnomswgi/b/pkg/o/" -> (known after apply)
      ~ id                    = "n/axvxsnomswgi/b/pkg/p/..." -> (known after apply)
        name                  = "pkg_repo_readonly"
      + object                = (known after apply)
      + object_name           = (known after apply)
      ~ par_id                = "..." -> (known after apply)
      ~ time_created          = "2024-04-11 21:25:50.045 +0000 UTC" -> (known after apply)
        # (4 unchanged attributes hidden)
    }

Expected Behavior

a previously created PAR should not be deleted.

Actual Behavior

The PARs are deleted, and we need to re-distribute these on every single terraform run.

Steps to Reproduce

References

This has been the case for a couple of years at least: https://github.com/oracle/terraform-provider-oci/issues/1570

tf-oci-pub commented 7 months ago

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

jacobcsmith commented 4 months ago

To work around this bug we used the ignore_changes lifecycle attribute to instruct terraform to ignore changes to bucket_listing_action. Once added, terraform no longer attempts to recreate the oci_objectstorage_preauthrequest resource.

dch commented 4 months ago

@jacobcsmith interesting. can you give a more complete example of this please? thanks!

jacobcsmith commented 4 months ago

Using your example it would be like this

resource "oci_objectstorage_preauthrequest" "pkg" {
    access_type = "AnyObjectRead"
    bucket_listing_action = "ListObjects"
    bucket = "pkg"
    name = "pkg_repo_readonly"
    namespace = var.tenancy_namespace
    time_expires = "2038-01-01T12:00:00Z"

    lifecycle {
      ignore_changes = [bucket_listing_action]
    }
}