有时候我们想要在Terraform中使用一些外部数据,但不巧这些数据并没有对应的数据源可用,HashiCorp为这种场景提供了特殊的External Data Source。 external类型数据源允许我们使用外部程序或是脚本来读取数据,并且通过向stdout输出JSON格式数据的形式向Terraform返回数据。 我们来看一个简单的例子,假设我们想要创建一个含有AWS EC2...
# so terraform_external_data will errorifthey aren't.gitName = query['gitName']response = requ...
terraform扮演执行器,利用external provider进行执行各脚本语言,实现执行脚本内容达到预定目标。 三http数据源 3.1 测试场景 使用Terraform编写编排文件,获取github个人资料信息。 3.2 代码 目录结构 ├── main.tf//主文件├── outputs.tf//输出文件└── variables.tf//变量文件 代码内容 # main.tf data"http"...
import json from terraform_external_data import terraform_external_data import requests import json @terraform_external_data def fetch(query): # Terraform requires the values you return be strings, # so terraform_external_data will error if they aren't. gitName = query['gitName'] response = r...
利用data 的http/external可以非常方便的是心啊调用外部接口获取数据。但官方对于External Data Source的定位是"逃生窗口",因此在考虑使用该方案时,为最后手段。 参考链接 https://registry.terraform.io/providers/hashicorp/http/latest/docs 点击关注,第一时间了解华为云新鲜技术~...
terraform扮演执行器,可以执行shell/js/golang/python等各语言代码,但需要在执行环境中具备对应语言的解释器。 五 总结 利用data 的http/external可以非常方便的是心啊调用外部接口获取数据。但官方对于External Data Source的定位是"逃生窗口",因此在考虑使用该方案时,为最后手段。 参考链接...
external=8000 } volumes{ container_path="/usr/share/nginx/html" host_path="/data/nginx_home" } } 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 3.terraform init 初始化 4.terraform plan 预览 root@tf:~/nginx-tf# terraform plan ...
name="nginx_test"ports{internal=80// docker 内部的端口external=8000// 对外访问的端口}volumes{ container_path="/usr/share/nginx/html"host_path="/Users/jasper/data/nginx_home"} } 新建目录/Users/jasper/data/nginx_home,windows去VirtualBox那操作,里面新建一个文件index.html,内容随便来点,就“Hello...
{ forward_table_id = alicloud_nat_gateway.main.forward_table_ids external_ip = alicloud_eip_address.foo.ip_address external_port = "80" ip_protocol = "tcp" internal_ip = "172.16.0.3" internal_port = "8080" } # adding snat entry resource "alicloud_snat_entry" "default" { depends_...
{ forward_table_id = alicloud_nat_gateway.main.forward_table_ids external_ip = alicloud_eip_address.foo.ip_address external_port = "80" ip_protocol = "tcp" internal_ip = "172.16.0.3" internal_port = "8080" } # adding snat entry resource "alicloud_snat_entry" "default" { depends_...