Git Product home page Git Product logo

terraformit-gcp's Introduction

terraformit-gcp

terraformit-gcp is an open source command line tool for generating tf files and tfstate from existing GCP resources.
Relieve the pain of coding tf of manually created GCP resources.

terraformit-gcp steps are as below.

  1. terraformit-gcp get json data of existing GCP resources using Cloud Asset API exportAssets method.

  2. terraformit-gcp generates files for creating a tfstate(="terraform import") from the json data.

  3. terraformit-gcp generates tf files from the tfstate.

  4. terraformit-gcp executes "terraform plan" command to check tf files are generated successfully.

Version Table

terraformit-gcp does not support terraform 0.12.0 now.

terraformit-gcp go terraform google provider google provider (beta)
v0.9.0 v1.12 v0.11.13 and v0.11.14 v2.5.1 v2.5.1

To start using terraformit-gcp

Please follow these steps.

Install commands

Install terraform or tfenv(Terraform version manager).

Install gcloud to create a credential.

Install Go tools to use go command.

Set gcloud authentication

Generate ~/.config/gcloud/application_default_credentials.json credential.
Terraform command and google storage library use this credential.

gcloud init

or

gcloud auth login

Install terraformit-gcp

Install terraformit-gcp. git clone terraformit-gcp to your GOPATH.

export GO111MODULE=on
git clone https://github.com/cloud-ace/terraformit-gcp.git -b v0.9.1 ~/go/src/github.com/cloud-ace/terraformit-gcp
cd ~/go/src/github.com/cloud-ace/terraformit-gcp
go install

Set path

Add GOPATH to PATH, if you need.
(mac)

echo 'export GOPATH=$HOME/go' >> ~/.bash_profile
echo 'export PATH=$PATH:$GOPATH/bin' >> ~/.bash_profile
source ~/.bash_profile

Enable CloudAssetAPI

Enable CloudAssetAPI.

Create bucket for storing CloudAssetAPI json data

Create bucket for storing CloudAssetAPI outputs.

Generate and download credential for CloudAssetAPI

Genereate Oauth Client ID and download a credentials.
Cloud Asset API only supports Oauth Client ID now.
https://cloud.google.com/resource-manager/docs/cloud-asset-inventory/calling-api-with-local-machine-howto?hl=en#downloading_the_credential_file

cd your pj directory

Change your terraform project directory.

cd "your terraform project directory"

Create .terraformit-gcp.yaml in your project directory

Create .terraformit-gcp.yaml in your project directory and set your configuration.
Please refer to the sample file(sample.terraformit-gcp.yaml) in this repository.

CloudAsset:
  # GCP project number
  project-number: "xxxxxxxx" 

  # bucket name. CloudAssetAPI MetadataFile is exported to this bucket.
  bucket: "xxxxxxxxx"

  # Oauth Client ID credential location
  credential: "/Users/xxxxx/Downloads/xxxxxx.json"

Terraform:
  # provider. "google" or "google-beta" should be set.
  provider: "google"

  # your workspace 
  workspace: "default"

  # buckend type "local" or "gcs" is supported now.
  # https://www.terraform.io/docs/backends/types/gcs.html
  backend-type: "local"

  # if you set "local" to backend-type, set "" to backend-location.
  # backend-location: ""
  # if you set "gcs" to backend-type ,set your bucket name to backend-location
  # backend-location: "bucketname"  
  backend-location: ""

  # Default Region
  gcp-provider-default-region: "asia-northeast1"

  # whether add Default resources("true") or remove("false").
  # set true or false. If you set "false", skip default resource.
  # Default service accounts are removed automatically because their name start with number("12233445@....") which cause an error. 
  resource-default-network: false
  resource-default-subnetwork: false
  resource-default-route: false
  resource-default-firewall: false

terraformit-gcp Command

terraformit-gcp plan

Following steps below are executed.

  1. create CloudAssetMetadata calling CloudAssetAPI
  2. get CloudAssetMetadata from GCS
  3. create ImportFiles
  4. "terraform init"
  5. "terraform workspace new"
  6. "terraform import"(create tfstate)
  7. create tffile
  8. "terraform plan"

terraformit-gcp create cloudasset

Following steps below are executed.

  1. create CloudAssetMetadata calling CloudAssetAPI

terraformit-gcp create importfiles (-f ./xxx/xxxxx or gs://xxxxxx/xxxx)

Following steps below are executed.

  1. get CloudAssetMetadata from GCS or local(-f option)
  2. create ImportFiles

terraformit-gcp create tfstate

Following steps below are executed.

  1. "terraform init"
  2. "terraform workspace new"
  3. "terraform import" using importfiles

terraformit-gcp create tffile (-f tfstatefile)

Following steps below are executed.

  1. create tffile

Support Table

This command supports GCP resources which is supported by Cloud Asset API.

โœ…:support
๐Ÿ”ง:will support
/ :not supported

CloudAssetAPI Name CloudAssetAPI Support terrafromResource name terrafromResource Support
Cloud Key Management Service
cloudkms.googleapis.com/KeyRing โœ… google_kms_key_ring โœ…
cloudkms.googleapis.com/CryptoKey โœ… google_kms_crypto_key โœ…
cloudkms.googleapis.com/CryptoKeyVersion / / /
Resource Manager
cloudresourcemanager.googleapis.com/Organization / / /
cloudresourcemanager.googleapis.com/Folder / google_folder /
cloudresourcemanager.googleapis.com/Project โœ… google_project โœ…
Compute Engine
compute.googleapis.com/Autoscaler โœ… google_compute_autoscaler โœ…
compute.googleapis.com/BackendBucket โœ… google_compute_backend_bucket โœ…
compute.googleapis.com/BackendService โœ… google_compute_backend_service โœ…
compute.googleapis.com/Disk โœ… google_compute_disk โœ…
compute.googleapis.com/Firewall โœ… google_compute_firewall โœ…
compute.googleapis.com/ForwardingRule โœ…(only support in default Region) google_compute_forwarding_rule โœ…
compute.googleapis.com/GlobalForwardingRule โœ… google_compute_global_forwarding_rule โœ…
compute.googleapis.com/HealthCheck โœ… google_compute_health_check โœ…
compute.googleapis.com/HttpHealthCheck โœ… google_compute_http_health_check โœ…
compute.googleapis.com/HttpsHealthCheck ๐Ÿ”ง google_compute_https_health_check ๐Ÿ”ง
compute.googleapis.com/Image โœ… google_compute_image โœ…
compute.googleapis.com/Instance โœ… google_compute_instance โœ…
compute.googleapis.com/InstanceGroup โœ… google_compute_instance_group โœ…
compute.googleapis.com/InstanceGroupManager โœ… google_compute_instance_group_manager โœ…
compute.googleapis.com/InstanceTemplate โœ… google_compute_instance_template โœ…
compute.googleapis.com/Network โœ… google_compute_network โœ…
compute.googleapis.com/Project / / /
compute.googleapis.com/RegionBackendService ๐Ÿ”ง google_compute_region_backend_service ๐Ÿ”ง
compute.googleapis.com/Route โœ… google_compute_route โœ…
compute.googleapis.com/Router ๐Ÿ”ง google_compute_router ๐Ÿ”ง
compute.googleapis.com/Snapshot โœ… google_compute_snapshot โœ…
compute.googleapis.com/SslCertificate โœ… google_compute_ssl_certificate(you need to set your private key manually) โœ…
compute.googleapis.com/Subnetwork โœ… google_compute_subnetwork โœ…
compute.googleapis.com/TargetHttpProxy โœ… google_compute_target_http_proxy โœ…
compute.googleapis.com/TargetHttpsProxy โœ… google_compute_target_https_proxy โœ…
compute.googleapis.com/TargetInstance / / /
compute.googleapis.com/TargetPool โœ…(only support in default Region) google_compute_target_pool โœ…
compute.googleapis.com/TargetTcpProxy ๐Ÿ”ง google_compute_target_tcp_proxy ๐Ÿ”ง
compute.googleapis.com/TargetSslProxy ๐Ÿ”ง google_compute_target_ssl_proxy ๐Ÿ”ง
compute.googleapis.com/TargetVpnGateway ๐Ÿ”ง google_compute_vpn_gateway ๐Ÿ”ง
compute.googleapis.com/UrlMap โœ… google_compute_url_map โœ…
compute.googleapis.com/VpnTunnel ๐Ÿ”ง google_compute_vpn_tunnel ๐Ÿ”ง
App Engine
appengine.googleapis.com/Application ๐Ÿ”ง google_app_engine_application(cannot delete app engine) ๐Ÿ”ง
appengine.googleapis.com/Service / / /
appengine.googleapis.com/Version / / /
Google Kubernetes Engine
container.googleapis.com/Cluster โœ… google_container_cluster โœ…
container.googleapis.com/NodePool(beta) ๐Ÿ”ง google_container_node_pool ๐Ÿ”ง
Cloud Billing
cloudbilling.googleapis.com/BillingAccount / / /
Cloud Storage
storage.googleapis.com/Bucket โœ… google_storage_bucket โœ…
Cloud DNS
dns.googleapis.com/ManagedZone โœ… google_dns_managed_zone โœ…
dns.googleapis.com/Policy โœ…(only google-beta) google_dns_policy โœ…
Cloud Spanner
spanner.googleapis.com/Instance ๐Ÿ”ง google_spanner_instance ๐Ÿ”ง
spanner.googleapis.com/Database ๐Ÿ”ง google_spanner_database ๐Ÿ”ง
BigQuery
bigquery.googleapis.com/Dataset ๐Ÿ”ง google_bigquery_dataset ๐Ÿ”ง
bigquery.googleapis.com/Table ๐Ÿ”ง google_bigquery_table ๐Ÿ”ง
Cloud Identity and Access Management
iam.googleapis.com/Role ๐Ÿ”ง google_iam_member ๐Ÿ”ง
iam.googleapis.com/ServiceAccount โœ… google_service_account โœ…
Cloud Pub/Sub
pubsub.googleapis.com/Topic โœ… google_pubsub_subscription โœ…
pubsub.googleapis.com/Subscription โœ… google_pubsub_topic โœ…
Cloud Dataproc
dataproc.googleapis.com/Cluster ๐Ÿ”ง google_dataproc_cluster ๐Ÿ”ง
dataproc.googleapis.com/Job ๐Ÿ”ง google_dataproc_job ๐Ÿ”ง
Cloud SQL
sqladmin.googleapis.com/Instance โœ… google_sql_database_instance โœ…
Cloud Bigtable
bigtableadmin.googleapis.com/Cluster / / /
bigtableadmin.googleapis.com/Instance ๐Ÿ”ง google_bigtable_instance ๐Ÿ”ง
bigtableadmin.googleapis.com/Table ๐Ÿ”ง google_bigtable_table ๐Ÿ”ง
Google Kubernetes Engine
k8s.io/Node / / /
k8s.io/Pod / / /
k8s.io/Namespace / / /
rbac.authorization.k8s.io/Role / / /
rbac.authorization.k8s.io/RoleBinding / / /
rbac.authorization.k8s.io/ClusterRole / / /
rbac.authorization.k8s.io/RoleBinding / / /

terraformit-gcp's People

Contributors

ca-iijima avatar yasunorikawasaki avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.