variable "access_key" {
  default = "fHrc64JJfNV9pLVUMIsQ"
}

variable "secret_key" {
  default = "93qernzjJp9CKuGkXLlHxQNn2bkxIKauzCkBjrw4"
}

locals {
  timestamp = regex_replace(timestamp(), "[- TZ:]", "")
}

source "ncloud" "test-linux" {
  access_key                = "${var.access_key}"
  secret_key                = "${var.secret_key}"
  server_image_product_code = "SW.VSVR.OS.LNX64.UBNTU.SVR2004.B050"
  server_image_name         = "packer-${local.timestamp}"
  server_image_description  = "server image description"
  region_code               = "KR"
  support_vpc               = true
  communicator              = "ssh"
  ssh_username              = "root"
}

build {
  sources = ["source.ncloud.test-linux"]

  provisioner "ansible" {
    playbook_file       = "./ansible/node_roles.yaml"
    user                = "root"
    #extra_arguments     = ["--become","--ssh-extra-args", "'-o HostKeyAlgorithms=+ssh-rsa'", "'-o PubkeyAcceptedKeyTypes=+ssh-rsa'"]
    extra_arguments     = ["--scp-extra-args", "'-O'", "--ssh-extra-args", "-o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedKeyTypes=+ssh-rsa -o IdentitiesOnly=yes", "--become"]
    ansible_env_vars    = ["ANSIBLE_HOST_KEY_CHECKING=False"]
  }
}
