Skip to content

Commit ecdac66

Browse files
committed
add CI/CD
1 parent 5a57bcb commit ecdac66

File tree

5 files changed

+101
-19
lines changed

5 files changed

+101
-19
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Terraform Validate
2+
3+
on:
4+
push:
5+
paths:
6+
- 'terraform/**'
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
validate:
13+
name: Init and Validate
14+
runs-on: ubuntu-latest
15+
env:
16+
TF_IN_AUTOMATION: "true"
17+
TF_INPUT: "false"
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
22+
- name: Setup Terraform
23+
uses: hashicorp/setup-terraform@v3
24+
with:
25+
terraform_version: 1.13.1
26+
27+
- name: Terraform Init
28+
working-directory: terraform
29+
run: terraform init
30+
31+
- name: Terraform Validate
32+
working-directory: terraform
33+
run: terraform validate
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Terraform via Webhook
2+
3+
on:
4+
repository_dispatch:
5+
6+
permissions:
7+
contents: read
8+
9+
jobs:
10+
terraform:
11+
name: Run Terraform
12+
runs-on: ubuntu-latest
13+
env:
14+
TF_IN_AUTOMATION: "true"
15+
TF_INPUT: "false"
16+
TF_VAR_iam_token: ${{ secrets.YC_IAM_TOKEN }}
17+
TF_VAR_cloud_id: ${{ secrets.YC_CLOUD_ID }}
18+
TF_VAR_folder_id: ${{ secrets.YC_FOLDER_ID }}
19+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
20+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
25+
- name: Setup Terraform
26+
uses: hashicorp/setup-terraform@v3
27+
with:
28+
terraform_version: 1.13.1
29+
30+
- name: Terraform Init
31+
run: terraform init
32+
33+
- name: Terraform Plan
34+
run: terraform plan -var="preemptible=true" -out=tfplan
35+
36+
- name: Terraform Apply
37+
run: terraform apply -auto-approve tfplan

main.tf renamed to terraform/main.tf

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,19 @@ terraform {
55
}
66
}
77
required_version = ">= 0.13"
8-
}
9-
10-
variable "cloud_id" {
11-
type = string
12-
nullable = false
13-
}
14-
15-
variable "folder_id" {
16-
type = string
17-
nullable = false
18-
}
198

20-
variable "iam_token" {
21-
type = string
22-
nullable = false
23-
}
9+
backend "s3" {
10+
endpoints = {
11+
s3 = "https://storage.yandexcloud.net"
12+
}
13+
bucket = "tf-states-bucket"
14+
region = "ru-central1"
15+
key = "ru-proxy/terraform.tfstate"
2416

25-
variable "preemptible" {
26-
type = bool
27-
default = false
28-
description = "reduces the price twice but instance may stop suddenly"
17+
skip_region_validation = true
18+
skip_credentials_validation = true
19+
skip_requesting_account_id = true
20+
}
2921
}
3022

3123
provider "yandex" {
File renamed without changes.

terraform/variables.tf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
variable "cloud_id" {
2+
type = string
3+
nullable = false
4+
}
5+
6+
variable "folder_id" {
7+
type = string
8+
nullable = false
9+
}
10+
11+
variable "iam_token" {
12+
type = string
13+
nullable = false
14+
}
15+
16+
variable "preemptible" {
17+
type = bool
18+
default = false
19+
description = "reduces the price twice but instance may stop suddenly"
20+
}

0 commit comments

Comments
 (0)