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

Cannot omit field "bucket" for resource alicloud_oss_bucket

Open zcxsythenew opened this issue 4 months ago • 0 comments

The document of alicloud_oss_bucket says, the field "bucket" is "optional", and if it is "omitted, Terraform will assign a random and unique name."

However, when I really omitted the field and applied the following configuration:

terraform {
  required_providers {
    alicloud = {
        source = "aliyun/alicloud"
        version = "1.231.0"
    }
  }
}

provider "alicloud" {
  region = "cn-hangzhou"
  access_key = "x"
  secret_key = "x"
}

resource "alicloud_oss_bucket" "test_ci" {
  
}

I got the following error:

z@U-HW2FKVC9-1903 empty % tofu apply

OpenTofu used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

OpenTofu will perform the following actions:

  # alicloud_oss_bucket.test_ci will be created
  + resource "alicloud_oss_bucket" "test_ci" {
      + acl                                      = (known after apply)
      + bucket                                   = "tf-oss-bucket-20241021015616642900000001"
      + creation_date                            = (known after apply)
      + extranet_endpoint                        = (known after apply)
      + force_destroy                            = false
      + id                                       = (known after apply)
      + intranet_endpoint                        = (known after apply)
      + lifecycle_rule_allow_same_action_overlap = false
      + location                                 = (known after apply)
      + owner                                    = (known after apply)
      + redundancy_type                          = "LRS"
      + resource_group_id                        = (known after apply)
      + storage_class                            = "Standard"

      + access_monitor (known after apply)
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  OpenTofu will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

╷
│ Error: Provider produced inconsistent final plan
│ 
│ When expanding the plan for alicloud_oss_bucket.test_ci to include new values learned so far during apply, provider
│ "registry.opentofu.org/aliyun/alicloud" produced an invalid new value for .bucket: was cty.StringVal("tf-oss-bucket-20241021015616642900000001"),
│ but now cty.StringVal("tf-oss-bucket-20241021015618490200000001").
│ 
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.
╵

Therefore, either the provider has a bug when the field "bucket" is omitted, or the field "bucket" should be designed to be required.

Possible solution:

  • If we agree that the field "bucket" should continue to be optional, then maybe the value of this field should remain "(known after apply)" during plan, and should not be set until applying.
  • If we agree that the field "bucket" should be required, then the document and the resource schema should be modified.

zcxsythenew avatar Oct 21 '24 02:10 zcxsythenew