Skip to content

Commit

Permalink
Add OpenTofu example
Browse files Browse the repository at this point in the history
  • Loading branch information
batonogov committed Apr 15, 2024
1 parent bda99ee commit 630307f
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 4 deletions.
41 changes: 41 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Created by https://www.toptal.com/developers/gitignore/api/terraform
# Edit at https://www.toptal.com/developers/gitignore?templates=terraform

### Terraform ###
# Local .terraform directories
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*

# Crash log files
crash.log
crash.*.log

# Exclude all .tfvars files, which are likely to contain sensitive 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
*.tfvars.json

# 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

# End of https://www.toptal.com/developers/gitignore/api/terraform

4 changes: 0 additions & 4 deletions opentofu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,3 @@ export TF_VAR_instance_zone=ru-central-d
```bash
export TF_VAR_instance_zone='["ru-central-a","ru-central-b"]'
```

```bash
tofu apply
```
25 changes: 25 additions & 0 deletions opentofu/test_vm/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions opentofu/test_vm/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output "ip_address_vm_01" {
description = "IP адрес vm-01"
value = proxmox_virtual_environment_vm.vm-01.ipv4_addresses[1]
}
17 changes: 17 additions & 0 deletions opentofu/test_vm/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
terraform {
required_providers {
proxmox = {
source = "bpg/proxmox"
version = ">= 0.53.1"
}
}
}

provider "proxmox" {
endpoint = var.virtual_environment_endpoint
api_token = var.virtual_environment_api_token
insecure = true
ssh {
agent = false
}
}
2 changes: 2 additions & 0 deletions opentofu/test_vm/terraform.tfvars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
virtual_environment_api_token = "root@pam!for-terraform-provider=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
virtual_environment_endpoint = "https://x.x.x.x:8006/"
9 changes: 9 additions & 0 deletions opentofu/test_vm/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
variable "virtual_environment_endpoint" {
type = string
description = "The endpoint for the Proxmox Virtual Environment API (example: https://host:port)"
}

variable "virtual_environment_api_token" {
type = string
description = "The api roken the Proxmox Virtual Environment API (example: root@pam!for-terraform-provider=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)"
}
66 changes: 66 additions & 0 deletions opentofu/test_vm/vm-01.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Машинка
resource "proxmox_virtual_environment_vm" "vm-01" {
name = "vm-01"
description = "Managed by OpenTofu"
tags = ["opentofu", "test"]
on_boot = true

# Указываем целевой узел, на котором будет запущена ВМ
node_name = "pve-01"

# Шоблон из которого будет создавать ВМ
clone {
vm_id = "9000"
node_name = "pve-01"
retries = 2
}

# Активируем QEMU для этов ВМ
agent {
enabled = true
}

operating_system {
type = "l26"
}

cpu {
cores = 4
type = "host"
numa = true
}

memory {
dedicated = 4096
}

disk {
size = "40"
interface = "virtio0"
datastore_id = "proxmox-data-02"
file_format = "raw"
}

network_device {
bridge = "vmbr0"
model = "virtio"
}

initialization {
datastore_id = "proxmox-data-02"
ip_config {
ipv4 {
address = "dhcp"
}
}
dns {
servers = ["77.88.8.8"]
}
user_account {
username = "infra"
keys = [
"ssh-rsa..."
]
}
}
}

0 comments on commit 630307f

Please sign in to comment.