Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DBaaS State File Stores/Provisions Incorrect CPU Core Count #539

Closed
HJeon139 opened this issue Jun 1, 2018 · 5 comments
Closed

DBaaS State File Stores/Provisions Incorrect CPU Core Count #539

HJeon139 opened this issue Jun 1, 2018 · 5 comments
Assignees
Labels

Comments

@HJeon139
Copy link

HJeon139 commented Jun 1, 2018

Terraform Version 0.11.7

$ terraform -v Terraform v0.11.7

OCI Provider Version

$ /terraform-provider-oci_v2.1.10

Description

Summary

OCI Provider stores incorrect value in state file or provisions with an incorrect value for cpu count.

Details

Validation on OCI has been updated to check if the cpu count is outside the limits for the requested shape. https://docs.us-phoenix-1.oraclecloud.com/Content/Database/Concepts/overview.htm
Because of this, we are passing in cpu count as 4 and the shape as VM.Instance1.4.
However, the provider stores the cpu count as 8. As a result, any following runs will force a new resource, forcing the process to destroy any configured db and delay builds by the OCI DBaaS Provisioning time (~90 mins).

Steps to reproduce

  1. Build DB by running terraform apply

  2. Check state file to compare input and saved values for oci_database_db_system.database.*.cpu_core_count.

Expected behavior

This value should be the same as the input.

Bug behavior

This value is different from the input.

  1. run terraform apply again
Expected behavior

Terraform recognizes there has been no changes and does nothing.

Bug behavior

Terraform reads that the state file has cpu_core_count=8 but configuration has cpu_core_count=4. Terrraform forces new resource to apply change.

Terraform Plan

Database Resource and Outputs

resource "oci_database_db_system" "database" {
  count                   = "1"

  availability_domain     = "${var.availability_domain}"
  compartment_id          = "${var.compartment_ocid}"
  cpu_core_count          = "${var.cpu_core_count}"
  database_edition        = "ENTERPRISE_EDITION_EXTREME_PERFORMANCE"
  db_home {
    database {
      "admin_password"    = "${var.password}"
      "db_name"           = "${var.db_name}"
      "character_set"     = "AL32UTF8"
      "ncharacter_set"    = "AL16UTF16"
      "db_workload"       = "OLTP"
    }
    db_version            = "12.1.0.2"
  }

  hostname                = "oracle-db"
  shape                   = "VM.Standard1.4"
  ssh_public_keys         = ["${file("${var.ssh_public_key}")}"]
  subnet_id               = "${var.subnet_id}"

  cluster_name            = "DB"
  data_storage_size_in_gb = "256"
  disk_redundancy         = "HIGH"
  display_name            = "Test-Oracle-DB"
  node_count              = "${var.node_count}"
  license_model           = "LICENSE_INCLUDED"
}

output "input_cpu_core_count" {
  value = "${var.cpu_core_count}"
}

output "output_cpu_core_count" {
  value = "${oci_database_db_system.database.*.cpu_core_count}"
}

Plan

terraform plan log

Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.


------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create
  ~ update in-place
 <= read (data resources)

Terraform will perform the following actions:

  ~ data.oci_core_vnic.database_node_vnics[0]
      id:                                      "" => <computed>
      availability_domain:                     "" => <computed>
      compartment_id:                          "" => <computed>
      display_name:                            "" => <computed>
      hostname_label:                          "" => <computed>
      is_primary:                              "" => <computed>
      mac_address:                             "" => <computed>
      private_ip_address:                      "" => <computed>
      public_ip_address:                       "" => <computed>
      skip_source_dest_check:                  "" => <computed>
      state:                                   "" => <computed>
      subnet_id:                               "" => <computed>
      time_created:                            "" => <computed>
      vnic_id:                                 "" => "[REDACTED]"

  ~ data.oci_core_vnic.database_node_vnics[1]
      id:                                      "" => <computed>
      availability_domain:                     "" => <computed>
      compartment_id:                          "" => <computed>
      display_name:                            "" => <computed>
      hostname_label:                          "" => <computed>
      is_primary:                              "" => <computed>
      mac_address:                             "" => <computed>
      private_ip_address:                      "" => <computed>
      public_ip_address:                       "" => <computed>
      skip_source_dest_check:                  "" => <computed>
      state:                                   "" => <computed>
      subnet_id:                               "" => <computed>
      time_created:                            "" => <computed>
      vnic_id:                                 "" => "[REDACTED]"

 <= data.oci_database_databases.databases
      id:                                      <computed>
      compartment_id:                          "[REDACTED]"
      databases.#:                             <computed>
      db_home_id:                              "[REDACTED]"

 <= data.oci_database_db_homes.database_homes
      id:                                      <computed>
      compartment_id:                          "[REDACTED]"
      db_homes.#:                              <computed>
      db_system_id:                            "[REDACTED]"

 <= data.oci_database_db_nodes.database_nodes
      id:                                      <computed>
      compartment_id:                          "[REDACTED]"
      db_nodes.#:                              <computed>
      db_system_id:                            "[REDACTED]"

  + oci_database_db_system.database
      id:                                      <computed>
      availability_domain:                     "[REDACTED]"
      backup_subnet_id:                        <computed>
      cluster_name:                            "DB"
      compartment_id:                          "[REDACTED]"
      cpu_core_count:                          "4"
      data_storage_percentage:                 <computed>
      data_storage_size_in_gb:                 "256"
      database_edition:                        "ENTERPRISE_EDITION_EXTREME_PERFORMANCE"
      db_home.#:                               "1"
      db_home.0.database.#:                    "1"
      db_home.0.database.0.admin_password:     <sensitive>
      db_home.0.database.0.character_set:      "AL32UTF8"
      db_home.0.database.0.db_backup_config.#: <computed>
      db_home.0.database.0.db_name:            "DB"
      db_home.0.database.0.db_workload:        "OLTP"
      db_home.0.database.0.ncharacter_set:     "AL16UTF16"
      db_home.0.database.0.pdb_name:           <computed>
      db_home.0.db_version:                    "12.1.0.2"
      db_home.0.display_name:                  <computed>
      disk_redundancy:                         "HIGH"
      display_name:                            "Test-Oracle-DB"
      domain:                                  <computed>
      hostname:                                "oracle-db"
      last_patch_history_entry_id:             <computed>
      license_model:                           "LICENSE_INCLUDED"
      lifecycle_details:                       <computed>
      listener_port:                           <computed>
      node_count:                              "2"
      reco_storage_size_in_gb:                 <computed>
      scan_dns_record_id:                      <computed>
      scan_ip_ids.#:                           <computed>
      shape:                                   "VM.Standard1.4"
      ssh_public_keys.#:                       "1"
      ssh_public_keys.0:                       "[REDACTED]"
      state:                                   <computed>
      subnet_id:                               "[REDACTED]"
      time_created:                            <computed>
      version:                                 <computed>
      vip_ids.#:                               <computed>


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

------------------------------------------------------------------------

Note: You didn't specify an "-out" parameter to save this plan, so Terraform
can't guarantee that exactly these actions will be performed if
"terraform apply" is subsequently run.

Apply log

terraform apply log

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create
  ~ update in-place
 <= read (data resources)

Terraform will perform the following actions:

  ~ data.oci_core_vnic.database_node_vnics[0]
      id:                                      "" => <computed>
      availability_domain:                     "" => <computed>
      compartment_id:                          "" => <computed>
      display_name:                            "" => <computed>
      hostname_label:                          "" => <computed>
      is_primary:                              "" => <computed>
      mac_address:                             "" => <computed>
      private_ip_address:                      "" => <computed>
      public_ip_address:                       "" => <computed>
      skip_source_dest_check:                  "" => <computed>
      state:                                   "" => <computed>
      subnet_id:                               "" => <computed>
      time_created:                            "" => <computed>
      vnic_id:                                 "" => "[REDACTED]"

  ~ data.oci_core_vnic.database_node_vnics[1]
      id:                                      "" => <computed>
      availability_domain:                     "" => <computed>
      compartment_id:                          "" => <computed>
      display_name:                            "" => <computed>
      hostname_label:                          "" => <computed>
      is_primary:                              "" => <computed>
      mac_address:                             "" => <computed>
      private_ip_address:                      "" => <computed>
      public_ip_address:                       "" => <computed>
      skip_source_dest_check:                  "" => <computed>
      state:                                   "" => <computed>
      subnet_id:                               "" => <computed>
      time_created:                            "" => <computed>
      vnic_id:                                 "" => "[REDACTED]"

 <= data.oci_database_databases.databases
      id:                                      <computed>
      compartment_id:                          "[REDACTED]"
      databases.#:                             <computed>
      db_home_id:                              "[REDACTED]"

 <= data.oci_database_db_homes.database_homes
      id:                                      <computed>
      compartment_id:                          "[REDACTED]"
      db_homes.#:                              <computed>
      db_system_id:                            "[REDACTED]"

 <= data.oci_database_db_nodes.database_nodes
      id:                                      <computed>
      compartment_id:                          "[REDACTED]"
      db_nodes.#:                              <computed>
      db_system_id:                            "[REDACTED]"

  + oci_database_db_system.database
      id:                                      <computed>
      availability_domain:                     "[REDACTED]"
      backup_subnet_id:                        <computed>
      cluster_name:                            "DB"
      compartment_id:                          "[REDACTED]"
      cpu_core_count:                          "4"
      data_storage_percentage:                 <computed>
      data_storage_size_in_gb:                 "256"
      database_edition:                        "ENTERPRISE_EDITION_EXTREME_PERFORMANCE"
      db_home.#:                               "1"
      db_home.0.database.#:                    "1"
      db_home.0.database.0.admin_password:     <sensitive>
      db_home.0.database.0.character_set:      "AL32UTF8"
      db_home.0.database.0.db_backup_config.#: <computed>
      db_home.0.database.0.db_name:            "DB"
      db_home.0.database.0.db_workload:        "OLTP"
      db_home.0.database.0.ncharacter_set:     "AL16UTF16"
      db_home.0.database.0.pdb_name:           <computed>
      db_home.0.db_version:                    "12.1.0.2"
      db_home.0.display_name:                  <computed>
      disk_redundancy:                         "HIGH"
      display_name:                            "Test-Oracle-DB"
      domain:                                  <computed>
      hostname:                                "oracle-db"
      last_patch_history_entry_id:             <computed>
      license_model:                           "LICENSE_INCLUDED"
      lifecycle_details:                       <computed>
      listener_port:                           <computed>
      node_count:                              "2"
      reco_storage_size_in_gb:                 <computed>
      scan_dns_record_id:                      <computed>
      scan_ip_ids.#:                           <computed>
      shape:                                   "VM.Standard1.4"
      ssh_public_keys.#:                       "1"
      ssh_public_keys.0:                       "[REDACTED]"
      state:                                   <computed>
      subnet_id:                               "[REDACTED]"
      time_created:                            <computed>
      version:                                 <computed>
      vip_ids.#:                               <computed>


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

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

  Enter a value: yes

oci_database_db_system.database: Creating...
  availability_domain:                     "" => "[REDACTED]"
  backup_subnet_id:                        "" => "<computed>"
  cluster_name:                            "" => "DB"
  compartment_id:                          "" => "[REDACTED]"
  cpu_core_count:                          "" => "4"
  data_storage_percentage:                 "" => "<computed>"
  data_storage_size_in_gb:                 "" => "256"
  database_edition:                        "" => "ENTERPRISE_EDITION_EXTREME_PERFORMANCE"
  db_home.#:                               "" => "1"
  db_home.0.database.#:                    "" => "1"
  db_home.0.database.0.admin_password:     "<sensitive>" => "<sensitive>"
  db_home.0.database.0.character_set:      "" => "AL32UTF8"
  db_home.0.database.0.db_backup_config.#: "" => "<computed>"
  db_home.0.database.0.db_name:            "" => "DB"
  db_home.0.database.0.db_workload:        "" => "OLTP"
  db_home.0.database.0.ncharacter_set:     "" => "AL16UTF16"
  db_home.0.database.0.pdb_name:           "" => "<computed>"
  db_home.0.db_version:                    "" => "12.1.0.2"
  db_home.0.display_name:                  "" => "<computed>"
  disk_redundancy:                         "" => "HIGH"
  display_name:                            "" => "Test-Oracle-DB"
  domain:                                  "" => "<computed>"
  hostname:                                "" => "oracle-db"
  last_patch_history_entry_id:             "" => "<computed>"
  license_model:                           "" => "LICENSE_INCLUDED"
  lifecycle_details:                       "" => "<computed>"
  listener_port:                           "" => "<computed>"
  node_count:                              "" => "2"
  reco_storage_size_in_gb:                 "" => "<computed>"
  scan_dns_record_id:                      "" => "<computed>"
  scan_ip_ids.#:                           "" => "<computed>"
  shape:                                   "" => "VM.Standard1.4"
  ssh_public_keys.#:                       "" => "1"
  ssh_public_keys.0:                       "" => "[REDACTED]"
  state:                                   "" => "<computed>"
  subnet_id:                               "" => "[REDACTED]"
  time_created:                            "" => "<computed>"
  version:                                 "" => "<computed>"
  vip_ids.#:                               "" => "<computed>"
oci_database_db_system.database: Still creating... (10s elapsed)
oci_database_db_system.database: Still creating... (20s elapsed)
oci_database_db_system.database: Still creating... (30s elapsed)
.
.
.
oci_database_db_system.database: Still creating... (1h39m31s elapsed)
oci_database_db_system.database: Creation complete after 1h39m37s (ID: [REDACTED])
data.oci_database_db_nodes.database_nodes: Refreshing state...
data.oci_database_db_homes.database_homes: Refreshing state...
data.oci_core_vnic.database_node_vnics[0]: Refreshing state...
data.oci_core_vnic.database_node_vnics[1]: Refreshing state...
data.oci_database_databases.databases: Refreshing state...

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Outputs:

input_cpu_core_count = 4
output_cpu_core_count = [
    8
]

2nd apply (to show force new resource)

terraform 2nd apply log

oci_database_db_system.database: Refreshing state... (ID: ocid1.dbsystem.oc1.iad.abuwcljsbkpmy4cz...bij4etsboxbw6aldcmsayzo4budg7byczbk3wq)
data.oci_database_db_homes.database_homes: Refreshing state...
data.oci_database_db_nodes.database_nodes: Refreshing state...
data.oci_core_vnic.database_node_vnics[0]: Refreshing state...
data.oci_core_vnic.database_node_vnics[1]: Refreshing state...
data.oci_database_databases.databases: Refreshing state...

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  ~ update in-place
-/+ destroy and then create replacement
 <= read (data resources)

Terraform will perform the following actions:

  ~ data.oci_core_vnic.database_node_vnics[0]
      id:                                      "" => <computed>
      availability_domain:                     "" => <computed>
      compartment_id:                          "" => <computed>
      display_name:                            "" => <computed>
      hostname_label:                          "" => <computed>
      is_primary:                              "" => <computed>
      mac_address:                             "" => <computed>
      private_ip_address:                      "" => <computed>
      public_ip_address:                       "" => <computed>
      skip_source_dest_check:                  "" => <computed>
      state:                                   "" => <computed>
      subnet_id:                               "" => <computed>
      time_created:                            "" => <computed>
      vnic_id:                                 "" => "[REDACTED]"

  ~ data.oci_core_vnic.database_node_vnics[1]
      id:                                      "" => <computed>
      availability_domain:                     "" => <computed>
      compartment_id:                          "" => <computed>
      display_name:                            "" => <computed>
      hostname_label:                          "" => <computed>
      is_primary:                              "" => <computed>
      mac_address:                             "" => <computed>
      private_ip_address:                      "" => <computed>
      public_ip_address:                       "" => <computed>
      skip_source_dest_check:                  "" => <computed>
      state:                                   "" => <computed>
      subnet_id:                               "" => <computed>
      time_created:                            "" => <computed>
      vnic_id:                                 "" => "[REDACTED]"

 <= data.oci_database_databases.databases
      id:                                      <computed>
      compartment_id:                          "[REDACTED]"
      databases.#:                             <computed>
      db_home_id:                              "[REDACTED]"

 <= data.oci_database_db_homes.database_homes
      id:                                      <computed>
      compartment_id:                          "[REDACTED]"
      db_homes.#:                              <computed>
      db_system_id:                            "[REDACTED]"

 <= data.oci_database_db_nodes.database_nodes
      id:                                      <computed>
      compartment_id:                          "[REDACTED]"
      db_nodes.#:                              <computed>
      db_system_id:                            "[REDACTED]"

-/+ oci_database_db_system.database (new resource required)
      id:                                      "[REDACTED]" => <computed> (forces new resource)
      availability_domain:                     "[REDACTED]" => "[REDACTED]"
      backup_subnet_id:                        "" => <computed>
      cluster_name:                            "DB" => "DB"
      compartment_id:                          "[REDACTED]" => "[REDACTED]"
      cpu_core_count:                          "8" => "4" (forces new resource)
      data_storage_percentage:                 "80" => <computed>
      data_storage_size_in_gb:                 "256" => "256"
      database_edition:                        "ENTERPRISE_EDITION_EXTREME_PERFORMANCE" => "ENTERPRISE_EDITION_EXTREME_PERFORMANCE"
      db_home.#:                               "1" => "1"
      db_home.0.database.#:                    "1" => "1"
      db_home.0.database.0.admin_password:     <sensitive> => <sensitive> (attribute changed)
      db_home.0.database.0.character_set:      "AL32UTF8" => "AL32UTF8"
      db_home.0.database.0.db_backup_config.#: "0" => <computed>
      db_home.0.database.0.db_name:            "DB" => "DB"
      db_home.0.database.0.db_workload:        "OLTP" => "OLTP"
      db_home.0.database.0.ncharacter_set:     "AL16UTF16" => "AL16UTF16"
      db_home.0.database.0.pdb_name:           "" => <computed>
      db_home.0.db_version:                    "12.1.0.2" => "12.1.0.2"
      db_home.0.display_name:                  "" => <computed>
      disk_redundancy:                         "HIGH" => "HIGH"
      display_name:                            "Test-Oracle-DB" => "Test-Oracle-DB"
      domain:                                  "[REDACTED]" => <computed>
      hostname:                                "oracle-db" => "oracle-db"
      last_patch_history_entry_id:             "" => <computed>
      license_model:                           "LICENSE_INCLUDED" => "LICENSE_INCLUDED"
      lifecycle_details:                       "" => <computed>
      listener_port:                           "1521" => <computed>
      node_count:                              "2" => "2"
      reco_storage_size_in_gb:                 "256" => <computed>
      scan_dns_record_id:                      "[REDACTED]" => <computed>
      scan_ip_ids.#:                           "3" => <computed>
      shape:                                   "VM.Standard1.4" => "VM.Standard1.4"
      ssh_public_keys.#:                       "1" => "1"
      ssh_public_keys.0:                       "[REDACTED]" (forces new resource)
      state:                                   "AVAILABLE" => <computed>
      subnet_id:                               "[REDACTED]" => "[REDACTED]"
      time_created:                            "2018-06-01 18:39:16.419 +0000 UTC" => <computed>
      version:                                 "12.2.0.1.180116" => <computed>
      vip_ids.#:                               "2" => <computed>


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

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

  Enter a value: no


Error: Apply cancelled.

@HJeon139
Copy link
Author

HJeon139 commented Jun 4, 2018

It appears that the cpu core count is no longer being used and is instead calculated based on the shape. So cpu count for a 2 node DB is 8 when using shape VM.Instance1.4.

Perhaps the fix would be to make the field not required and not force new resource as mentioned in the other issue:

#517

@drauba
Copy link

drauba commented Jun 4, 2018

It appears that the cpu core count is no longer being used and is instead calculated based on the shape. So cpu count for a 2 node DB is 8 when using shape VM.Instance1.4.

This is only true for Database Systems with a VM node. CPU Core Count is used for Database Systems running on Baremetal shapes.

@rcohenma
Copy link
Contributor

From the documentation:

  • cpu_core_count - (Required) The number of CPU cores to enable. The valid values depend on the specified shape: - BM.DenseIO1.36 and BM.HighIO1.36 - Specify a multiple of 2, from 2 to 36. - BM.RACLocalStorage1.72 - Specify a multiple of 4, from 4 to 72. - Exadata.Quarter1.84 - Specify a multiple of 2, from 22 to 84. - Exadata.Half1.168 - Specify a multiple of 4, from 44 to 168. - Exadata.Full1.336 - Specify a multiple of 8, from 88 to 336. For VM DB systems, the core count is inferred from the specific VM shape chosen, so this parameter is not used.

To solve your issue we will make cpu_core_count Optional rather than Required so that you can avoid specifying it when using VM shapes.

While we work on this fix you can change your config to match the value in the statefile (the value returned by the service). This will avoid unnecessary diffs on subsequent applies.

@HJeon139
Copy link
Author

HJeon139 commented Jun 19, 2018

The issue we had where OCI would not set it to the calculated value (node count * cpu per node) is now resolved. We are able to spin up db systems by using the calculated value. (e.g. in the example above we can now put in shape 1.4 and node count 2 with cpu core count 8).

@codycushing
Copy link
Contributor

Hello, this has been addressed in release 2.1.13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants