terraform 支持多种module 的source 配置
以下是一个简单的使用github source的demo

测试项目

  • 项目结构
├── init.tpl
├── main.tf
  • 代码说明
main.tf 主要配置module block
module "users" {
source = "github.com/rongfengliang/terraform-module-demo/modules/users"
username = "dddddemo"
consul_host ="http://127.0.0.1:8500"
}
resource "local_file" "foo" {
content = "${module.users.exec_shell}"
filename = "${path.module}/init.sh"
}
init.tpl 模板
#!/bin/bash
curl -X POST \
${consul_host} \
-H 'Content-Type: application/json' \
-H 'cache-control: no-cache' \
-d '{
"name":"${name}",
"age": "${age}",
"platform":"${platform}",
"id":"${uuid()}"
}'

运行&&效果

使用方法和普通的方式是一样的

  • get module
terraform get 

效果

terraform get
- module.users
  • init
Initializing modules...
- module.users Initializing provider plugins... The following providers do not have any version constraints in configuration,
so the latest version was installed. To prevent automatic upgrades to new major versions that may contain breaking
changes, it is recommended to add version = "..." constraints to the
corresponding provider blocks in configuration, with the constraint strings
suggested below. * provider.local: version = "~> 1.2"
* provider.template: version = "~> 2.1" Terraform has been successfully initialized! You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work. If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
  • 查看plan
terraform plan

效果

Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage. data.template_file.init: Refreshing state...
local_file.foo: Refreshing state... (ID: bf52295095341d2d11821cecc698720af3a7d98f) ------------------------------------------------------------------------ An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
-/+ destroy and then create replacement Terraform will perform the following actions: -/+ local_file.foo (new resource required)
id: "bf52295095341d2d11821cecc698720af3a7d98f" => <computed> (forces new resource)
content: "#!/bin/bash\ncurl -X POST \\\n http://\"http://127.0.0.1:8500\" \\\n -H 'Content-Type: application/json' \\\n -H 'cache-control: no-cache' \\\n -d '{\n \"name\":\"dddddemo\",\n \"age\": \"444\",\n \"platform\":\"mobile\",\n \"id\":\"ac61e848-238a-4646-c58e-e71560690deb\"\n}'" => "#!/bin/bash\ncurl -X POST \\\n http://\"http://127.0.0.1:8500\" \\\n -H 'Content-Type: application/json' \\\n -H 'cache-control: no-cache' \\\n -d '{\n \"name\":\"dddddemo\",\n \"age\": \"444\",\n \"platform\":\"mobile\",\n \"id\":\"67daebf6-21cb-56c6-4a29-fc829333b3e7\"\n}'" (forces new resource)
filename: "/Users/dalong/mylearning/mymodule-ttf/init.sh" => "/Users/dalong/mylearning/mymodule-ttf/init.sh" Plan: 1 to add, 0 to change, 1 to destroy. ------------------------------------------------------------------------ Note: You didn't specify an "-out" parameter to save this plan, so Terraform
can't guarantee that exactly these actions will be performed if
"terraform apply" is subsequently run.
  • apply
terraform apply

效果

data.template_file.init: Refreshing state...
local_file.foo: Refreshing state... (ID: bf52295095341d2d11821cecc698720af3a7d98f) An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
-/+ destroy and then create replacement Terraform will perform the following actions: -/+ local_file.foo (new resource required)
id: "bf52295095341d2d11821cecc698720af3a7d98f" => <computed> (forces new resource)
content: "#!/bin/bash\ncurl -X POST \\\n http://\"http://127.0.0.1:8500\" \\\n -H 'Content-Type: application/json' \\\n -H 'cache-control: no-cache' \\\n -d '{\n \"name\":\"dddddemo\",\n \"age\": \"444\",\n \"platform\":\"mobile\",\n \"id\":\"ac61e848-238a-4646-c58e-e71560690deb\"\n}'" => "#!/bin/bash\ncurl -X POST \\\n http://\"http://127.0.0.1:8500\" \\\n -H 'Content-Type: application/json' \\\n -H 'cache-control: no-cache' \\\n -d '{\n \"name\":\"dddddemo\",\n \"age\": \"444\",\n \"platform\":\"mobile\",\n \"id\":\"3a605320-88e5-47c4-e667-05f4a08b233a\"\n}'" (forces new resource)
filename: "/Users/dalong/mylearning/mymodule-ttf/init.sh" => "/Users/dalong/mylearning/mymodule-ttf/init.sh" Plan: 1 to add, 0 to change, 1 to destroy. Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve. Enter a value: yes local_file.foo: Destroying... (ID: bf52295095341d2d11821cecc698720af3a7d98f)
local_file.foo: Destruction complete after 0s
local_file.foo: Creating...
content: "" => "#!/bin/bash\ncurl -X POST \\\n http://\"http://127.0.0.1:8500\" \\\n -H 'Content-Type: application/json' \\\n -H 'cache-control: no-cache' \\\n -d '{\n \"name\":\"dddddemo\",\n \"age\": \"444\",\n \"platform\":\"mobile\",\n \"id\":\"3a605320-88e5-47c4-e667-05f4a08b233a\"\n}'"
filename: "" => "/Users/dalong/mylearning/mymodule-ttf/init.sh"
local_file.foo: Creation complete after 0s (ID: f29538bda6dcd489041d6cc535c939287d801a70) Apply complete! Resources: 1 added, 0 changed, 1 destroyed.
  • 生成的文件
    init.sh
#!/bin/bash
curl -X POST \
http://"http://127.0.0.1:8500" \
-H 'Content-Type: application/json' \
-H 'cache-control: no-cache' \
-d '{
"name":"dddddemo",
"age": "444",
"platform":"mobile",
"id":"3a605320-88e5-47c4-e667-05f4a08b233a"
}'

说明

terraform module source 对于多种类型的支持还是很不全的,对于我们进行代码的复用还是很方便的

参考资料

https://www.terraform.io/docs/modules/sources.html
https://github.com/rongfengliang/terraform-module-demo

 
 
 
 

terraform 配置github module source的更多相关文章

  1. Git客户端图文详解如何安装配置GitHub操作流程攻略

    收藏自 http://www.ihref.com/read-16377.html Git介绍 分布式 : Git版本控制系统是一个分布式的系统, 是用来保存工程源代码历史状态的命令行工具; 保存点 : ...

  2. Redhat 6 配置CentOS yum source

    由于最近曝出linux的bash漏洞,想更新下bash,于是 想到了配置CentOS yum source. 测试bash漏洞的命令: env x='() { :;}; echo "Your ...

  3. 在配置github中遇到的一些问题

    这次在配置github时,我出现了问题,就是在我装好Git以后,我打开Git Bash,输入了这句代码:$ ssh-keygen -t rsa -C "your_email@youremai ...

  4. 配置GitHub Push自动触发Jenkins的构建

    这里以gitbook的项目为例,GitHub中的gitbook项目部署在Jenkins中,执行git push命令时自动执行Jenkins构建,其他项目只是最后的执行脚本不同 环境准备 安装Jenki ...

  5. windows 下 配置 github

       github   功能介绍 1. 记录多个版本 2.查看历史操作,可以进行版本回退和前进的控制 3. 多端共享代码,自动合成  Github  与  SVN   1.  SVN 版本集中管理,所 ...

  6. 配置GitHub的SSH key

    配置GitHub的SSH key 生成密钥对 打开git bash工具(Windows环境),Linux则直接打开命令行,执行下面的命令生成密钥文件 ssh-Keygen -t rsa -C &quo ...

  7. 如何在Mac下配置Github和Bitbucket的SSH

    --- title: 如何在Mac下配置Github和Bitbucket的SSH date: 2017-12-23 21:10:30 tags: - Mac - Git - Github catego ...

  8. Eclipse配置Github -分享你的代码

    搭建了虚拟机供练手用,想要保存练习代码,于是想在VM Eclipse上配置Github,从此随练随保存. 步骤:1. eclipse ->help->install new softwar ...

  9. [IDEA_3] IDEA 配置 GitHub 并上传项目

    0. 说明 参考 Git & GitHub 的安装配置 IDEA 配置 GitHub 并上传项目 1. 安装配置 Git & GitHub 参照 Git & GitHub 的安 ...

随机推荐

  1. OC的反射机制

    反射机制主要是指程序可以访问.检测和修改它本身状态或行为的一种能力.反射机制是指在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法.对于人一个对象,都能够调用这个对象的任意方法和属性.这种 ...

  2. 微信小程序开发学习记录

    两天撸了一遍小程序的文档,跟网页相似,个人感觉是简化版.但是因为开放了很多微信自带的接口又使得部分功能开发起来相对方便 思维导图如下: 目前我的理解大概是这么个逻辑,以后深入学习后可能会有更改 跟着大 ...

  3. Index.get_indexer 方法的含义

    表示,to_match 中的字符,在 unoque_vals 中的位置索引

  4. vue里面的v-model的变量不要使用下划线

    遇到一个问题,就是如果变量名是text_right,的时候更改v-model的值,则text_right不会更新,如果改成textRight就会更新,目前还不知道原因,先记录下来

  5. Swapping Characters CodeForces - 903E (字符串模拟)

    大意: 给定k个字符串, 长度均为n, 求是否存在一个串S, 使得k个字符串都可以由S恰好交换两个字符得到. 暴力枚举交换的两个字符的位置, 计算出交换后与其他串不同字符的个数, 若为1或>2显 ...

  6. 『TensorFlow』张量拼接_调整维度_切片

    1.tf.concat tf.concat的作用主要是将向量按指定维连起来,其余维度不变:而1.0版本以后,函数的用法变成: t1 = [[1, 2, 3], [4, 5, 6]] t2 = [[7, ...

  7. MVC实战之排球计分(六)—— 使用EF框架,创建Controller,生成数据库。

    在上篇博客我们写到,此软件的数据库连接我们使用的是EF框架,code first模式下, 通过模型类,在创建controller的时候直接生成数据库,完成数据库的连接,与操作. 在使用EF框架之前,我 ...

  8. 记一下JavaScript的几种排序算法

    零.写在最前 排序的方法有很多种,这篇文章只是记录我熟悉的算法: 我发现了一个关于排序算法很有趣的网站,把相关的算法演示做成了动画,有兴趣的同学可以看看! 附上SortAnimate网站链接:http ...

  9. 斜率优化dp的总结

    放在了我的另一个博客上面 斜率优化dp的总结(多刷新几次才打得开)

  10. 微信小程序城市定位(百度地图API)

    概述 微信小程序提供一些API(地址)用于获取当前用户的地理位置等信息,但无论是wx.getLocation,还是wx.chooseLocation均没有单独的字段表示国家与城市信息,仅有经纬度信息. ...