-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from liquidweb/examples
adding examples
- Loading branch information
Showing
35 changed files
with
1,588 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
devkey | ||
devkey.pub | ||
**/devkey | ||
**/devkey.pub | ||
terraform.tfvars | ||
*.log | ||
.terraform/ | ||
**/.terraform/ | ||
vendor/ | ||
.lwapi.toml | ||
terraform-provider-liquidweb | ||
terraform.tfstate* | ||
*.tfvars | ||
*.tfvars.json | ||
go/ | ||
.cache/ | ||
dist/ | ||
.ash_history | ||
.terraform.lock.hcl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# Terraform Examples | ||
|
||
This repository contains terraform examples that are slated for inclusion in the terraform repository elsewhere, but not yet ready. | ||
|
||
## What is Terraform? | ||
|
||
Terraform is a tool targeted at a Infrastructure as Code approach to managing asset inventory. | ||
It offers a declarative language to create configurations describing infrastructure. | ||
Given the configurations, you can rapidly create, remove, and recreate infrastructure. | ||
Since the configuraitons are plaintext, it allows easy versioning of the infrastructure state with Version Control Software. | ||
|
||
### Background Terms | ||
|
||
That's a loaded paragraph, some terminology: | ||
|
||
- Version Control Software (vcs) - like `git`, a tool that lets you track files over time and compare differences | ||
- Of note, most developers put their source code in VCS. This has many benefits. | ||
- Infrastructure as Code (IaC) - managing servers via config files, often which you can commit to a repository | ||
- Declarative Syntax / Language - describing what an system should be | ||
- Asset Inventory - what assets you have. VPS's are an asset, but SSL certificates, LB's, and Block Storage are also assets. | ||
- configuration files end in `.tf` and determine what is needed | ||
- State - the current way a system is, the actual live snapshot of it, not the way it hsould be | ||
- Lockfile - a file tracking what things terraform currently has | ||
|
||
### Terraform Basic Commands | ||
|
||
The focus of Terraform is create, recreate, and destroying what is needed. | ||
Terraform can be used alone, and assets recreated as your schema changes. | ||
But most of the time, multiple IaC tools are used to better describe a system. | ||
|
||
The major background pieces it will create are: | ||
|
||
- the lock file resides at `./.terraform.lock.hcl` | ||
- the state file resides at `./terraform.tfstate` | ||
- a backup state file at `./terraform.tfstate.backup` | ||
- providers typically reside in `./terraform.d` | ||
|
||
If you have something deployed, you want to save the | ||
|
||
The major commands that terraform provides are: | ||
|
||
- `init` - download required providers and set up state and lockfile | ||
- `validate` - make sure configs are valid | ||
- `plan` - show changes to modify state to match configs | ||
- `apply` - run `plan`, then prompt to make those changes | ||
- `destroy` show changes to remove everything, prompt, then remove everything | ||
- `show` - display the current assets | ||
- `taint` - mark an asset currently deployed, on next `apply` will be recreated | ||
- `refresh` - update the state of assets (not supported with LiquidWeb's provider) | ||
- `import` - add existing assets into current state (not supported with LiquidWeb's provider) | ||
|
||
### Installing and Examples | ||
|
||
The [Hashicorp official instructions for installing terraform](https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli) are well written. | ||
You are likely best off going there. | ||
Do note, you will likely have a better time if you use the package install for your OS. | ||
In other words, on macOS use `homebrew`, on Windows use `choco`, on Linux use your package manager. | ||
|
||
The LiquidWeb provider does not require special installation. | ||
If it is used in your configs, it should be automatically installed with `terraform init`. | ||
|
||
[Documentation for that provider is published on the provider page](https://registry.terraform.io/providers/liquidweb/liquidweb/latest/docs). | ||
|
||
You will need to provide credentials to a LiquidWeb account in order to use the LiquidWeb provider. | ||
These credentials should be in the following environment variables: | ||
|
||
```env | ||
LWAPI_USERNAME="username" | ||
LWAPI_PASSWORD="password" | ||
``` | ||
|
||
There is also an `acme` SSL provider. | ||
If your domain is hosted with LiquidWeb, you can use this to get an SSL. | ||
[The documentation gives a basic example](https://registry.terraform.io/providers/vancluever/acme/latest/docs/guides/dns-providers-liquidweb). | ||
If you wish to get an SSL with the `acme` provider with a DNS server, you must provide the following credentials: | ||
|
||
```env | ||
LIQUID_WEB_USERNAME="username" | ||
LIQUID_WEB_PASSWORD="password" | ||
``` | ||
|
||
For examples, please look at: | ||
|
||
- [Basic server example](./basic-example/) | ||
- [Basic wordpress example](./simple-wordpress/) | ||
- [Wordpress Cluster example](./scalable-wordpress/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
examples/loadbalancer.tf → examples/basic-example/loadbalancer.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
terraform { | ||
required_providers { | ||
liquidweb = { | ||
source = "local.providers/liquidweb/liquidweb" | ||
version = "~> 1.6.2" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Basic Example | ||
|
||
This most basic Terraform example in this folder does not target a specific use case, instead it just creates resources. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
terraform { | ||
required_providers { | ||
liquidweb = { | ||
source = "liquidweb/liquidweb" | ||
version = ">= 1.7.0" | ||
} | ||
acme = { | ||
source = "vancluever/acme" | ||
version = "2.17.1" | ||
} | ||
} | ||
} | ||
|
||
resource "random_id" "server" { | ||
byte_length = 1 | ||
# count = 1 | ||
} | ||
|
||
resource "random_password" "server" { | ||
length = 20 | ||
special = false | ||
} | ||
|
||
resource "random_password" "wordpress_dbpass" { | ||
length = 20 | ||
special = true | ||
} | ||
|
||
resource "random_password" "wordpress_salt" { | ||
length = 32 | ||
special = true | ||
} | ||
|
||
data "liquidweb_network_zone" "zonec" { | ||
name = "Zone C" | ||
region_name = "US Central" | ||
} | ||
|
||
data "template_file" "install-wordpress" { | ||
template = file("${path.module}/templates/install-wordpress.sh") | ||
vars = { | ||
user = var.username | ||
} | ||
} | ||
|
||
data "template_file" "wp-config" { | ||
template = file("${path.module}/templates/wp-config.php") | ||
vars = { | ||
dbname = var.wordpress_dbname | ||
dbuser = var.wordpress_dbuser | ||
dbpass = random_password.wordpress_dbpass.result | ||
salt = random_password.wordpress_salt.result | ||
dbhost = liquidweb_cloud_server.dbserver.ip | ||
} | ||
} | ||
|
||
data "template_file" "site-conf" { | ||
template = file("${path.module}/templates/nginx.conf") | ||
vars = { | ||
domain = var.site_name | ||
user = var.username | ||
} | ||
} | ||
|
||
data "template_file" "php-conf" { | ||
template = file("${path.module}/templates/php-fpm.conf") | ||
vars = { | ||
user = var.username | ||
} | ||
} | ||
|
||
resource "liquidweb_network_dns_record" "webserver_dns" { | ||
count = 3 | ||
name = liquidweb_cloud_server.webserver[count.index].domain | ||
type = "A" | ||
rdata = liquidweb_cloud_server.webserver[count.index].ip | ||
zone = var.top_domain | ||
} | ||
|
||
resource "liquidweb_network_dns_record" "wordpress_record" { | ||
name = var.site_name | ||
type = "A" | ||
rdata = liquidweb_network_load_balancer.loadbalancer.vip | ||
zone = var.top_domain | ||
} | ||
|
||
output "domain_a_name" { | ||
value = liquidweb_network_dns_record.wordpress_record.name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
resource "liquidweb_cloud_server" "dbserver" { | ||
#config_id = "${data.liquidweb_storm_server_config.api.id}" | ||
config_id = 1757 | ||
zone = data.liquidweb_network_zone.zonec.network_zone_id | ||
#data.liquidweb_network_zone.api.id | ||
template = "ROCKYLINUX_8_UNMANAGED" | ||
domain = "wordpress-db01-p${random_id.server.dec}.us-midwest-2.${var.top_domain}" | ||
public_ssh_key = file("${path.root}/default.pub") | ||
password = random_password.server.result | ||
|
||
connection { | ||
type = "ssh" | ||
user = "root" | ||
agent = true | ||
host = self.ip | ||
} | ||
|
||
provisioner "remote-exec" { | ||
inline = [ | ||
"yum install -y epel-release", | ||
"yum install -y http://rpms.remirepo.net/enterprise/remi-release-8.rpm", | ||
"yum install -y wget curl mysql mysql-common mysql-server" | ||
] | ||
} | ||
|
||
provisioner "remote-exec" { | ||
inline = [ | ||
"systemctl start mysqld.service", | ||
"systemctl enable mysqld.service", | ||
"firewall-cmd --zone public --permanent --add-port 3306/tcp", | ||
"firewall-cmd --reload" | ||
] | ||
} | ||
} | ||
|
||
output "dbserver_hostnames" { | ||
value = liquidweb_cloud_server.dbserver.ip | ||
} | ||
|
||
output "dbserver_ips" { | ||
value = liquidweb_cloud_server.dbserver.ip | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDWMKoQLgiAhw3ZZrCd7pZfQ/Wqj+ct6jvV/+MzOJ2BLgoUd9ijnOImf/HWUwuWDol8vQP5sf5Q7mMURut2uFm7bLcZMVnZ7wWSUhS8qptdJY/Hixc3S65xP/DCRjKuE1YWbZXVZYPzLt7JERY3jADo7C0XjOzn5jY509RAU77EIm/idKT0Q0S382OjP8avNNfoevZ2h8A5EiRlcypCTsn8VJk6NFIk+NnqxWsxuCHCbt7+91hPvIhPFxW8f0y4TujIZyUc/8OqKqqBb7e3/eBEBfrCcDRVAho3vD7kLt42xdKy0BtpK58Dds3iToPjfho342qflaAoniXpeAkh0nX2PBJXN6t698bfJ+TVr5xChZ3J7FJw/G7D6KI01hdr43ACTILpDb1gpWHgZMTt7/G2PE3T6hPZeZDYVce5HHkn8B1ptZtRr3vbKZLsPLTm5lEK3GayOWxuUpBRvYaqQNOHw7lOlGTlYJGlCfbfuI2bFQxPBLhaA/KlTiPT5MIGganJyD82gIf4Yw4UckpV57AP7KAP64D9++a5fmpVQ4lBWE7DP+GoXUz8yw9YMygBbniEbkM6dXf6RB8G+8GxHohfZ/lFgWUEyrrL9vrFi5eELTCpoPu5COzXwMg61cXKfsGD8/n3Eh8XSMTFeJQJdRmPQCBs8SormvT6j5JhGUOVyw== cardno:9_021_958 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
resource "liquidweb_network_load_balancer" "loadbalancer" { | ||
# depends_on = [data.liquidweb_network_zone.testing_zone] | ||
name = "wordpress-loadbalancer1-p${random_id.server.dec}${var.top_domain}" | ||
|
||
region = data.liquidweb_network_zone.zonec.region_id | ||
|
||
nodes = liquidweb_cloud_server.webserver[*].ip | ||
|
||
service { | ||
src_port = 80 | ||
dest_port = 80 | ||
} | ||
|
||
service { | ||
src_port = 443 | ||
dest_port = 443 | ||
} | ||
|
||
#session_persistence = false | ||
#ssl_termination = false | ||
strategy = "roundrobin" | ||
} | ||
|
||
output "lb_vip" { | ||
value = liquidweb_network_load_balancer.loadbalancer.vip | ||
} |
Oops, something went wrong.