oracle / terraform-provider-oci

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

oci_database_cloud_autonomous_vm_cluster fails to update due to unused/invalid property #1817

Open jvantillo opened 1 year ago

jvantillo commented 1 year ago

Community Note

Terraform Version and Provider Version

Terraform v1.4.2
on linux_amd64
+ provider registry.terraform.io/hashicorp/azurerm v3.49.0
+ provider registry.terraform.io/oracle/oci v4.113.0

Affected Resource(s)

oci_database_cloud_autonomous_vm_cluster

Terraform Configuration Files

resource "oci_database_cloud_autonomous_vm_cluster" "cluster" {
  cloud_exadata_infrastructure_id = var.infra_id
  compartment_id                  = var.compartment_id
  # (snip)

  # Maintenance window
  maintenance_window_details {
    preference                       = "CUSTOM_PREFERENCE"
    is_custom_action_timeout_enabled = false
    custom_action_timeout_in_mins    = 0
    weeks_of_month                   = var.maintenance_schedule.week_of_month
    hours_of_day                     = [var.maintenance_schedule.start_hour_utc]

    dynamic "months" {
      for_each = local.maintenance_months
      content {
        name = months.value
      }
    }

    dynamic "days_of_week" {
      for_each = var.maintenance_schedule.day_of_week
      content {
        name = days_of_week.value
      }
    }
  }

Expected Behavior

After creation of the VM cluster, the updatable properties can be modified. As an example, the display name.

Actual Behavior

Upon making any change and running apply, the following occurs:

Error: 400-InvalidParameter, MaintenanceWindow leadTimeInWeeks  : is only supported for Exadata DbSystems.
β”‚ Suggestion: Please update the parameter(s) in the Terraform config as per error message MaintenanceWindow leadTimeInWeeks  : is only supported for Exadata DbSystems.
β”‚ Documentation: https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/database_cloud_autonomous_vm_cluster 
β”‚ API Reference: https://docs.oracle.com/iaas/api/#/en/database/20160918/CloudAutonomousVmCluster/UpdateCloudAutonomousVmCluster 
β”‚ Request Target: PUT https://database.eu-amsterdam-1.oraclecloud.com/snip/cloudAutonomousVmClusters/ocid1.cloudautonomousvmcluster.oc1.eu-amsterdam-1.snipsnip
β”‚ Provider version: 4.113.0, released on 2023-03-22. 
β”‚ Service: Database Cloud Autonomous Vm Cluster 
β”‚ Operation Name: UpdateCloudAutonomousVmCluster 
β”‚ OPC request ID: snip

Steps to Reproduce

Important Factoids

It appears related to how the provider deals with 'lead time in weeks'. Note that in the code we never specify this property and Terraform will create the cluster accordingly. Afterwards, I verified through oci db cloud-autonomous-vm-cluster get --cloud-autonomous-vm-cluster-id that when you request the cluster from the API, the corresponding 'lead time' property is set to null:

 "maintenance-window": {
      "custom-action-timeout-in-mins": null,
      "days-of-week": [
        {
          "name": "SUNDAY"
        }
      ],
      "hours-of-day": [
        4
      ],
      "is-custom-action-timeout-enabled": null,
      "is-monthly-patching-enabled": null,
      "lead-time-in-weeks": null,
      "months": [
        {
          "name": "FEBRUARY"
        },
        {
          "name": "MAY"
        },
        {
          "name": "AUGUST"
        },
        {
          "name": "NOVEMBER"
        }
      ],
      "patching-mode": null,
      "preference": "CUSTOM_PREFERENCE",
      "weeks-of-month": [
        1
      ]
    },

However, when you issue a terraform state show it will show for that same resource the value '0' for the lead time:

maintenance_window_details {
        custom_action_timeout_in_mins    = 0
        hours_of_day                     = [
            4,
        ]
        is_custom_action_timeout_enabled = false
        is_monthly_patching_enabled      = false
        lead_time_in_weeks               = 0
        preference                       = "CUSTOM_PREFERENCE"
        weeks_of_month                   = [
            1,
        ]

        days_of_week {
            name = "SUNDAY"
        }

        months {
            name = "FEBRUARY"
        }
        months {
            name = "MAY"
        }
        months {
            name = "AUGUST"
        }
        months {
            name = "NOVEMBER"
        }
    }

With TF_LOG=DEBUG OCI_GO_SDK_DEBUG=v I was able to verify that when Terraform issues the PUT request to update the resource, it has the following in the body of the request:

"maintenanceWindowDetails":{"customActionTimeoutInMins":0,"daysOfWeek":[{"name":"SUNDAY"}],"hoursOfDay":[4],"isCustomActionTimeoutEnabled":false,"isMonthlyPatchingEnabled":false,"leadTimeInWeeks":0,"months":[{"name":"FEBRUARY"},{"name":"MAY"},{"name":"AUGUST"},{"name":"NOVEMBER"}],"preference":"CUSTOM_PREFERENCE","weeksOfMonth":[1]}

It appears that the null from the API is imported into the Terraform state as 0 which is then propagated in subsequent updates.

alexandruirimia88 commented 3 months ago

Hello. Any updates on this ?