Closed3
Github provider触る
terraformの下記providerを触ってみる
githubはこれ
認証方法は下記3パターンある。
- Github CLI
- PAT
- Github apps
https://registry.terraform.io/providers/integrations/github/latest/docs#authentication
Github CLIとGithub appsで認証してみる
- Github CLI
gh auth loginコマンドでghを使用できるように設定するだけ。providerには下記のように何も記載する必要がなかった
terraform {
required_providers {
github = {
source = "integrations/github"
version = "~> 6.0"
}
}
}
# Configure the GitHub Provider
provider "github" {}
- Github apps
https://registry.terraform.io/providers/integrations/github/latest/docs#github-app-installation
Github appsを作成後、対象のレポジトリにinstall + Private keyの発行を行う。
providerには下記のように記載する。(pem_fileの値はgit管理はせずに対応した方がいいが一旦検証のために直接値を指定した)
terraform {
required_providers {
github = {
source = "integrations/github"
version = "~> 6.0"
}
}
}
# Configure the GitHub Provider
provider "github" {
owner = "harayu-k"
app_auth {
id = app_id
installation_id = installation_id
pem_file = <<-EOT
secret content
EOT
}
}
試しにGHAで使用するVariablesを作成してみた。
data "github_repository" "terraform-github-provider" {
full_name = "harayu-k/terraform-github-provider"
}
resource "github_actions_variable" "test_variable" {
repository = data.github_repository.terraform-github-provider.name
variable_name = "TEST"
value = "test"
}
apply時に403が出てリソース作成できない時はGithub appsのpermissionや許可しているリポジトリなどをみる必要あり。
このスクラップは2025/03/01にクローズされました