Instance creation fails when using count and ad-specific subnets
kral2 opened this issue · 1 comments
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 #49 (comment)
@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
- you are using ad-specific subnets (regional subnets are not affected by this bug),
length(var.subnet_ocids) < 3 && length(var.subnet_ocids) < var.instance_count
recommendations
With the current instance_count
implementation, the recommentations are the following:
- use regional subnets whenever it is possible
- 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. - 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:
- implementing
for_each
inside the module onoci_core_instance
- using Terraform 0.13 capability to use
count
andfor_each
on a module - using
oci_core_instance_configuration
andoci_core_instance_pool
as they now support attaching and detaching instances
Let me know if if works for you.