oracle-terraform-modules / terraform-oci-compute-instance

Terraform Module for creating Oracle Cloud Infrastructure compute instances
https://registry.terraform.io/modules/oracle-terraform-modules/compute-instance/oci/latest
Other
46 stars 62 forks source link

Instance creation fails when using count and ad-specific subnets #52

Closed kral2 closed 3 years ago

kral2 commented 3 years ago

When trying to apply with assign_public_ip=true and instance_count=2, the errors are thrown (edit: same error with instance_count=1 actually)

Error: work request did not succeed, workId: ocid1.coreservicesworkrequest.oc1.eu-frankfurt-1.abtheljtvz65owfd5dbokd5zqsgq63ur4nj72nklwhvt2eexuvp3j345qhxq, entity: instance, action: CREATED. Message: A problem occurred while preparing the instance's VNIC.  (Parameter 'availabilityDomain' does not match. VNIC has 'eu-frankfurt-1-ad-3' while the subnet has 'eu-frankfurt-1-ad-1')

  on ..\..\main.tf line 58, in resource "oci_core_instance" "this":
  58: resource "oci_core_instance" "this" {

Error: work request did not succeed, workId: ocid1.coreservicesworkrequest.oc1.eu-frankfurt-1.abtheljtcnunlsdl3iwdu7sfv3kpz23z5nmvwk7u32vussh2bznma3q7ov4a, entity: instance, action: CREATED. Message: A problem occurred while preparing the instance's VNIC.  (Parameter 'availabilityDomain' does not match. VNIC has 'eu-frankfurt-1-ad-3' while the subnet has 'eu-frankfurt-1-ad-1')

  on ..\..\main.tf line 58, in resource "oci_core_instance" "this":
  58: resource "oci_core_instance" "this" {

It seems the issue is related to PR #46 Additional tests required to identify the exact conditions to reproduce the problem. My current tests successfully provision instances with count 1 to 6 all with public IPs, on regional subnets. Probably additional checks needed with ad-specific subnets.

Originally posted by @kral2 in https://github.com/oracle-terraform-modules/terraform-oci-compute-instance/issues/49#issuecomment-781216556

kral2 commented 3 years ago

@aorcl I reproduced the issue. It is due to how instance_count and ad-specific subnets are implemented in the current version of the module.

isolating the repro conditions

recommendations

With the current instance_count implementation, the recommentations are the following:

  1. use regional subnets whenever it is possible
  2. when using ad-specific subnets and var.instance_count together, try to always declare as many subnets as the region have Availability Domains. In this situation, instances will always get affected a valid subnet ocid related to the ad they are affected.
  3. If you cannot provision one ad-specific subnet per ad region, you cannot provision instances count greater than the number of ad specific subnets in the same module.

Long term plan

Plan is to probably deprecate var.instance_count in a future release or go through a major refactoring.

There is better ways to handle multiple instances creation at once today than it was possible two years ago, using either Terraform new capabilities or OCI API new capabilities.

Some options:

Let me know if if works for you.