Terraformer导入云上资源
【摘要】 一 背景针对需要Terraform管理的存量资源,虽然terraform提供了import命令来进行导入到terraform统一管理,但是其过程繁琐复杂,且容易出错,需要一块工具一键快速导入存量资源到terraform。 二 Terraformer简介 2.1 工具简介对此Terraformer是一款基于现有基础架构(反向 Terraform)生成 tf/json 和 tfstate 文件...
一 背景
针对需要Terraform管理的存量资源,虽然terraform提供了import命令来进行导入到terraform统一管理,但是其过程繁琐复杂,且容易出错,需要一块工具一键快速导入存量资源到terraform。
二 Terraformer简介
2.1 工具简介
对此Terraformer是一款基于现有基础架构(反向 Terraform)生成 tf/json 和 tfstate 文件的 CLI 工具,帮助用户一件快速导入存量资源。
2.2 能力
- 根据资源从现有基础结构为所有支持的对象生成 tf/json + tfstate 文件。
- 远程状态可以上传到 GCS 存储桶。
- 使用 terraform_remote_state(本地和存储桶)连接资源。
- 使用自定义文件夹树模式保存 tf/json 文件。
- 按资源名称和类型导入。
- 支持 terraform 0.13(对于 terraform 0.11 使用 v0.7.9)。
Terraformer 使用 Terraform 提供程序,旨在轻松支持新添加的资源。要使用新字段升级资源,您需要做的就是升级相关的 Terraform 提供程序。
三 安装
3.1 源码编译安装
- Run
git clone <terraformer repo> && cd terraformer/
- Run
go mod download
- Run
go build -v
for all providers OR build with one providergo run build/main.go {google,aws,azure,kubernetes,etc}
- Run
terraform init
against aversions.tf
file to install the plugins required for your platform. For example, if you need plugins for the google provider,versions.tf
should contain:
terraform {
required_providers {
google = {
source = "hashicorp/google"
}
}
required_version = ">= 0.13"
}
3.2 Mac安装
brew install terraformer
或者
export PROVIDER={all,google,aws,kubernetes}
curl -LO https://github.com/GoogleCloudPlatform/terraformer/releases/download/$(curl -s https://api.github.com/repos/GoogleCloudPlatform/terraformer/releases/latest | grep tag_name | cut -d '"' -f 4)/terraformer-${PROVIDER}-darwin-amd64
chmod +x terraformer-${PROVIDER}-darwin-amd64
sudo mv terraformer-${PROVIDER}-darwin-amd64 /usr/local/bin/terraformer
3.3 二进制安装
export PROVIDER={all,google,aws,kubernetes}
curl -LO https://github.com/GoogleCloudPlatform/terraformer/releases/download/$(curl -s https://api.github.com/repos/GoogleCloudPlatform/terraformer/releases/latest | grep tag_name | cut -d '"' -f 4)/terraformer-${PROVIDER}-linux-amd64
chmod +x terraformer-${PROVIDER}-linux-amd64
sudo mv terraformer-${PROVIDER}-linux-amd64 /usr/local/bin/terraformer
四 执行操作
$ terraformer -h
Usage:
[command]
Available Commands:
help Help about any command
import Import current state to Terraform configuration
plan Plan to import current state to Terraform configuration
version Print the version number of Terraformer
Flags:
-h, --help help for this command
-v, --version version for this command
$ terraformer import -h
Import current state to Terraform configuration
Usage:
import [command]
Available Commands:
alicloud Import current State to terraform configuration from alicloud
auth0 Import current state to Terraform configuration from Auth0
aws Import current state to Terraform configuration from AWS
azure Import current state to Terraform configuration from Azure
azuread Import current state to Terraform configuration from Azure Active Directory
azuredevops Import current state to Terraform configuration from Azure DevOps
cloudflare Import current state to Terraform configuration from Cloudflare
commercetools Import current state to Terraform configuration from Commercetools
datadog Import current state to Terraform configuration from Datadog
digitalocean Import current state to Terraform configuration from DigitalOcean
fastly Import current state to Terraform configuration from Fastly
github Import current state to Terraform configuration from GitHub
gitlab Import current state to Terraform configuration from GitLab
gmailfilter Import current state to Terraform configuration from Gmail
google Import current state to Terraform configuration from Google Cloud
grafana Import current state to Terraform configuration from Grafana
heroku Import current state to Terraform configuration from Heroku
ibm Import current state to Terraform configuration from ibm
keycloak Import current state to Terraform configuration from Keycloak
kubernetes Import current state to Terraform configuration from Kubernetes
launchdarkly Import current state to Terraform configuration from LaunchDarkly
linode Import current state to Terraform configuration from Linode
logzio Import current state to Terraform configuration from Logz.io
mackerel Import current state to Terraform configuration from Mackerel
metal Import current state to Terraform configuration from Equinix Metal
mikrotik Import current state to Terraform configuration from RouterOS
newrelic Import current state to Terraform configuration from New Relic
ns1 Import current state to Terraform configuration from NS1
octopusdeploy Import current state to Terraform configuration from Octopus Deploy
okta Import current State to terraform configuration from okta
openstack Import current state to Terraform configuration from OpenStack
opsgenie Import current state to Terraform configuration from Opsgenie
pagerduty Import current state to Terraform configuration from PagerDuty
panos Import current state to Terraform configuration from a PAN-OS
plan Import planned state to Terraform configuration
rabbitmq Import current state to Terraform configuration from RabbitMQ
tencentcloud Import current state to Terraform configuration from Tencent Cloud
vault Import current state to Terraform configuration from Vault
vultr Import current state to Terraform configuration from Vultr
xenorchestra Import current state to Terraform configuration from Xen Orchestra
yandex Import current state to Terraform configuration from Yandex Cloud
您可以使用 --resources 参数来告诉您要从哪个服务导入资源。要从所有服务导入资源,请使用 --resources="*" 。如果要排除某些服务,可以将该参数与 --excludes 组合以从您不想导入的服务中排除资源,例如–resources="*" --excludes=“iam”。
利用Terraformer导入CVM资源
terraformer import tencentcloud -r "*"
五 其他
- 该工具需要只读权限才能列出服务资源。
参考链接
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)