阿里云Terraform实践
2020-06-04 05:37
746 查看
阿里云Terraform实践
Terraform环境准备与安装
Golang环境准备
下载Golang安装包
https://golang.org/dl/
清除旧的版本
brew info gobrew uninstall go
安装Golang
- 下载pkg,双击确认
- 编辑~/.bash_profile
export GOPATH=/Users/sjl/Projects/golangexport PATH=$PATH:$GOPATH/bin
Terraform安装
参考Terraform官方文档:https://learn.hashicorp.com/terraform/getting-started/install.html
On mac OSX
brew install terraformterraform -helpterraform -install-autocomplete
mkdir -p Projects/terraforms; cd $_mkdir terraform-docker-demo && cd $_
vi main.tf
resource "docker_image" "nginx" {name = "nginx:latest"keep_locally = false}resource "docker_container" "nginx" {image = docker_image.nginx.latestname = "tutorial"ports {internal = 80external = 8000}}
terraform initterraform planterraform apply
访问如下地址,验证运行结果
docker pshttp://localhost:8000/
terraform destroy
Alibaba Terraform Provider
mkdir -p $GOPATH/src/github.com/terraform-providers; cd $_git clone git@github.com:terraform-providers/terraform-provider-alicloudcd terraform-provider-alicloudmake build
设置环境变量
设置环境变量,省去每次测试时输入AK的要求
运行
Terraform阿里云
创建RAM用户并授权
为提高权限管理的灵活性和安全性,建议您创建RAM用户,并为其授权。
登录 RAM控制台。
创建名为Terraform的RAM用户,并为该用户创建AccessKey。具体步骤请参见创建RAM用户。
为RAM用户授权。具体步骤请参见为RAM用户授权。
export ALICLOUD_ACCESS_KEY=xxxexport ALICLOUD_SECRET_KEY=xxxexport ALICLOUD_REGION=xxxexport ALICLOUD_ACCOUNT_ID=xxxexport ALICLOUD_RESOURCE_GROUP_ID=xxxexport outfile=gotest.outTF_ACC=1 TF_LOG=INFO go test ./alicloud -v -run=TestAccAlicloud -timeout=1440m | tee $outfilego2xunit -input $outfile -output $GOPATH/tests.xml# If your account belongs to domestic siteexport ALICLOUD_ACCOUNT_SITE=Domestic# If your account belongs to international siteexport ALICLOUD_ACCOUNT_SITE=International
vi setenv.sh
export ALICLOUD_ACCESS_KEY="LTAIUrZCw3********"export ALICLOUD_SECRET_KEY="zfwwWAMWIAiooj14GQ2*************"export ALICLOUD_REGION="cn-beijing"
vi unsetenv.sh
unset ALICLOUD_ACCESS_KEYunset ALICLOUD_SECRET_KEYunset ALICLOUD_REGION
chmod 600 setenv.shchmod 600 unsetenv.sh
source setenv.shterraform applyterraform showterraform destroy
参考资料
[1] https://github.com/terraform-providers/terraform-provider-alicloud
[2] https://help.aliyun.com/document_detail/95825.html?spm=a2c4g.11186623.2.14.123240f2MaAtuZ#task-bts-tlz-dfb
[3] https://www.terraform.io/docs/configuration/index.html
[4] https://www.jianshu.com/p/1745e64f07e9
相关文章推荐
- 云上DevOps-CodePipeline,Packer和Terraform集成实践探索
- 利用Terraform 部署 Kubernetes集群最佳实践
- Multi-Cloud模式下Terraform和Packer开源工具实践分享
- Spring MVC-表单(Form)标签-列表框(Listbox)示例(转载实践)
- 阿里云消息队列的实践应用
- 阿里云总监课第四期:阿里褚霸携专家团独家分享弹性计算最佳实践
- Docker实践(四):配置Docker Hub 加速器(DaoCloud、阿里云)
- ERP物理机迁移至阿里云实践
- [bigdata-60]mysql的高可用主主同步复制及其在阿里云上的实践
- 阿里云搭建wordpress生产级CMS网站实践
- 最佳实践:阿里云VPC、ECS支持IPv6啦!
- 南瓜电影CTO庄徐麟:阿里云PCDN集成实践和使用效果分享
- Introduction to Terraform
- ExtJS2.0开发与实践笔记[1]——ExtJS中的Dialog与Form
- HashiCorp Terraform 0.12 新特性抢鲜看:广义Splat算子
- HashiCorp Terraform 0.12 新特性抢鲜看: 丰富的数据类型
- 云端存储的基本技巧和上云实践——清宵教你玩转云存储一:数据上云的基本实践-阿里云栖-专题视频课程...
- 2月06日云栖精选夜读:高德地图基于阿里云MaxCompute的最佳实践
- Spring MVC-表单(Form)标签-复选框(Checkbox)示例(转载实践)