当前位置:网站首页>Terraformer importing cloud resources

Terraformer importing cloud resources

2022-06-11 13:18:00 Hua Weiyun

One background

For the needs of Terraform Managed stock resources , although terraform Provides import Command to import into terraform Unified management , But the process is complicated , And easy to make mistakes , You need a tool to quickly import stock resources to terraform.

Two Terraformer brief introduction

2.1 Tool introduction

Regarding this Terraformer Is based on an existing infrastructure ( reverse Terraform) Generate tf/json and tfstate Of documents CLI Tools , Help users quickly import stock resources .

2.2 Ability

  • Generate... From existing infrastructure for all supported objects based on resources tf/json + tfstate file .
  • Remote status can be uploaded to GCS bucket .
  • Use terraform_remote_state( Local and bucket ) Connect resources .
  • Use custom folder tree mode to save tf/json file .
  • Import by resource name and type .
  • Support terraform 0.13( about terraform 0.11 Use v0.7.9).

Terraformer Use Terraform Provider , Designed to easily support newly added resources . To upgrade resources with new fields , All you need to do is upgrade the related Terraform Provider .

3、 ... and install

3.1 Source code compilation and installation

  1. Run git clone <terraformer repo> && cd terraformer/
  2. Run go mod download
  3. Run go build -v for all providers OR build with one provider go run build/main.go {google,aws,azure,kubernetes,etc}
  4. Run terraform init against a versions.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 install

brew install terraformer

perhaps

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-amd64chmod +x terraformer-${PROVIDER}-darwin-amd64sudo mv terraformer-${PROVIDER}-darwin-amd64 /usr/local/bin/terraformer

3.3 Binary installation

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-amd64chmod +x terraformer-${PROVIDER}-linux-amd64sudo mv terraformer-${PROVIDER}-linux-amd64 /usr/local/bin/terraformer

Four Perform the operation

$ terraformer -hUsage:   [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 TerraformerFlags:  -h, --help      help for this command  -v, --version   version for this command$ terraformer import -hImport current state to Terraform configurationUsage:   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

You can use --resources Parameter to tell you which service to import resources from . To import resources from all services , Please use --resources="*" . If you want to exclude certain services , You can associate this parameter with --excludes Composition to exclude resources from services you do not want to import , for example –resources="*" --excludes=“iam”.

utilize Terraformer Import CVM resources

terraformer import tencentcloud -r "*"

5、 ... and other

  • The tool requires read-only permission to list service resources .

Reference link

原网站

版权声明
本文为[Hua Weiyun]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206111312171853.html