by shigemk2

当面は技術的なことしか書かない

Terraform

限定公開クラスター

cloud.google.com Terraform的にはこの辺かな registry.terraform.io

google_service_account

サービスアカウント情報を管理。 resourceもdataもあるしdataはresourceを定義しなくても使える。 registry.terraform.io

terraform-google-kubernetes-engine timeouts

timeoutsの設定、masterにはマージされているけど現状最新の21.1.0じゃ設定にないから、内部で設定してあるデフォルト値のようなものが入る。 github.com github.com

google_compute_router_nat vs terraform-google-cloud-nat

addressとかnatとかが既に作成されているならregistryの書き方をなぞった方が早いかも registry.terraform.io github.com

terraform-google-kubernetes-engine timeouts

2022/06/17のmasterブランチにはtimeoutsオプションがありげだったけど2週間前にマージされた機能であるから、まだ21.1.0にはなかった github.com

setup-terraform

この辺がすごい参考になる plan結果をGitHubのプルリクにコメント残したい + 同一のコメントを更新し続ける(commit pushするたびにコメントが増えない)ようにする。 - uses: actions/github-script@v6 if: github.event_name == 'pull_request' env: PLAN: "…

Terraform local name

aws_instance タイプ web ローカルネーム resource "aws_instance" "web" { ami = "ami-a1b2c3d4" instance_type = "t2.micro" } www.terraform.io

Index brackets must contain either a literal number or a literal string.

原理はまるで分からないけど、つまりはそういうことなんだろう # 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…

terraform-google-network

network/subnetwork/routeをまとめて作るterraformのモジュールでGCP開発。 github.com flow log周りとかsecondary ip rangeとか、terraform-google-modulesのソースコードを見たらわかるけどループでぐるぐる回してる このモジュールの設定が、実際のterraf…

Small-size infrastructure with Terraform

1アカウントで小さく始める。 www.terraform-best-practices.com

google_compute_route

ルートのリソース。 A Route resource must have exactly one specification of either nextHopGateway, nextHopInstance, nextHopIp, nextHopVpnTunnel, or nextHopIlb. なんかoptionalな風を見せてるけどnext hopの設定はどれか設定してやらないといけない…

GitHub Actionsでディレクトリを切り替えながらterraformを実行する

Terraformはルートモジュール(work-dir)の直下のHCLファイルの追加変更削除しか対応してくれないので、変更箇所のあるディレクトリをmatrixでまとめて実行してしまおうという。 なのだけれど、変更箇所の検知が git diff --name-only HEAD^ HEAD なので、例…

terraform import

terraform importはstateを更新(実体としてはバックエンドのtfstateファイルを更新)するだけでconfigは生成しないから、HCLファイルの方はterraform showの結果などを手動自前でいい感じに編集する必要がある。 www.terraform.io ちなみにgcloud beta resour…

gcloud beta resource-config bulk-export

形式はTerraformです。 gcloud beta resource-config bulk-exportしてHCLファイルを出力し、gcloud beta resource-config terraform generate-importしてTerraformモジュールとimportスクリプトを出力し、スクリプトを実行してterraform importする。import…

terraformerとtfc

terraformer importしてterraform initするところまでは一緒だけど、providerをreplaceしないといけない。terraformerが最新に合っていないのか、、 あとはprovider.tfにcloudブロックを入れて、terraform init $ terraform state replace-provider registry…

terraformer

Google謹製だから余程のことがない限りはメンテは続くと思う。 類似のterraformingがりどみで紹介されていたけど去年末にメンテ終了してしまった。 github.com 例 terraformer import google --resources=gcs,forwardingRules,httpHealthChecks --connect=tr…

Terraform google_secret_manager_secret

AWSのsecrets managerみたいなものか registry.terraform.io

Terraform google_bigquery_table

リソースを指定するときはデータセットもセットで。 $ terraform import google_bigquery_table.default gcp-project/foo/bar registry.terraform.io

Terraform google_storage_bucket

ポイントはこの辺 $ 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

Terraform 変数メモ

Input Variables Output Values Local Values www.terraform.io

Terraform Cloudでterraform import

キーワードは terraform cloud import とかで検索したっていまいち欲しい情報が得られないっていう バックエンドremote設定をversions.tfなどに書いておいて、terraform loginしてterraform initしてterraform importすれば、stateがTerraform Cloudに上がっ…

terraform import google_compute_instance

書き方。 $ 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.…

Terraform api account memo

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…

Terraform backendメモ

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

terragrunt

brew install terragrunt terragrunt.gruntwork.io

Terraform GCP チュートリアル

やっぱりチュートリアルだね homebrewでtfenvとterraformが両立しない GCPよくわかんないけど、最初のVPC作成でterraform applyしようとしたらcompute.networks.createの権限がないって怒られた。サービスアカウントの権限まわりよくわからないから別途調べ…

Terraform Best Practices

中の人が書いてるから信用性あると思う www.terraform-best-practices.com

resource aws_s3_bucket_notification

パラメータが案外多いけど、Lambda/SNS/SQSで分かれているからそこまで多くもない。 registry.terraform.io

Terraform output参照

モジュール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." } 別モジュ…

ExtendedS3DestinationConfiguration

APIレファレンスを見る分には、prefixとかも指定できそう registry.terraform.io docs.aws.amazon.com