Skip to content

Commit 7d8bf69

Browse files
authored
Merge pull request #21 from GokuWorks/terraform-guide-gokuworks
Add Terraform Guide
2 parents 6798035 + 93c9a9d commit 7d8bf69

File tree

2 files changed

+149
-0
lines changed

2 files changed

+149
-0
lines changed
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# OpenStack Infrastructure Provisioning with Terraform
2+
3+
## 1. Introduction
4+
5+
This document provides a comprehensive guide for provisioning and managing OpenStack infrastructure using Terraform, an Infrastructure as Code (IaC) tool. It outlines the necessary steps for configuring Terraform, authenticating with OpenStack, and deploying virtual machine instances.
6+
7+
### 1.1 Purpose
8+
9+
This guide serves as a technical reference for the infrastructure team and club members seeking to automate OpenStack resource deployment using Terraform.
10+
11+
### 1.2 Scope
12+
13+
This document covers the following topics:
14+
15+
* Terraform fundamentals
16+
* OpenStack application credential generation
17+
* Terraform project setup and configuration
18+
* Virtual machine instance deployment
19+
20+
## 2. Prerequisites
21+
22+
The following prerequisites must be met prior to proceeding with this guide:
23+
24+
* **OpenStack Cloud Access:** Valid credentials for an OpenStack environment are required.
25+
* **Control Node:** A dedicated system (physical or virtual) with Terraform installed. It is recommended to deploy a virtual machine within the OpenStack environment for this purpose.
26+
* **Terraform Installation:** Terraform CLI must be installed on the Control Node. Refer to the official [Terraform documentation](https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli) for installation instructions.
27+
28+
## 3. OpenStack Application Credentials
29+
30+
Application credentials are required for Terraform to authenticate with OpenStack.
31+
32+
### 3.1 Credential Generation
33+
34+
1. **Access Horizon Dashboard:** Log in to the OpenStack Horizon web interface.
35+
2. **Navigate to Identity:** Proceed to "Identity" > "Application Credentials."
36+
3. **Create Credentials:** Initiate the credential creation process by clicking "Create Application Credential."
37+
4. **Configuration:**
38+
* Provide a descriptive name, optional description, and an expiration date.
39+
* Leave other fields at their default values.
40+
5. **Download `clouds.yaml`:** Download the generated `clouds.yaml` file, which contains the application credentials.
41+
42+
## 4. Terraform Project Setup
43+
44+
### 4.1 Project Directory
45+
46+
Create a dedicated directory for the Terraform project on the Control Node.
47+
48+
```bash
49+
mkdir terraform_project && cd terraform_project
50+
```
51+
### 4.2 Configuration Files
52+
53+
Create the following Terraform configuration files: `main.tf` and `variables.tf`.
54+
```bash
55+
touch main.tf variables.tf
56+
```
57+
### 4.3 `clouds.yaml` Placement
58+
59+
Move the downloaded `clouds.yaml` file into the `terraform_project` directory.
60+
61+
## 5. Terraform Configuration
62+
63+
### 5.1 `variables.tf` Configuration
64+
65+
Define input variables in `variables.tf` to parameterize the infrastructure deployment. Note: replace "key_pair" with the name of your key pair in OpenStack.
66+
```
67+
variable "image_name" {
68+
default = "Ubuntu 24.04"
69+
}
70+
71+
variable "flavor_name" {
72+
default = "m1.small"
73+
}
74+
75+
variable "network_name" {
76+
default = "External Network"
77+
}
78+
79+
variable "key_pair" {
80+
default = "Openstack-Personal"
81+
}
82+
83+
variable "instance_count" {
84+
default = 3
85+
}
86+
```
87+
### 5.2 `main.tf` Configuration
88+
89+
Define the OpenStack provider and virtual machine resources in `main.tf` and replace "Allow-ssh" with your SSH security group.
90+
```
91+
terraform {
92+
required_version = ">= 1.10.0"
93+
required_providers {
94+
openstack = {
95+
source = "terraform-provider-openstack/openstack"
96+
version = "~> 1.53.0"
97+
}
98+
}
99+
}
100+
101+
provider "openstack" {
102+
cloud = "openstack"
103+
}
104+
105+
resource "openstack_compute_instance_v2" "ubuntu_servers" {
106+
count = var.instance_count
107+
name = "ubuntu-vm-${count.index + 1}"
108+
image_name = var.image_name
109+
flavor_name = var.flavor_name
110+
key_pair = var.key_pair
111+
security_groups = ["Allow-ssh"]
112+
113+
network {
114+
name = var.network_name
115+
}
116+
}
117+
```
118+
## 6. Infrastructure Deployment
119+
120+
### 6.1 Terraform Initialization
121+
122+
Initialize the Terraform project to download provider plugins.
123+
```bash
124+
terraform init
125+
```
126+
### 6.2 Configuration Validation
127+
128+
Validate the Terraform configuration.
129+
```bash
130+
terraform validate
131+
```
132+
### 6.3 Execution Plan
133+
134+
Generate an execution plan to preview the changes.
135+
```bash
136+
terraform plan
137+
```
138+
### 6.4 Resource Application
139+
140+
Apply the Terraform configuration to deploy the virtual machine instances.
141+
```bash
142+
terraform apply
143+
```
144+
Confirm the deployment by typing `yes` when prompted.
145+
146+
### 6.5 Verification
147+
148+
Verify the deployment by confirming the creation of the virtual machine instances in the OpenStack Horizon dashboard.

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ nav:
4848
- "Security Groups Guide": "guides/Security Groups.md"
4949
- "How to Launch an Instance": "guides/How to Launch an Instance.md"
5050
- "Migration Guide": "guides/Migrate Instance.md"
51+
- "OpenStack with Terraform": "guides/OpenStack with Terraform.md"
5152
- "Windows Instances": "guides/How to access Windows Instances.md"
5253
- "Troubleshooting": "guides/Troubleshooting.md"
5354
- "Linux Cyberlab Secure": "guides/Linux Cyberlab Secure.md"

0 commit comments

Comments
 (0)