Terraform
cloud.google.com Terraform的にはこの辺かな registry.terraform.io
サービスアカウント情報を管理。 resourceもdataもあるしdataはresourceを定義しなくても使える。 registry.terraform.io
timeoutsの設定、masterにはマージされているけど現状最新の21.1.0じゃ設定にないから、内部で設定してあるデフォルト値のようなものが入る。 github.com github.com
addressとかnatとかが既に作成されているならregistryの書き方をなぞった方が早いかも registry.terraform.io github.com
2022/06/17のmasterブランチにはtimeoutsオプションがありげだったけど2週間前にマージされた機能であるから、まだ21.1.0にはなかった github.com
この辺がすごい参考になる plan結果をGitHubのプルリクにコメント残したい + 同一のコメントを更新し続ける(commit pushするたびにコメントが増えない)ようにする。 - uses: actions/github-script@v6 if: github.event_name == 'pull_request' env: PLAN: "…
aws_instance タイプ web ローカルネーム resource "aws_instance" "web" { ami = "ami-a1b2c3d4" instance_type = "t2.micro" } www.terraform.io
原理はまるで分からないけど、つまりはそういうことなんだろう # NG $ terraform import module.rds.aws_cloudwatch_log_subscription_filter.rds_logs_delivery["prod-service-reports.audit"] rds-logs-delivery-prod-service-master # OK $ terraform imp…
network/subnetwork/routeをまとめて作るterraformのモジュールでGCP開発。 github.com flow log周りとかsecondary ip rangeとか、terraform-google-modulesのソースコードを見たらわかるけどループでぐるぐる回してる このモジュールの設定が、実際のterraf…
1アカウントで小さく始める。 www.terraform-best-practices.com
ルートのリソース。 A Route resource must have exactly one specification of either nextHopGateway, nextHopInstance, nextHopIp, nextHopVpnTunnel, or nextHopIlb. なんかoptionalな風を見せてるけどnext hopの設定はどれか設定してやらないといけない…
Terraformはルートモジュール(work-dir)の直下のHCLファイルの追加変更削除しか対応してくれないので、変更箇所のあるディレクトリをmatrixでまとめて実行してしまおうという。 なのだけれど、変更箇所の検知が git diff --name-only HEAD^ HEAD なので、例…
terraform importはstateを更新(実体としてはバックエンドのtfstateファイルを更新)するだけでconfigは生成しないから、HCLファイルの方はterraform showの結果などを手動自前でいい感じに編集する必要がある。 www.terraform.io ちなみにgcloud beta resour…
形式はTerraformです。 gcloud beta resource-config bulk-exportしてHCLファイルを出力し、gcloud beta resource-config terraform generate-importしてTerraformモジュールとimportスクリプトを出力し、スクリプトを実行してterraform importする。import…
terraformer importしてterraform initするところまでは一緒だけど、providerをreplaceしないといけない。terraformerが最新に合っていないのか、、 あとはprovider.tfにcloudブロックを入れて、terraform init $ terraform state replace-provider registry…
Google謹製だから余程のことがない限りはメンテは続くと思う。 類似のterraformingがりどみで紹介されていたけど去年末にメンテ終了してしまった。 github.com 例 terraformer import google --resources=gcs,forwardingRules,httpHealthChecks --connect=tr…
AWSのsecrets managerみたいなものか registry.terraform.io
リソースを指定するときはデータセットもセットで。 $ terraform import google_bigquery_table.default gcp-project/foo/bar registry.terraform.io
ポイントはこの辺 $ terraform import google_storage_bucket.image-store image-store-bucket $ terraform import google_storage_bucket.image-store tf-test-project/image-store-bucket registry.terraform.io
Input Variables Output Values Local Values www.terraform.io
キーワードは terraform cloud import とかで検索したっていまいち欲しい情報が得られないっていう バックエンドremote設定をversions.tfなどに書いておいて、terraform loginしてterraform initしてterraform importすれば、stateがTerraform Cloudに上がっ…
書き方。 $ terraform import google_compute_instance.default projects/{{project}}/zones/{{zone}}/instances/{{name}} $ terraform import google_compute_instance.default {{project}}/{{zone}}/{{name}} $ terraform import google_compute_instance.…
Account represents the current user interacting with Terraform. It returns the same type of object as the Users API, but also includes an email address, which is hidden when viewing info about other users. curl \ --header "Authorization: B…
stateファイルの共有 デフォルトはローカルディスク 利用できるbackendはいっぱいある(AWS/GCP/Azure) terraform { backend "s3" { bucket = "mybucket" key = "path/to/my/key" region = "us-east-1" } } www.terraform.io blog.mosuke.tech
brew install terragrunt terragrunt.gruntwork.io
やっぱりチュートリアルだね homebrewでtfenvとterraformが両立しない GCPよくわかんないけど、最初のVPC作成でterraform applyしようとしたらcompute.networks.createの権限がないって怒られた。サービスアカウントの権限まわりよくわからないから別途調べ…
中の人が書いてるから信用性あると思う www.terraform-best-practices.com
パラメータが案外多いけど、Lambda/SNS/SQSで分かれているからそこまで多くもない。 registry.terraform.io
モジュールmodでoutput.tf書いて mod ├── main.tf ├── output.tf ├── variables.tf └── versions.tf output "instance_ip_addr" { value = aws_instance.server.private_ip description = "The private IP address of the main server instance." } 別モジュ…
APIレファレンスを見る分には、prefixとかも指定できそう registry.terraform.io docs.aws.amazon.com