【问题标题】:What is the correct merge type for cloud-init sections in multipart MIME format?多部分 MIME 格式的 cloud-init 部分的正确合并类型是什么?
【发布时间】:2017-12-18 02:38:52
【问题描述】:

我正在尝试将 cloud-init 配置的多个部分与 Terraform 的 AWS 实例的 template_cloudinit_config 功能合并。

想象一下 4 个模板(此处简化):

# template 1
hostname: ${hostname}

# template 2
users:
- name: "a"
- name: "b"
- name: "c"

# template 3
coreos:
  units:
  - name: ${service}.service

# template 4
coreos:
  units:
  - name: ${service2}.service

如果我使用 cloud-config 标头对这些进行 MIME 编码...

--MIMEBOUNDARY
Content-Transfer-Encoding: 7bit
Content-Type: text/cloud-config
Mime-Version: 1.0

要使用的正确合并类型是什么?

【问题讨论】:

    标签: terraform mime cloud-init


    【解决方案1】:

    您列出的模板是cloud-config,而不是cloud-init

    使用数据源template_file,我是直接写的,没有测试,能不能验证一下?

    data "template_file" "user-data" {
      template = <<EOF
    #cloud-config
    # template 1
    hostname: ${hostname}
    
    # template 2
    users:
    - name: "a"
    - name: "b"
    - name: "c"
    
    # template 3
    coreos:
      units:
      - name: ${service}.service
    
    # template 4
    coreos:
      units:
      - name: ${service2}.service
    
    EOF
    
      vars {
        hostname = "${var.hostname}"
        service  = "${var.service}"
        service2 = "${var.service2}"
    
      }
    }
    
    resource "aws_instance" "instance" {
      ami = "${ var.ami-id }"
      ...
    
      user_data = "${ data.template_file.user-data.rendered }"
    
    }
    

    【讨论】:

      猜你喜欢
      • 2011-11-10
      • 2012-11-08
      • 2019-07-21
      • 2017-12-19
      • 1970-01-01
      • 2013-01-22
      • 2016-12-24
      • 2011-05-11
      相关资源
      最近更新 更多