From af24a4b4faa64023318f26c52a05c72e04ed17d4 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Wed, 27 Sep 2023 18:57:04 +0100 Subject: [PATCH] feat(terraform): add support for terraform repos Add terraform as a project type, make the language optional, and add a .gitignore and justfile template for Terraform repositories. --- src/Action/CreateListOfFilesToGenerate.php | 7 ++++ src/DataTransferObject/Config.php | 3 +- src/Enum/ProjectType.php | 1 + templates/terraform/.gitignore.twig | 45 ++++++++++++++++++++++ templates/terraform/justfile.twig | 25 ++++++++++++ 5 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 templates/terraform/.gitignore.twig create mode 100644 templates/terraform/justfile.twig diff --git a/src/Action/CreateListOfFilesToGenerate.php b/src/Action/CreateListOfFilesToGenerate.php index 3b70591..ae24aac 100644 --- a/src/Action/CreateListOfFilesToGenerate.php +++ b/src/Action/CreateListOfFilesToGenerate.php @@ -115,6 +115,13 @@ final class CreateListOfFilesToGenerate ); } break; + + case (strtolower(ProjectType::Terraform->name)): + $filesToGenerate = collect([ + new TemplateFile(data: 'terraform/.gitignore', name: '.gitignore'), + new TemplateFile(data: 'terraform/justfile', name: 'justfile'), + ]); + break; } $filesToGenerate[] = new TemplateFile( diff --git a/src/DataTransferObject/Config.php b/src/DataTransferObject/Config.php index 95b1f5f..b57d9fb 100644 --- a/src/DataTransferObject/Config.php +++ b/src/DataTransferObject/Config.php @@ -47,14 +47,13 @@ final class Config public array $experimental; #[Assert\Choice(choices: ['javascript', 'php', 'typescript'])] - #[Assert\NotBlank] public string $language; #[Assert\Length(min: 1)] #[Assert\NotBlank] public string $name; - #[Assert\Choice(choices: ['astro', 'drupal', 'fractal', 'laravel', 'php-library', 'vuejs'])] + #[Assert\Choice(choices: ['astro', 'drupal', 'fractal', 'laravel', 'php-library', 'terraform', 'vuejs'])] #[Assert\NotBlank] public string $type; diff --git a/src/Enum/ProjectType.php b/src/Enum/ProjectType.php index 9365ce9..9754a34 100644 --- a/src/Enum/ProjectType.php +++ b/src/Enum/ProjectType.php @@ -9,4 +9,5 @@ enum ProjectType case Astro; case Drupal; case Fractal; + case Terraform; } diff --git a/templates/terraform/.gitignore.twig b/templates/terraform/.gitignore.twig new file mode 100644 index 0000000..c46fa31 --- /dev/null +++ b/templates/terraform/.gitignore.twig @@ -0,0 +1,45 @@ +# {{ managedText }} + +# Created by https://www.toptal.com/developers/gitignore/api/terraform +# Edit at https://www.toptal.com/developers/gitignore?templates=terraform + +### Terraform ### +# Local .terraform directories +**/.terraform/* + +# Plans +terraform.tfplan + +# .tfstate files +*.tfstate +*.tfstate.* + +# Crash log files +crash.log +crash.*.log + +# Exclude all .tfvars files, which are likely to contain sensitive data, such as +# password, private keys, and other secrets. These should not be part of version +# control as they are data points which are potentially sensitive and subject +# to change depending on the environment. +*.tfvars +*.tfvars.json + +# Ignore override files as they are usually used to override resources locally and so +# are not checked in +override.tf +override.tf.json +*_override.tf +*_override.tf.json + +# Include override files you do wish to add to version control using negated pattern +# !example_override.tf + +# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan +# example: *tfplan* + +# Ignore CLI configuration files +.terraformrc +terraform.rc + +# End of https://www.toptal.com/developers/gitignore/api/terraform diff --git a/templates/terraform/justfile.twig b/templates/terraform/justfile.twig new file mode 100644 index 0000000..4781927 --- /dev/null +++ b/templates/terraform/justfile.twig @@ -0,0 +1,25 @@ +# {{ managedText|raw }} + +default: + @just --list + +# Enable or disable Git hooks +git-hooks command: + #!/usr/bin/env bash + set -euo pipefail + + case "{{ '{{ command }}'|raw }}" in + "on") + echo "Enabling Git hooks..." + git config core.hooksPath .githooks + ;; + "off") + echo "Disabling Git hooks..." + git config --unset core.hooksPath + ;; + *) + echo "Error: Invalid argument. Must be either 'on' or 'off'" + ;; + esac + +# vim: ft=just