Checking in changes for terraform and ts structure

This commit is contained in:
2022-11-10 09:55:22 -05:00
parent 3fe2507f52
commit 986d8f7a82
11 changed files with 175 additions and 1 deletions

View File

@@ -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',

View File

@@ -0,0 +1,3 @@
# Devops
[Terraform](/terraform/)

View 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)
}
}
```

View 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"
}
```

View 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
View 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.

View 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
View File

@@ -0,0 +1,4 @@
# Types
## Basic Types

1
docs/ts/index.md Normal file
View File

@@ -0,0 +1 @@
# Typescript

9
docs/ts/sidebar.json Normal file
View File

@@ -0,0 +1,9 @@
[
{
"text": "Typescript Basics",
"items": [
{"text": "Introduction", "link": "/ts/"},
{"text": "Types", "link": "/ts/basics/types"}
]
}
]