UNCLASSIFIED

Skip to content
Snippets Groups Projects
Commit dccdc50d authored by kmc-home's avatar kmc-home
Browse files

update terraform

parent 62a42e5f
No related merge requests found
......@@ -67,7 +67,7 @@ terraform destroy
### Provider Configuration
```hcl
```yaml
terraform {
required_providers {
openstack = {
......@@ -80,11 +80,15 @@ terraform {
### Resource Blocks
```hcl
resource "aws_instance" "example" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
```yaml
resource "openstack_compute_instance_v2" "example" {
name = "example-instance"
image_name = "Ubuntu 20.04"
flavor_name = "m1.tiny"
network {
name = "public"
}
tags = {
Name = "example-instance"
}
......@@ -93,7 +97,7 @@ resource "aws_instance" "example" {
### Variables
```hcl
```yaml
# variables.tf
variable "instance_type" {
description = "EC2 instance type"
......@@ -109,7 +113,7 @@ resource "aws_instance" "example" {
### Outputs
```hcl
```yaml
output "instance_ip" {
value = aws_instance.example.public_ip
}
......@@ -117,7 +121,8 @@ output "instance_ip" {
## Working with State
Exercise 5: State management
State management
```sh
terraform show # Display current state
terraform state list # List resources
......@@ -133,7 +138,8 @@ terraform state push # Upload local state
## Terraform Workspaces
Exercise 6: Managing environments
Managing environments
```sh
terraform workspace new dev
terraform workspace new prod
......@@ -141,10 +147,12 @@ terraform workspace select dev
```
## Data Sources
```hcl
data "aws_ami" "ubuntu" {
```yaml
data "openstack_compute_image_v2" "ubuntu" {
most_recent = true
name = "Ubuntu 20.04"
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"]
......@@ -154,14 +162,17 @@ data "aws_ami" "ubuntu" {
## Modules
Exercise 7: Create reusable module
```hcl
Create reusable module
```yaml
# modules/webserver/main.tf
variable "instance_type" {}
resource "aws_instance" "web" {
ami = data.aws_ami.ubuntu.id
instance_type = var.instance_type
resource "openstack_compute_instance_v2" "web" {
image_name = "Ubuntu 20.04"
flavor_name = "m1.tiny"
network {
name = "public"
}
}
# Root main.tf
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment