mv felh assignment
This commit is contained in:
parent
755040ef0e
commit
b25cc69276
Misc./felh
91
Misc./felh/.github/workflows/terraform.yml
vendored
Normal file
91
Misc./felh/.github/workflows/terraform.yml
vendored
Normal file
@ -0,0 +1,91 @@
|
||||
# This workflow installs the latest version of Terraform CLI and configures the Terraform CLI configuration file
|
||||
# with an API token for Terraform Cloud (app.terraform.io). On pull request events, this workflow will run
|
||||
# `terraform init`, `terraform fmt`, and `terraform plan` (speculative plan via Terraform Cloud). On push events
|
||||
# to the "main" branch, `terraform apply` will be executed.
|
||||
#
|
||||
# Documentation for `hashicorp/setup-terraform` is located here: https://github.com/hashicorp/setup-terraform
|
||||
#
|
||||
# To use this workflow, you will need to complete the following setup steps.
|
||||
#
|
||||
# 1. Create a `main.tf` file in the root of this repository with the `remote` backend and one or more resources defined.
|
||||
# Example `main.tf`:
|
||||
# # The configuration for the `remote` backend.
|
||||
# terraform {
|
||||
# backend "remote" {
|
||||
# # The name of your Terraform Cloud organization.
|
||||
# organization = "example-organization"
|
||||
#
|
||||
# # The name of the Terraform Cloud workspace to store Terraform state files in.
|
||||
# workspaces {
|
||||
# name = "example-workspace"
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
#
|
||||
# # An example resource that does nothing.
|
||||
# resource "null_resource" "example" {
|
||||
# triggers = {
|
||||
# value = "A example resource that does nothing!"
|
||||
# }
|
||||
# }
|
||||
#
|
||||
#
|
||||
# 2. Generate a Terraform Cloud user API token and store it as a GitHub secret (e.g. TF_API_TOKEN) on this repository.
|
||||
# Documentation:
|
||||
# - https://www.terraform.io/docs/cloud/users-teams-organizations/api-tokens.html
|
||||
# - https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets
|
||||
#
|
||||
# 3. Reference the GitHub secret in step using the `hashicorp/setup-terraform` GitHub Action.
|
||||
# Example:
|
||||
# - name: Setup Terraform
|
||||
# uses: hashicorp/setup-terraform@v1
|
||||
# with:
|
||||
# cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
|
||||
|
||||
name: 'Terraform'
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "main" ]
|
||||
pull_request:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
terraform:
|
||||
name: 'Terraform'
|
||||
runs-on: ubuntu-latest
|
||||
environment: production
|
||||
|
||||
# Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
|
||||
steps:
|
||||
# Checkout the repository to the GitHub Actions runner
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
# Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token
|
||||
- name: Setup Terraform
|
||||
uses: hashicorp/setup-terraform@v1
|
||||
with:
|
||||
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
|
||||
|
||||
# Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc.
|
||||
- name: Terraform Init
|
||||
run: terraform init
|
||||
|
||||
|
||||
# Generates an execution plan for Terraform
|
||||
- name: Terraform Plan
|
||||
run: terraform plan -input=false
|
||||
|
||||
# On push to "main", build or change infrastructure according to Terraform configuration files
|
||||
# Note: It is recommended to set up a required "strict" status check in your repository for "Terraform Cloud". See the documentation on "strict" required status checks for more information: https://help.github.com/en/github/administering-a-repository/types-of-required-status-checks
|
||||
- name: Terraform Apply
|
||||
#if: github.ref == 'refs/heads/"main"' && github.event_name == 'push'
|
||||
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
|
||||
run: terraform apply -auto-approve -input=false
|
4
Misc./felh/.notgitignore
Normal file
4
Misc./felh/.notgitignore
Normal file
@ -0,0 +1,4 @@
|
||||
modules/files/*.txt
|
||||
terraform.tfstate*
|
||||
.terraform/
|
||||
.terraform.lock.hcl
|
46
Misc./felh/main.tf
Normal file
46
Misc./felh/main.tf
Normal file
@ -0,0 +1,46 @@
|
||||
module "files" {
|
||||
source = "./modules/files"
|
||||
file_count = 5
|
||||
}
|
||||
|
||||
module "read" {
|
||||
source = "./modules/read"
|
||||
input_value = module.files.file_names
|
||||
}
|
||||
|
||||
variable "answer_1" {}
|
||||
variable "answer_2" {}
|
||||
variable "answer_3" {}
|
||||
variable "answer_4" {}
|
||||
variable "answer_5" {}
|
||||
module "write" {
|
||||
source = "./modules/write"
|
||||
answer_1 = var.answer_1
|
||||
answer_2 = var.answer_2
|
||||
answer_3 = var.answer_3
|
||||
answer_4 = var.answer_4
|
||||
answer_5 = var.answer_5
|
||||
}
|
||||
|
||||
|
||||
|
||||
output "read_output" {
|
||||
#value = module.read.processed_input
|
||||
value = module.read.prefixed_outputs
|
||||
}
|
||||
|
||||
output "answers" {
|
||||
value = module.write.all_variables
|
||||
}
|
||||
|
||||
module "data" {
|
||||
source = "./modules/data"
|
||||
depends_on = [module.files]
|
||||
file_count = module.files.file_count
|
||||
path = "${path.root}/modules/files/file1.txt"
|
||||
}
|
||||
|
||||
output "file_id" {
|
||||
description = "The ID of the file"
|
||||
value = module.data.file_id
|
||||
}
|
7
Misc./felh/modules/data/main.tf
Normal file
7
Misc./felh/modules/data/main.tf
Normal file
@ -0,0 +1,7 @@
|
||||
locals {
|
||||
file_number = 1
|
||||
}
|
||||
|
||||
data "local_file" "file_data" {
|
||||
filename = var.path
|
||||
}
|
4
Misc./felh/modules/data/outputs.tf
Normal file
4
Misc./felh/modules/data/outputs.tf
Normal file
@ -0,0 +1,4 @@
|
||||
output "file_id" {
|
||||
description = "The ID of the file"
|
||||
value = data.local_file.file_data.id
|
||||
}
|
8
Misc./felh/modules/data/variables.tf
Normal file
8
Misc./felh/modules/data/variables.tf
Normal file
@ -0,0 +1,8 @@
|
||||
variable "file_count" {
|
||||
description = "The count of generated files"
|
||||
type = number
|
||||
}
|
||||
|
||||
variable "path" {
|
||||
type = string
|
||||
}
|
14
Misc./felh/modules/files/main.tf
Normal file
14
Misc./felh/modules/files/main.tf
Normal file
@ -0,0 +1,14 @@
|
||||
|
||||
resource "null_resource" "generate_files" {
|
||||
count = var.file_count
|
||||
|
||||
triggers = {
|
||||
timestamp = timestamp()
|
||||
}
|
||||
|
||||
provisioner "local-exec" {
|
||||
command = <<-EOT
|
||||
echo "Content of file ${path.module}${count.index}${var.file_extension}" > ${path.module}/${var.file_prefix}${count.index}${var.file_extension}
|
||||
EOT
|
||||
}
|
||||
}
|
8
Misc./felh/modules/files/outputs.tf
Normal file
8
Misc./felh/modules/files/outputs.tf
Normal file
@ -0,0 +1,8 @@
|
||||
output "file_names" {
|
||||
description = "The names of the generated files"
|
||||
value = [for i in range(var.file_count) : "${var.file_prefix}${i}${var.file_extension}"]
|
||||
}
|
||||
|
||||
output "file_count" {
|
||||
value = var.file_count
|
||||
}
|
18
Misc./felh/modules/files/variables.tf
Normal file
18
Misc./felh/modules/files/variables.tf
Normal file
@ -0,0 +1,18 @@
|
||||
|
||||
variable "file_count" {
|
||||
description = "The number of files to be created"
|
||||
type = number
|
||||
default = 1
|
||||
}
|
||||
|
||||
variable "file_prefix" {
|
||||
description = "The prefix for the filenames"
|
||||
type = string
|
||||
default = "file"
|
||||
}
|
||||
|
||||
variable "file_extension" {
|
||||
description = "The extension for the filenames"
|
||||
type = string
|
||||
default = ".txt"
|
||||
}
|
14
Misc./felh/modules/read/outputs.tf
Normal file
14
Misc./felh/modules/read/outputs.tf
Normal file
@ -0,0 +1,14 @@
|
||||
locals {
|
||||
output_prefixes = {
|
||||
for key, value in var.input_value : "prefixed_${key}" => value
|
||||
}
|
||||
}
|
||||
|
||||
output "prefixed_outputs" {
|
||||
value = local.output_prefixes
|
||||
}
|
||||
|
||||
#output "processed_input" {
|
||||
# description = "The input received from the files module with a prefix of 'read-'"
|
||||
# value = "read-${var.input_value}"
|
||||
#}
|
5
Misc./felh/modules/read/variables.tf
Normal file
5
Misc./felh/modules/read/variables.tf
Normal file
@ -0,0 +1,5 @@
|
||||
variable "input_value" {
|
||||
description = "The input value received from the files module"
|
||||
type = list(any)
|
||||
default = []
|
||||
}
|
9
Misc./felh/modules/write/outputs.tf
Normal file
9
Misc./felh/modules/write/outputs.tf
Normal file
@ -0,0 +1,9 @@
|
||||
output "all_variables" {
|
||||
value = {
|
||||
answer_1 = var.answer_1
|
||||
answer_2 = var.answer_2
|
||||
answer_3 = var.answer_3
|
||||
answer_4 = var.answer_4
|
||||
answer_5 = var.answer_5
|
||||
}
|
||||
}
|
5
Misc./felh/modules/write/variables.tf
Normal file
5
Misc./felh/modules/write/variables.tf
Normal file
@ -0,0 +1,5 @@
|
||||
variable "answer_1" {}
|
||||
variable "answer_2" {}
|
||||
variable "answer_3" {}
|
||||
variable "answer_4" {}
|
||||
variable "answer_5" {}
|
5
Misc./felh/terraform.tfvars
Normal file
5
Misc./felh/terraform.tfvars
Normal file
@ -0,0 +1,5 @@
|
||||
answer_1 = "state"
|
||||
answer_2 = "tuple"
|
||||
answer_3 = "while"
|
||||
answer_4 = "using meta-argument"
|
||||
answer_5 = "using -var flag"
|
Loading…
x
Reference in New Issue
Block a user