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

how to use the user_data? #86

Open has12zen opened 2 years ago

has12zen commented 2 years ago

can you provide an example cloud-init-file and shell script and how to use it in user_data? I have created an example repo: https://github.com/has12zen/terraform-oci-compute-instance please can you help me.

kral2 commented 2 years ago

Hi @has12zen

This is how you tell compute-instance module to inject a file using user_data module argument:

# declare a Variable Input to be used as a module argument and assign it a value
variable "some_user_data_variable" {
  description = "provide a shell script or Cloud-Init configuration file to be passed to a compute instance to be executed at instance's first boot" 
  type = string
  default = "path/to/your/file"
}

# declare your module using the variable you just created
module "a_compute_instance" {
  source  = "oracle-terraform-modules/compute-instance/oci"
  version = "2.3.0"
  ... // insert all required arguments
  user_data = filebase64(var.some_user_data_variable) // add `user_data` argument
}

You can have a look at https://github.com/kral2/iacbox to see how it can be used in a real Terraform configuration. Pay attention particularly to these lines:

The file type will be automatically detected and then executed by Cloud-Init, whether it is a shell script or a cloud-init configuration. No additional configuration needed.

I will probably update #74 to include examples in the module's repo. In the meantime, this issue should provide the necessary guidance to use the existing feature.

Please feel free to additional feedback if you think you are still missing something to use this feature 👍