2017-04-06 8 views
0
에 클라우드 초기화와 인스턴스를 initialice 수 있습니다 I 클라우드 초기화를 사용하여 AWS 인스턴스를 initilice하려고

, 나는 시험에 다음 terraform 코드를 사용 :어떻게 Terraform

variable "hostname" {} 
variable "domain_name" {} 


variable "filename" { 
    default = "cloud-config.cfg" 
} 

data "template_file" "test" { 
    template = <<EOF 
#cloud-config 
hostname: $${hostname} 
fqdn: $${fqdn} 
mounts: 
    - [ ephemeral, null ] 
output: 
    all: '| tee -a /var/log/cloud-init-output.log' 
EOF 

    vars { 
    hostname = "${var.hostname}" 
    fqdn  = "${format("%s.%s", var.hostname, var.domain_name)}" 
    } 
} 

data "template_cloudinit_config" "test" { 
    gzip   = false 
    base64_encode = false 

    part { 
    filename  = "${var.filename}" 
    content_type = "text/cloud-config" 
    content  = "${data.template_file.test.rendered}" 
    } 
} 


resource "aws_instance" "bootstrap2" { 
    ami = "${var.aws_centos_ami}" 
    availability_zone = "eu-west-1b" 
    instance_type = "t2.micro" 
    key_name = "${var.aws_key_name}" 
    security_groups = ["${aws_security_group.bastion.id}"] 
    associate_public_ip_address = true 
    private_ip = "10.0.0.12" 
    source_dest_check = false 
    subnet_id = "${aws_subnet.eu-west-1b-public.id}" 
    triggers { 
     template = "${data.template_file.test.rendered}" 
    } 

    tags { 
      Name = "bootstrap2" 
     } 
} 

그러나 내부 트리거를 실패 "부트 스트랩"자원. 그렇다면 내가 정의한 클라우드 구성으로이 인스턴스를 어떻게 프로비저닝 할 수 있습니까?

답변

2

triggersaws_instance 리소스에 대한 유효한 인수가 아닙니다. cloud-init에 구성을 전달하는 일반적인 방법이처럼 user_data 인수를 통해입니다 :

resource "aws_instance" "bootstrap2" { 
    ami = "${var.aws_centos_ami}" 
    availability_zone = "eu-west-1b" 
    instance_type = "t2.micro" 
    key_name = "${var.aws_key_name}" 
    security_groups = ["${aws_security_group.bastion.id}"] 
    associate_public_ip_address = true 
    private_ip = "10.0.0.12" 
    source_dest_check = false 
    subnet_id = "${aws_subnet.eu-west-1b-public.id}" 

    # Pass templated configuration to cloud-init 
    user_data = "${data.template_file.test.rendered}" 

    tags { 
    Name = "bootstrap2" 
    } 
} 
+0

정말 thankss을! 완벽하게 작동합니다. –