Skip to content

Commit 1cc6df4

Browse files
committed
Remove using static service account key
1 parent 4b8ce50 commit 1cc6df4

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

.github/workflows/deploy.yml

-4
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ jobs:
3030
tofu_version: 1.8.2
3131
- uses: arduino/setup-task@v2
3232
- uses: nightstory/setup-yc@v1
33-
- run: |
34-
jq -r '.' > ./deploy/terraform/sa_key.json << EOF
35-
${{ secrets.SA_KEY }}
36-
EOF
3733
- run: |
3834
../scripts/tofu-opensource.sh --tofurc --cleanup --init --target data.shell_script.kubeconfig --apply --approve
3935
ls -la ./kubeconfig.conf && sleep 10

deploy/scripts/tofu-opensource.sh

+5-3
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ if [ "$CI" == "true" ]; then
112112
PROFILE_NAME="${SERVICE}-${SUFFIX}-$(date +%s)"
113113
fi
114114

115-
if [ -z "${SA_FILE}" ]; then
115+
if [ -z "${SA_FILE}" ] && [ "$CI" != "true" ]; then
116116
SA_FILE="$(pwd)/sa_key.json"
117117
fi
118118

@@ -137,13 +137,15 @@ trap 'yc-cleanup' EXIT
137137

138138
if [ ! "${YC_PROFILE_EXISTS}" == "true" ]; then
139139
echo "💡 yc profile [${PROFILE_NAME}] does not exists, creating..."
140-
if [ -f "${SA_FILE}" ]; then
140+
if [ -f "${SA_FILE}" ] || [ "$CI" == "true" ]; then
141141
yc config profile create "${PROFILE_NAME}" &>/dev/null || exit 1
142142

143143
yc config set cloud-id ${CLOUD_ID} &>/dev/null || exit 1
144144
yc config set folder-id ${FOLDER_ID} &>/dev/null || exit 1
145145
yc config set endpoint "${API_ENDPOINT}:443" &>/dev/null || exit 1
146-
yc config set service-account-key "${SA_FILE}" &>/dev/null || exit 1
146+
if [ ! -z "${SA_FILE}" ]; then
147+
yc config set service-account-key "${SA_FILE}" &>/dev/null || exit 1
148+
fi
147149
else
148150
echo "❌ service account file '${SA_FILE}' does not exists, configure profile '${PROFILE_NAME}' manually at 'yc' cli or provider sa account file, exit..."
149151
fi

deploy/terraform/github-runner.tf

+16
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@ data "yandex_lockbox_secret_version" "github-runner" {
2020
secret_id = yandex_lockbox_secret.github-runner["main"].id
2121
}
2222

23+
resource "yandex_iam_service_account" "github-runner" {
24+
for_each = toset(local.is_create_github_runner ? ["main"] : [])
25+
26+
name = "${local.service}-gh-runner-sa"
27+
}
28+
29+
resource "yandex_resourcemanager_folder_iam_member" "github-runner" {
30+
for_each = toset(local.is_create_github_runner ? ["main"] : [])
31+
32+
folder_id = local.folder_id
33+
role = "admin"
34+
member = "serviceAccount:${yandex_iam_service_account.github-runner["main"].id}"
35+
}
36+
2337
data "yandex_compute_image" "this" {
2438
family = "ubuntu-24-04-lts"
2539
}
@@ -41,6 +55,8 @@ resource "yandex_compute_instance" "github-runner" {
4155
platform_id = "standard-v3"
4256
zone = local.zones[each.value % length(local.zones)]
4357

58+
service_account_id = yandex_iam_service_account.github-runner["main"].id
59+
4460
resources {
4561
cores = 2
4662
memory = 4

0 commit comments

Comments
 (0)