Skip to content

Commit c8aaa28

Browse files
Add Vultr terraform
1 parent 1cd1856 commit c8aaa28

File tree

9 files changed

+1805
-0
lines changed

9 files changed

+1805
-0
lines changed

terraform/vultr/.terraform/providers/registry.terraform.io/hashicorp/null/3.2.3/linux_amd64/LICENSE.txt

Lines changed: 375 additions & 0 deletions
Large diffs are not rendered by default.

terraform/vultr/.terraform/providers/registry.terraform.io/vultr/vultr/2.23.1/linux_amd64/CHANGELOG.md

Lines changed: 756 additions & 0 deletions
Large diffs are not rendered by default.

terraform/vultr/.terraform/providers/registry.terraform.io/vultr/vultr/2.23.1/linux_amd64/LICENSE

Lines changed: 373 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
Terraform Provider for Vultr
2+
==================
3+
4+
- Quickstart Guide: [How to Provision a Vultr Cloud Server with Terraform and Cloud-Init](https://www.vultr.com/docs/provision-a-vultr-cloud-server-with-terraform-and-cloud-init/)
5+
- Vultr Website: https://www.vultr.com
6+
- Terraform Website: https://www.terraform.io
7+
8+
<img src="https://raw.githubusercontent.com/hashicorp/terraform-website/master/public/img/logo-hashicorp.svg" width="600px">
9+
10+
Requirements
11+
------------
12+
13+
- [Terraform](https://www.terraform.io/downloads.html) 0.12.x+
14+
- [Go](https://golang.org/doc/install) 1.22.x+ (to build the provider plugin)
15+
16+
Building The Provider
17+
---------------------
18+
19+
Clone repository to: `$GOPATH/src/github.com/vultr/terraform-provider-vultr`
20+
21+
``` sh
22+
$ mkdir -p $GOPATH/src/github.com/vultr; cd $GOPATH/src/github.com/vultr
23+
$ git clone [email protected]:vultr/terraform-provider-vultr.git
24+
```
25+
26+
Enter the provider directory and build the provider
27+
28+
``` sh
29+
$ cd $GOPATH/src/github.com/vultr/terraform-provider-vultr
30+
$ make build
31+
```
32+
33+
Using the provider
34+
----------------------
35+
36+
See the [Vultr Provider documentation](website/docs/index.html.markdown) to get started using the Vultr provider.
37+
38+
Please read about [V2 changes from V1](example/V2Changes.md) for a list of new changes made to the Vultr Terraform Provider
39+
40+
### Installation
41+
In your terraform config, define `vultr/vultr` in your `required_providers` and set your API key:
42+
``` hcl
43+
terraform {
44+
required_providers {
45+
vultr = {
46+
source = "vultr/vultr"
47+
version = "2.22.1"
48+
}
49+
}
50+
}
51+
52+
provider "vultr" {
53+
api_key = "..."
54+
}
55+
```
56+
57+
After, run `terraform init` to install the provider.
58+
59+
#### Manual Installation
60+
If you don't have internet access on the target machine or prefer to install
61+
the provider locally follow the steps for the relevant operating system and architecture.
62+
63+
1) [Download](https://github.com/vultr/terraform-provider-vultr/releases) and
64+
extract the binary for your system and architecture
65+
66+
2) Make the local plugins directory:
67+
68+
On linux
69+
``` sh
70+
export VERSION=2.22.1 OS=linux ARCH=amd64
71+
mkdir -p ~/.terraform.d/plugins/local/vultr/vultr/${VERSION}/${OS}_${ARCH}/'
72+
```
73+
74+
On mac
75+
``` sh
76+
export VERSION=2.22.1 OS=darwin ARCH=arm64
77+
mkdir -p ~/.terraform.d/plugins/local/vultr/vultr/${VERSION}/${OS}_${ARCH}/'
78+
```
79+
80+
3) Rename and copy the binary into the local plugins directory:
81+
``` sh
82+
mv terraform-provider-vultr_v${VERSION} ~/.terraform.d/plugins/local/vultr/vultr/${VERSION}/${OS}_${ARCH}/terraform-provider-vultr_v${VERSION}
83+
```
84+
85+
4) Add the local provider to your terraform `main.tf` config:
86+
``` hcl
87+
terraform {
88+
required_providers {
89+
vultr = {
90+
source = "local/vultr/vultr"
91+
version = "2.22.1"
92+
}
93+
}
94+
}
95+
96+
provider "vultr" {
97+
api_key = "..."
98+
}
99+
```
100+
101+
5) Test everything by running `terraform init` in that same directory.
102+
103+
Developing the Provider
104+
---------------------------
105+
106+
If you wish to work on the provider, you'll first need [Go](http://www.golang.org) installed on your machine (version 1.11+ is *required*). You'll also need to correctly setup a [GOPATH](http://golang.org/doc/code.html#GOPATH), as well as adding `$GOPATH/bin` to your `$PATH`.
107+
108+
To compile the provider, run `make build`. This will build the provider and put the provider binary in the `$GOPATH/bin` directory.
109+
110+
``` sh
111+
$ make build
112+
...
113+
$ $GOPATH/bin/terraform-provider-vultr
114+
...
115+
```
116+
117+
In order to test the provider, you can simply run `make test`.
118+
119+
``` sh
120+
$ make test
121+
```
122+
123+
In order to run the full suite of acceptance tests, run `make testacc`.
124+
125+
*Note:* Acceptance tests create real resources, and often cost money to run.
126+
127+
``` sh
128+
$ make testacc
129+
```
130+
131+
In order to run a specific acceptance test, use the `TESTARGS` environment variable. For example, the following command will run `TestAccVultrUser_base` acceptance test only:
132+
133+
``` sh
134+
$ make testacc TESTARGS='-run=TestAccVultrUser_base'
135+
```

terraform/vultr/main.tf

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#resource "vultr_instance" "enterprise" {
2+
# plan = var.vultr_instance
3+
# region = var.vultr_region
4+
# os_id = 2284
5+
# label = var.resource_group_name_community
6+
#}
7+
8+
resource "vultr_ssh_key" "key" {
9+
name = "vultr-ssh-key"
10+
ssh_key = file(var.publickeypath)
11+
}
12+
13+
resource "vultr_instance" "community" {
14+
plan = var.vultr_instance
15+
region = var.vultr_region
16+
os_id = 2284
17+
label = var.resource_group_name_community
18+
ssh_key_ids = [vultr_ssh_key.key.id]
19+
}
20+
21+
22+
resource "null_resource" "ams-marketplace-setup_community" {
23+
provisioner "remote-exec" {
24+
connection {
25+
type = "ssh"
26+
user = var.user
27+
host = vultr_instance.community.main_ip
28+
private_key = file(var.privatekeypath)
29+
}
30+
inline = [
31+
"sudo sed -i 's/#\\$nrconf{kernelhints} = -1;/\\$nrconf{kernelhints} = -1;/g' /etc/needrestart/needrestart.conf",
32+
"echo 'NEEDRESTART_SUSPEND=1' >> /etc/environment",
33+
"sudo source /etc/environment",
34+
"while sudo fuser /var/lib/dpkg/lock >/dev/null 2>&1; do sleep 1; done",
35+
"while sudo fuser /var/lib/apt/lists/lock >/dev/null 2>&1; do sleep 1; done",
36+
"sudo apt-get update -y",
37+
"sudo apt-get dist-upgrade -y",
38+
"wget https://raw.githubusercontent.com/ant-media/Scripts/master/install_ant-media-server.sh",
39+
"curl -L -o ant-media-server-community.zip https://github.com/ant-media/Ant-Media-Server/releases/download/ams-v${var.ams_version}/ant-media-server-community-${var.ams_version}.zip",
40+
"sudo bash ./install_ant-media-server.sh -i ant-media-server-community.zip",
41+
"sudo sed -i 's/server.marketplace=.*/server.marketplace=azure/g' /usr/local/antmedia/conf/red5.properties",
42+
"sudo systemctl stop antmedia",
43+
"sudo rm -rf /usr/local/antmedia/conf/instanceId",
44+
"sudo rm -rf /usr/local/antmedia/*.db.* && sudo rm -rf /usr/local/antmedia/*.db",
45+
"sudo rm -rf /root/*.zip && sudo rm -rf /root/install*",
46+
"sudo rm -rf /root/.ssh",
47+
"history -c",
48+
"sudo shutdown -h now",
49+
50+
]
51+
}
52+
depends_on = [
53+
vultr_instance.community
54+
]
55+
56+
}
57+
58+
resource "vultr_firewall_group" "my_firewall_grp" {
59+
description = "Firewall"
60+
}
61+
resource "vultr_firewall_rule" "allow_http" {
62+
firewall_group_id = vultr_firewall_group.my_firewall_grp.id
63+
protocol = "tcp"
64+
ip_type = "v4"
65+
subnet = "0.0.0.0"
66+
subnet_size = 0
67+
port = "5080"
68+
}
69+
resource "vultr_firewall_rule" "allow_https" {
70+
firewall_group_id = vultr_firewall_group.my_firewall_grp.id
71+
protocol = "tcp"
72+
ip_type = "v4"
73+
subnet = "0.0.0.0"
74+
subnet_size = 0
75+
port = "5443"
76+
}
77+
resource "vultr_firewall_rule" "allow_ssh" {
78+
firewall_group_id = vultr_firewall_group.my_firewall_grp.id
79+
protocol = "tcp"
80+
ip_type = "v4"
81+
subnet = "0.0.0.0"
82+
subnet_size = 0
83+
port = "22"
84+
}
85+
86+
resource "vultr_snapshot" "snapshot" {
87+
instance_id = resource.vultr_instance.community.id
88+
89+
90+
timeouts {
91+
create = "60m"
92+
}
93+
depends_on = [
94+
null_resource.ams-marketplace-setup_community
95+
]
96+
97+
}
98+
99+
output "ipv4_address" {
100+
value = vultr_instance.community.main_ip
101+
}

terraform/vultr/provider.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
terraform {
2+
required_providers {
3+
vultr = {
4+
source = "vultr/vultr"
5+
version = "2.23.1"
6+
}
7+
}
8+
}
9+
10+
# Configure the Vultr Provider
11+
provider "vultr" {
12+
api_key = var.vultr_token
13+
rate_limit = 100
14+
retry_limit = 3
15+
}

terraform/vultr/variables.tf

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
variable "vultr_token" {
2+
type = string
3+
}
4+
5+
variable "vultr_region" {
6+
type = string
7+
default = "fra"
8+
}
9+
10+
variable "vultr_instance" {
11+
type = string
12+
default = "vc2-2c-4gb"
13+
}
14+
15+
variable "resource_group_name_enterprise" {
16+
default = "enterprise"
17+
description = "Name"
18+
}
19+
20+
21+
variable "resource_group_name_community" {
22+
default = "community"
23+
description = "Name"
24+
}
25+
26+
variable "publickeypath" {
27+
type = string
28+
default = "./ssh/id_rsa.pub"
29+
}
30+
31+
variable "privatekeypath" {
32+
type = string
33+
default = "./ssh/id_rsa"
34+
}
35+
36+
variable "user" {
37+
type = string
38+
default = "root"
39+
40+
}
41+
42+
variable "ams_version" {
43+
type = string
44+
description = "AMS Version"
45+
}
46+
47+
variable "zip_file_id" {
48+
description = "Google drive ID"
49+
type = string
50+
}

0 commit comments

Comments
 (0)