mirror of
https://gitlab.com/djdietrick/docs
synced 2026-05-03 00:20:54 -04:00
Checking in changes for terraform and ts structure
This commit is contained in:
@@ -9,6 +9,8 @@ export default {
|
||||
'/python/': require('../python/sidebar.json'),
|
||||
'/rust/': require('../rust/sidebar.json'),
|
||||
'/nuxt/': require('../nuxt/sidebar.json'),
|
||||
'/ts/': require('../ts/sidebar.json'),
|
||||
'/terraform': require('../terraform/sidebar.json'),
|
||||
'/': [
|
||||
{
|
||||
text: 'Home',
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
# Devops
|
||||
|
||||
[Terraform](/terraform/)
|
||||
39
docs/terraform/basics/provisioner.md
Normal file
39
docs/terraform/basics/provisioner.md
Normal file
@@ -0,0 +1,39 @@
|
||||
# Provisioning
|
||||
|
||||
After we define our providers and resources to establish our environment, we use provisioners to deploy and execute code in that environment. You can deploy things like scripts and then use `remote-exec` to execute them. This is accomplished via SSH, and you can override the connection details as well.
|
||||
|
||||
```hcl
|
||||
resource "aws_key_pair" "mykey" {
|
||||
key_name = "mykey"
|
||||
public_key = file(var.PATH_TO_PUBLIC_KEY)
|
||||
}
|
||||
|
||||
resource "aws_instance" "example1" {
|
||||
ami = ${lookup(var.AMIS, var.AWS_REGION)}
|
||||
instance_type = "t2.micro"
|
||||
key_name = aws_key_pair.mykey.key_name
|
||||
|
||||
provisioner "file" {
|
||||
source = "deploy.sh"
|
||||
destination = "/etc/deploy.sh"
|
||||
}
|
||||
provisioner "remote-exec" {
|
||||
inline = [
|
||||
"chmod +x /tmp/script.sh",
|
||||
"sudo sed -i -e 's/\r$//' /tmp/script.sh", # Remove the spurious CR characters.
|
||||
"sudo /tmp/script.sh",
|
||||
]
|
||||
}
|
||||
connection {
|
||||
user = var.instance_user
|
||||
password = var.instance_password
|
||||
}
|
||||
# or use keys
|
||||
connection {
|
||||
host = coalesce(self.public_ip, self.private_ip)
|
||||
type = "ssh"
|
||||
user = var.instance_user
|
||||
private_key = file(var.PATH_TO_PRIVATE_KEY)
|
||||
}
|
||||
}
|
||||
```
|
||||
29
docs/terraform/basics/resources.md
Normal file
29
docs/terraform/basics/resources.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# Resources
|
||||
|
||||
Resources should be defined in `instance.tf`. Before creating a resource you must first create a provider in `provider.tf`. A provider is an entity such as AWS, GCP, DigitalOcean, etc. Once you specify a provider, run `terraform init` to download that provider's module. Within these providers are services which we can use via resources.
|
||||
|
||||
```hcl
|
||||
# provider.tf
|
||||
provider "aws" {
|
||||
# version = xxx
|
||||
}
|
||||
|
||||
# vars.tf
|
||||
variable "AWS_REGION" {
|
||||
type = "string"
|
||||
}
|
||||
|
||||
variable "AMIS" {
|
||||
type = map
|
||||
default = {
|
||||
us-central-1: "my ami"
|
||||
}
|
||||
}
|
||||
|
||||
# instance.tf
|
||||
resource "aws_instance" "example1" {
|
||||
ami = ${lookup(var.AMIS, var.AWS_REGION)}
|
||||
instance_type = "t2.micro"
|
||||
}
|
||||
|
||||
```
|
||||
68
docs/terraform/basics/variables.md
Normal file
68
docs/terraform/basics/variables.md
Normal file
@@ -0,0 +1,68 @@
|
||||
# Variables
|
||||
|
||||
Variables should be defined in `vars.tf`.
|
||||
|
||||
```hcl
|
||||
variable "myvar" {
|
||||
type = "string"
|
||||
default ="hello terraform"
|
||||
}
|
||||
|
||||
variable "mymap" {
|
||||
type = map(string)
|
||||
default = {
|
||||
mykey = "myvalue"
|
||||
mykey2 = "myvalue2"
|
||||
}
|
||||
}
|
||||
|
||||
variable "mylist" {
|
||||
type = list
|
||||
default = [1,2,3]
|
||||
}
|
||||
```
|
||||
```shell
|
||||
$ var.myvar
|
||||
hello terraform
|
||||
$ ${var.myvar}
|
||||
hello terraform
|
||||
$ var.mymap["mykey"]
|
||||
myvalue
|
||||
$ var.mylist[0]
|
||||
1
|
||||
$ slice(var.mylist, 0, 2)
|
||||
[
|
||||
1,
|
||||
2
|
||||
]
|
||||
```
|
||||
|
||||
You can also define variables in `terraform.tfvars` files. Generally you do not want to check this in to version control.
|
||||
|
||||
```hcl
|
||||
# In template.tfvars
|
||||
AWS_REGION="us-central-1"
|
||||
|
||||
# In vars.tf
|
||||
variable "AWS_REGION" {
|
||||
type = "string"
|
||||
}
|
||||
```
|
||||
|
||||
## Outputs
|
||||
|
||||
```hcl
|
||||
resource "aws_instance" "example" {
|
||||
ami = lookup(var.AMIS, var.AWS_REGION)
|
||||
instance_type = "t2.micro"
|
||||
|
||||
# can also be used in scripts
|
||||
provisioner "local-exec" {
|
||||
command = "echo ${aws_instance.example.private_ip} >> private_ips.txt"
|
||||
}
|
||||
}
|
||||
|
||||
output "ip" {
|
||||
value = aws_instance.example.public_ip
|
||||
}
|
||||
```
|
||||
8
docs/terraform/index.md
Normal file
8
docs/terraform/index.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# Terraform
|
||||
|
||||
Terraform is a software that allows you to define your infrastructure as code. You can automate your deployment, keep track of the state of your environments, and have an audit of all versions that have been deployed to an environment.
|
||||
|
||||
## Installation
|
||||
|
||||
Installation can be done from the [terraform website](terraform.io), where you can download the binary and add it to your path. If on mac, this can be done with brew.
|
||||
|
||||
11
docs/terraform/sidebar.json
Normal file
11
docs/terraform/sidebar.json
Normal file
@@ -0,0 +1,11 @@
|
||||
[
|
||||
{
|
||||
"text": "Terraform Basics",
|
||||
"items": [
|
||||
{"text": "Introduction", "link": "/terraform/"},
|
||||
{"text": "Variables", "link": "/terraform/basics/variables"},
|
||||
{"text": "Resources", "link": "/terraform/basics/resources"},
|
||||
{"text": "Provisioning", "link": "/terraform/basics/provisioner"}
|
||||
]
|
||||
}
|
||||
]
|
||||
4
docs/ts/basics/types.md
Normal file
4
docs/ts/basics/types.md
Normal file
@@ -0,0 +1,4 @@
|
||||
# Types
|
||||
|
||||
## Basic Types
|
||||
|
||||
1
docs/ts/index.md
Normal file
1
docs/ts/index.md
Normal file
@@ -0,0 +1 @@
|
||||
# Typescript
|
||||
9
docs/ts/sidebar.json
Normal file
9
docs/ts/sidebar.json
Normal file
@@ -0,0 +1,9 @@
|
||||
[
|
||||
{
|
||||
"text": "Typescript Basics",
|
||||
"items": [
|
||||
{"text": "Introduction", "link": "/ts/"},
|
||||
{"text": "Types", "link": "/ts/basics/types"}
|
||||
]
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user