Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
370 views
in Technique[技术] by (71.8m points)

devops - Terraform: What is the simplest way to Incrementally add servers to a deployment?

I am a newbie with terraform so don′t laugh :) I want to deploy a number of instances of a server, then add their IPs to a Route53 hosted zone. I will be using Terraform v0.12.24 no chance of 0.14 at the moment.

So far, I have working the "easy", spaghetti approach:

enter image description here

  • module server: buys and creates a list of servers

  • module route53: adds route53 records, parameter=aray of ips

main.tf

module "hostedzone" {
  source = "./route53"
  ncs_domain = var.ncs_domain
}

module "server" {
  source = "./server"
  name = "${var.ncs_hostname}-${var.ncs_id}"
  hcloud_token = var.server_htk
  servers = [
    {
      type = "cx11",
      location = "fsn1",
    },
    {
      type = "cx11",
      location = "fsn1",
    }
  ]
}

resource "aws_route53_record" "server1-record" {
  zone_id = module.hostedzone.zone.zone_id
  name = "${var.ncs_hostname}.${var.ncs_domain}"
  type = "A"
  ttl = "300"
  records = module.server.server.*.ipv4_address
}

and the relevant server resource array:

resource "hcloud_server" "apiserver" {
  count = length(var.servers)
  # Create a server
  name = "${var.name}-${count.index}"
  # Name server
  image = var.image
  # Basic image
  server_type = var.servers[count.index].type
  # Instance type
  location = var.servers[count.index].location
}

So if I run terraform apply, I get the server array created. Cool !

Now, I would like to be able to run this module to create and destroy specific servers on demand, like:

  • initially deploy the platform with one or two servers.

  • remove one of the initial servers in the array

  • add new servers

So, how could I use this incrementally, that is, without providing the whole array of servers everytime? Like just adding one to the existing list, or remove other.

question from:https://stackoverflow.com/questions/65845151/terraform-what-is-the-simplest-way-to-incrementally-add-servers-to-a-deployment

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...