[A-00141]TerraformでCloud Source Repositoriesを作成する

terraformを使ってGoogle CloudのCloud Source Repositoriesの作成方法をメモ

・アーキテクチャ

・API有効化

ServiceAccountを作成するので下記のURLからAPIを有効化します。

https://console.developers.google.com/apis/api/iam.googleapis.com/overview

Cloud Source RepositoriesのAPIも有効化します。

https://console.developers.google.com/apis/api/sourcerepo.googleapis.com/overview

・Terraform作成/実行

resource "google_service_account" "csr_svc_accnt" {
  account_id = "csr-service-account"
  display_name = "CSR Service Account"
}

resource "google_pubsub_topic" "topic" {
  name = "test-topic"
}

resource "google_sourcerepo_repository" "default" {
  name =  "${var.project_id}-repository"
  pubsub_configs {
    topic = google_pubsub_topic.topic.id
    message_format = "JSON"
    service_account_email = google_service_account.csr_svc_accnt.email
  }
}
variable "project_id" {
  default = "xxxx"
}

下記のコマンドを実行します。

terraform init
terraform plan
terraform apply

実行後、下記のようにリポジトリが作成されます。

下記のコマンドで片付けます。

terraform destroy

・Appendix

公式ドキュメントはこちら

https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sourcerepo_repository.html

参考文献はこちら

https://dev.classmethod.jp/articles/terraform-0-12-new-features/

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

*