mirror of
https://github.com/Dannecron/netology-devops.git
synced 2025-12-25 23:32:37 +03:00
add homework 7.4
This commit is contained in:
35
src/homework/07-terraform/7.4/terraform/.gitignore
vendored
Normal file
35
src/homework/07-terraform/7.4/terraform/.gitignore
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
# Local .terraform directories
|
||||
**/.terraform/*
|
||||
|
||||
# .tfstate files
|
||||
*.tfstate
|
||||
*.tfstate.*
|
||||
|
||||
# Crash log files
|
||||
crash.log
|
||||
crash.*.log
|
||||
|
||||
# Exclude all .tfvars files, which are likely to contain sentitive data, such as
|
||||
# password, private keys, and other secrets. These should not be part of version
|
||||
# control as they are data points which are potentially sensitive and subject
|
||||
# to change depending on the environment.
|
||||
#
|
||||
*.tfvars
|
||||
|
||||
# Ignore override files as they are usually used to override resources locally and so
|
||||
# are not checked in
|
||||
override.tf
|
||||
override.tf.json
|
||||
*_override.tf
|
||||
*_override.tf.json
|
||||
|
||||
# Include override files you do wish to add to version control using negated pattern
|
||||
#
|
||||
# !example_override.tf
|
||||
|
||||
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
|
||||
# example: *tfplan*
|
||||
|
||||
# Ignore CLI configuration files
|
||||
.terraformrc
|
||||
terraform.rc
|
||||
10
src/homework/07-terraform/7.4/terraform/.terraform.lock.hcl
generated
Normal file
10
src/homework/07-terraform/7.4/terraform/.terraform.lock.hcl
generated
Normal file
@@ -0,0 +1,10 @@
|
||||
# This file is maintained automatically by "terraform init".
|
||||
# Manual edits may be lost in future updates.
|
||||
|
||||
provider "registry.terraform.io/yandex-cloud/yandex" {
|
||||
version = "0.61.0"
|
||||
constraints = "~> 0.61.0"
|
||||
hashes = [
|
||||
"h1:hPOtT0blpx3w2CVdb3DFxBEsuU9cPW9fT1TmajL/ymI=",
|
||||
]
|
||||
}
|
||||
51
src/homework/07-terraform/7.4/terraform/main.tf
Normal file
51
src/homework/07-terraform/7.4/terraform/main.tf
Normal file
@@ -0,0 +1,51 @@
|
||||
module "yc-vpc" {
|
||||
name = terraform.workspace
|
||||
source = "git@github.com:hamnsk/terraform-yandex-vpc.git?ref=v0.5.0"
|
||||
create_folder = false
|
||||
yc_folder_id = var.YC_FOLDER_ID
|
||||
yc_cloud_id = var.YC_CLOUD_ID
|
||||
nat_instance = true
|
||||
subnets = [
|
||||
{
|
||||
zone = var.YC_ZONE
|
||||
v4_cidr_blocks = ["192.168.10.0/24"]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
resource "yandex_compute_instance" "vm-1" {
|
||||
name = "test-vm-1"
|
||||
count = local.vm_count[terraform.workspace]
|
||||
|
||||
resources {
|
||||
cores = 2
|
||||
memory = 2
|
||||
}
|
||||
|
||||
boot_disk {
|
||||
initialize_params {
|
||||
image_id = "fd81hgrcv6lsnkremf32" # ubuntu-20-04-lts-v20210908
|
||||
}
|
||||
}
|
||||
|
||||
network_interface {
|
||||
subnet_id = module.yc-vpc.subnets.0.id
|
||||
nat = true
|
||||
}
|
||||
|
||||
metadata = {
|
||||
ssh-keys = "ubuntu:${file("~/.ssh/id_rsa.pub")}"
|
||||
}
|
||||
}
|
||||
|
||||
output "internal_ip_address_vm_1" {
|
||||
value = [
|
||||
for vm in yandex_compute_instance.vm-1 : vm.network_interface.0.ip_address
|
||||
]
|
||||
}
|
||||
|
||||
output "external_ip_address_vm_1" {
|
||||
value = [
|
||||
for vm in yandex_compute_instance.vm-1 : vm.network_interface.0.nat_ip_address
|
||||
]
|
||||
}
|
||||
15
src/homework/07-terraform/7.4/terraform/provider.tf
Normal file
15
src/homework/07-terraform/7.4/terraform/provider.tf
Normal file
@@ -0,0 +1,15 @@
|
||||
terraform {
|
||||
required_providers {
|
||||
yandex = {
|
||||
source = "yandex-cloud/yandex"
|
||||
}
|
||||
}
|
||||
required_version = ">= 0.13"
|
||||
}
|
||||
|
||||
provider "yandex" {
|
||||
token = "auth_token_here"
|
||||
cloud_id = "cloud_id_here"
|
||||
folder_id = "folder_id_here"
|
||||
zone = "ru-central1-a"
|
||||
}
|
||||
11
src/homework/07-terraform/7.4/terraform/variables.tf
Normal file
11
src/homework/07-terraform/7.4/terraform/variables.tf
Normal file
@@ -0,0 +1,11 @@
|
||||
locals {
|
||||
vm_count = {
|
||||
default = 1
|
||||
stage = 1
|
||||
prod = 2
|
||||
}
|
||||
}
|
||||
|
||||
variable "YC_CLOUD_ID" { default = "" }
|
||||
variable "YC_FOLDER_ID" { default = "" }
|
||||
variable "YC_ZONE" { default = "" }
|
||||
Reference in New Issue
Block a user