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

When regional subnets are used, the instance fails to detect the availability domain #41

Closed aorcl closed 3 years ago

aorcl commented 3 years ago

The code in main.tf relies on deriving the AD from the subnet's AD used to create the instance. When the subnet used is of regional type, the detection fails

main.tf, line 17 availability_domain = data.oci_core_subnet.this[count.index % length(data.oci_core_subnet.this.*.availability_domain)].availability_domain

aorcl commented 3 years ago

this results in an error when plan or apply actions are called

Error: "availability_domain": required field is not set

  on ..\..\main.tf line 15, in resource "oci_core_instance" "this":
  15: resource "oci_core_instance" "this" {
aorcl commented 3 years ago

@kral2 - need to discuss this. With regional subnets, there is no input element anymore in the module that could be used as source for instance's AD. Should we add a mandatory input variable in variables.tf? I see no other way and guessing an AD or assigning a random AD doesn't look as the right idea.

kral2 commented 3 years ago

There is currently lot of broken or missing features: this module needs a major overhaul.

We will probably go for a complete rewrite for v3.0.0.

aorcl commented 3 years ago

I'll add the AD input variable in the module in the meantime, cannot release the upgraded 0.12 version without compatibility with regional subnets...

kral2 commented 3 years ago

Backporting a solution for this issue from my existing alternate compute module. The solution uses availability domaine Data Source + a list local

adding var.ad_number, data.oci_identity_availability_domains.ad, local.ADs

User can select the desired AD giving just a number. If no number is given, instances will be provisioned in a round robin manner starting with AD 1.

Module now compatible with both regional and ad-specific subnets (no more dependency at this level).