Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Event-Notes/CCDC2024/CCDC-Qualifier-2024/README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Big Empty
No Read ME currently written.
2 changes: 1 addition & 1 deletion Event-Notes/Service-First-15/DNS/Linux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ The only service that this may rely on is the a proxy if we are exposing a DNS s
## First 30
* Audit the DNS Server each machine is configured to use (/etc/resolv.conf, nmtui)
* Can Wazuh do this? What about Zabbix
* Is DNSSec something that is good
* Question(Need to look into): Is DNSSec something that is good?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably want to separate out any cleanup things like this into a separate pull request just to make sure things are more streamlined and clean. Its fine for this one, but something to keep in mind for the future.

I do this type of thing too. I am trying to get better...

## Stretch Goals
Enable DNSSec.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# About
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably want to make the title of the document more descriptive with the following section being an implicit about section for the document.

This a helpfile listing the components used in the creation of a teraform based infrastructure. This uses aws-provider based examples, but are general to any terraform provider. This is organized into 2 groups, components & files.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is different from the name of the document, which includes help-commands where it is more of an broader introduction?

Also Terraform is spelled incorrectly and should be capitalized.


*Of course, this is not every single aspect of terraform, but should be a decent start to creating a full terraform-based infrastructure*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
*Of course, this is not every single aspect of terraform, but should be a decent start to creating a full terraform-based infrastructure*
> [!NOTE]
> This is not every aspect of terraform, but should provide a decent starting point in the creation of a full terraform-based infrastructure



## Components
### Providers:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some sections have the : while others do not. I prefer not using them vs using them.

Providers are like toolboxes for your infrastructure. They define which cloud service or infrastructure you're working with (e.g., AWS, Azure, Google Cloud). If you're building on AWS, for example, you need the AWS provider.
```hcl
provider "aws" {
region = "us-west-2"
}
```
```hcl
provider "<provider-name>" {

}
```
Comment on lines +11 to +19
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is obvious which is which, but I think it would be better to clearly annotate which code block represents a real example vs which is a more general one.

Also I would comment in the body of the provider that additional attributes can be added?


### Resources:
Resources are the actual components you are building, like EC2 instances or S3 buckets.
A resource is like telling the worker to build a single unit in your skyscraper — an EC2 instance in AWS.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure the example here is helping much, I am not thinking of a good replacement.

Maybe something like: "Resources are like drawings on a blueprint, they describe individual components of the overall infrastructure - it is up to you to connect and coordinate those resources to make a coherent blueprint"

```hcl
resource "aws-instance" "example" {
ami = "ami-####" # Specific to AWS EC2 instance
instance_type = "t2.micro" # Specific to AWS EC2 instance
}
```
```hcl
resource "<resource-type>" "<resource-name>" {
<resouce specific key required by aws/provider>
}
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same feedback as previous code blocks

#### keyword vs key
keys are configuration attributes/fields (usually specific to the provider)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example provided is a little unclear.

Keywords are understandable but if keys are "attributes/fields" then are they parts of a resource like

... {
key = value
}

-- Like an attribute or field.

Or the provided example makes it seem like keys are the values we assign attributes of a resource?

.. {
attribute = key
}

keywords are reserved words specific to the programming language (ITC. Terraform)
- resource = keyword
- ami = key
- instance_type = key

### Modules:
Reusable chunks of code.
Sub-blueprint.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would tie this in so it is more structured.

something like

"Modules are reusable chunks of code, they are smaller reusable blueprints... etc"

Instead of writing the same set of instructions over and over again, you create a module that you can reuse across your projects.
If you need multiple identical floors in your skyscraper, a module is a reusable floor plan.

```hcl
module "web_server" {
source = "./modules/web_server"
instance_count = 3 # a custom variable defined within the web_server module
}
```
```hcl
module "web_server" {
source = "<path to find code for a specifc module>"
<you can specifc parameters that relate to the code here>
}
```

### State
Terraform keeps track of the infrastructure using a statefile.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expand on this, what does the statefile do, why should we not modify it. Are there any security considerations with it?


### Output
Outputs are like a report card after the construction is done. They tell you useful things like where the main door is (the public IP of the instance), so you know where to go or connect to after your infrastructure is built.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we want to use outputs, are there times where we would not want to use them or could they be dangerous?

```yaml
output "instance_ip" {
value = aws_instance.example.public_ip
}

```


### Data
data keyword like a scout who goes out to gather information about things that already exist. **You’re not creating anything new**; you’re just finding what’s already there (like discovering where roads or pipelines already exist before you build).
```yaml
data "aws_vpc" "default" {
default = true
}
```


# Files & Directories
Note: All the entire terraform component can be written in 1 main.tf file. Convention is to split up these components into logical component files.
## main.tf
- used to declare resources

## variables.tf
- a file to hold resuables variable names that you may use through out the terraform creation


## modules
A higher level Directory used to section off, organize and/or seperate often general components, for example, subnets, & a vpc files/details.
156 changes: 156 additions & 0 deletions OperatingSystem-Services/Platform-Linux/3-Terraform/help/workflow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
# Table of Contents <!-- omit from toc -->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably move about up here and change the name to be a document title with implicit about section

- [About](#about)
- [Workflow](#workflow)
- [Install Terraform on linux](#install-terraform-on-linux)
- [Configure the Terraform provider](#configure-the-terraform-provider)
- [Write configuration files](#write-configuration-files)
- [Initialize Terraform](#initialize-terraform)
- [Run terraform plan](#run-terraform-plan)
- [Create resources with terraform apply](#create-resources-with-terraform-apply)
- [Delete resources using terraform destroy](#delete-resources-using-terraform-destroy)
- [Notes:](#notes)

# About
This file describes the general flow I use for starting and creating a aws-based teraform infrastructure

Author: Chisom Ukaegbu

# Workflow
## Install Terraform on linux
1. Install Terraform (ubuntu debian ver.)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe link to the docs too?


- ` wget -O - https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings hashicorp-archive-keyring.gpg`

- `echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list`

- `sudo apt update && sudo apt install terraform `



## Configure the Terraform provider
For our example we will focus on using aws as the cloud provider aka the place where out machines will be created & hosted
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalize AWS


AWS will be our cloud provider and set up an account on aws cloud provider

0. You will need AWS Access KEY ID & AWS Secret Key ID
This is gathered from the aws web console. Create a user or use a preexisting user.

![aws-create-user.png](/images/aws-create-user.png)


Grab there access and secret key ids.

![alt text](/imageS/aws-secret-key.png)

1. Run `Aws Configure` in your terminal.
Input your keys
```sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably want to tab-in this code block

blueteam@cyber-range tf-tuts % aws configure
AWS Access Key ID [****************PYVK]: ****PYVK
AWS Secret Access Key [****************duMt]: ****duMt
Default region name [eu-central-1]: <same region where you want to place the machines>
Default output format [None]:
blueteam@cyber-range tf-tuts %
```

## Write configuration files
1. Setup Cloud Provider

Convention says to place this config in a file name provider.tf. It does not matter aslong as the file has the .tf extension and is unique in name.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Convention says to place this config in a file name provider.tf. It does not matter aslong as the file has the .tf extension and is unique in name.
Convention says to place this config in a file name provider.tf. It does not matter as long as the file has the .tf extension and is unique in name.


```yaml
terraform {
    required_providers {
        aws = {
            source = hashicorp/aws
            version = " ~> 4.19.0"
    }
}
    }
```
2. Create instances

Create a main.tf file. Convention is to name the file "main.tf"

This is where the block of the cofiguration for the virtual machines will be deployed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This is where the block of the cofiguration for the virtual machines will be deployed
This is where the block of the configuration for the virtual machines will be deployed


```yaml
# creating the code to create an EC2 instance in AWS using Terraform.
resource "aws_instance" "my_vm" {

 ami                       = "ami-065deacbcaac64cf2" //Ubuntu AMI
 instance_type             = "t2.micro"

 tags = {
   Name = "My EC2 instance",
 }

###########
# declared a resource block of type “aws_instance”.
### This instructs Terraform that we want to create an EC2 instance resource in AWS with the given attributes

# second parameter is “`my_vm`”, an internal identifier that refers to this ##particular EC2 instance elsewhere in the code. We can assign any name to this identifier


# assigned a `tag` “Name” with the value “My EC2 Instance”.
```

## Initialize Terraform
1. Intialize terraform
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
1. Intialize terraform
1. Initialize terraform


Run this command in your terminal of the same directory your provider is.
```sh
terraform init
```
You should see these hidden files. when running
```sh
ls -l
. .. .terraform .terraform.lock.hcl provider.tf
```

2. Format the code
This command will auto fixed syntax and indentation of your configuration code
```sh
terraform fmt
```


## Run terraform plan
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section is tabbed in too much making it into a code block

This command will output 2 scenarios
output: identify and highlight resources that will be created, updated, or deleted if we choose to execute the current version of the code

or

Show issues regarding your terraform file

```sh
terraform plan`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an extra `?

```
![t-fmt-1](</images/t-fmt-1.png>)
![t-fmt-2](</images/t-fmt-2.png>)
## Create resources with terraform apply
Running the command `terraform apply` will begin to create
```sh
terraform apply
```
Now if you navigate to aws, you will see the instances created.
Make sure you are in the same region as the provider you selected.
## Delete resources using terraform destroy
```sh
terraform destory
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think destroy is spelled wrong

```
Will delete any resources provisioned by your terraform script.
Virtual machines, vpcs, subnets etc are considered resources
# Notes:
There is more you can do with terraform but this is a quick start guide for creating an instance or network for the first time.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading