Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init(opentofu): test PR ci #1

Merged
merged 1 commit into from
Oct 20, 2023
Merged
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
40 changes: 40 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Tests

on:
push:
branches:
- main
paths:
- '**.rs'
- '**.toml'
- '.github/workflows/tests.yml'
tags:
- '*'
pull_request:
branches:
- main

permissions: {}

env:
CARGO_TERM_COLOR: always

jobs:
tfexe:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
#os: [ubuntu-latest, macos-latest]
project: [project1, project2, project4]
tfexe: [terraform, tofu, tfswitch]
steps:
- uses: actions/checkout@v3
- uses: hashicorp/setup-terraform@v2.0.3
- uses: opentofu/setup-opentofu@v1.0.0
- if: ${{ matrix.tfexe == 'tfswitch' }}
run: curl -L https://raw.githubusercontent.com/warrensbox/terraform-switcher/release/install.sh | sudo bash
- run: cargo run -- init
working-directory: ./test_dir/${{ matrix.project }}/
env:
TFEXE: ${{ matrix.tfexe }}
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 19 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
use std::env;
use std::io::Result;
use std::process::{exit, Child, Command, ExitStatus};
use std::process::{Command, ExitStatus};

fn main() -> Result<()> {
let args: Vec<String> = env::args().skip(1).collect();

let mut tfswitch: Child = Command::new("tfswitch").spawn()?;
let tfswitch_exit_status: ExitStatus = tfswitch.wait()?;
if !tfswitch_exit_status.success() {
exit(tfswitch_exit_status.code().unwrap_or(1));
fn exec(val: &str, args: Vec<String>) -> Result<ExitStatus, std::io::Error> {
let mut cmd = Command::new(val);
for arg in args {
cmd.arg(arg);
}
cmd.spawn()?.wait()
}

fn main() -> Result<(), std::io::Error> {
let args: Vec<String> = env::args().skip(1).collect();
let tfexe: String = env::var("TFEXE").unwrap_or_else(|_| "tfswitch".to_string());

let mut terraform: Child = Command::new("terraform").args(args).spawn()?;
let terraform_exit_status: ExitStatus = terraform.wait()?;
if !terraform_exit_status.success() {
exit(terraform_exit_status.code().unwrap_or(1));
match tfexe.as_str() {
"tfswitch" => {
let _ = exec("tfswitch", Vec::new())?;
exec("terraform", args)?;
}
_ => {
exec(&tfexe, args)?;
}
}

Ok(())
Expand Down
Empty file.
Empty file.
Empty file.
Empty file added test_dir/project1/aws/aws.tf
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file added test_dir/project1/gcp/gcp.tf
Empty file.
Empty file.
Empty file.
Empty file.
15 changes: 15 additions & 0 deletions test_dir/project1/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
terraform {
required_version = "<=0.15.0"
}

module "gcp" {
source = "./gcp"
}

module "azure" {
source = "./azure"
}

module "aws" {
source = "./aws"
}
Empty file added test_dir/project1/outputs.tf
Empty file.
Empty file added test_dir/project1/variables.tf
Empty file.
Empty file added test_dir/project2/dev/main.tf
Empty file.
3 changes: 3 additions & 0 deletions test_dir/project2/dev/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "vpc_id" {
value = "dev module here"
}
1 change: 1 addition & 0 deletions test_dir/project2/dev/region_a/service_one.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
environment = "dev"
1 change: 1 addition & 0 deletions test_dir/project2/dev/region_a/service_three.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
environment = "dev"
1 change: 1 addition & 0 deletions test_dir/project2/dev/region_a/service_two.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
environment = "dev"
1 change: 1 addition & 0 deletions test_dir/project2/dev/region_b/service_one.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
environment = "dev"
1 change: 1 addition & 0 deletions test_dir/project2/dev/region_b/service_three.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
environment = "dev"
1 change: 1 addition & 0 deletions test_dir/project2/dev/region_b/service_two.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
environment = "dev"
18 changes: 18 additions & 0 deletions test_dir/project2/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
terraform {
required_version = "~> 1.3"
}

module "conditionally_used_dev_module" {
source = "./dev"
count = var.environment == "dev" ? 1 : 0
}

module "conditionally_used_staging_module" {
source = "./staging"
count = var.environment == "staging" ? 1 : 0
}

module "conditionally_used_production_module" {
source = "./production"
count = var.environment == "production" ? 1 : 0
}
3 changes: 3 additions & 0 deletions test_dir/project2/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "module_used" {
value = concat(module.conditionally_used_dev_module[*].vpc_id, module.conditionally_used_production_module[*].vpc_id, module.conditionally_used_staging_module[*].vpc_id)
}
Empty file.
3 changes: 3 additions & 0 deletions test_dir/project2/production/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "vpc_id" {
value = "production module here"
}
1 change: 1 addition & 0 deletions test_dir/project2/production/region_a/service_one.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
environment = "production"
1 change: 1 addition & 0 deletions test_dir/project2/production/region_a/service_three.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
environment = "production"
1 change: 1 addition & 0 deletions test_dir/project2/production/region_a/service_two.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
environment = "production"
1 change: 1 addition & 0 deletions test_dir/project2/production/region_b/service_one.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
environment = "production"
1 change: 1 addition & 0 deletions test_dir/project2/production/region_b/service_three.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
environment = "production"
1 change: 1 addition & 0 deletions test_dir/project2/production/region_b/service_two.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
environment = "production"
Empty file.
3 changes: 3 additions & 0 deletions test_dir/project2/staging/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "vpc_id" {
value = "staging module here"
}
1 change: 1 addition & 0 deletions test_dir/project2/staging/region_a/service_one.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
environment = "staging"
1 change: 1 addition & 0 deletions test_dir/project2/staging/region_a/service_three.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
environment = "staging"
1 change: 1 addition & 0 deletions test_dir/project2/staging/region_a/service_two.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
environment = "staging"
1 change: 1 addition & 0 deletions test_dir/project2/staging/region_b/service_one.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
environment = "staging"
1 change: 1 addition & 0 deletions test_dir/project2/staging/region_b/service_three.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
environment = "staging"
1 change: 1 addition & 0 deletions test_dir/project2/staging/region_b/service_two.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
environment = "staging"
3 changes: 3 additions & 0 deletions test_dir/project2/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
variable "environment" {
type = string
}
1 change: 1 addition & 0 deletions test_dir/project3/applications/backend-app/env/dev.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
clouds = ["aws", "azure", "gcp"]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
clouds = ["aws", "gcp"]
1 change: 1 addition & 0 deletions test_dir/project3/applications/backend-app/env/qa.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
clouds = ["aws", "azure", "gcp"]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
clouds = ["aws", "azure", "gcp"]
3 changes: 3 additions & 0 deletions test_dir/project3/applications/backend-app/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
terraform {
required_version = "~> 1.2"
}
Empty file.
Empty file.
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions test_dir/project3/applications/frontend-app/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
terraform {
required_version = "1.4.1"
}
Empty file.
3 changes: 3 additions & 0 deletions test_dir/project3/modules/network/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
terraform {
required_version = "1.2.3"
}
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions test_dir/project3/modules/spaces/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
terraform {
required_version = "~> 0.15"
}
Empty file.
Empty file.
4 changes: 4 additions & 0 deletions test_dir/project4/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
terraform {
required_version = "~>1.6"
}

3 changes: 3 additions & 0 deletions test_dir/project4/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "environment" {
value = var.environment
}
4 changes: 4 additions & 0 deletions test_dir/project4/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "environment" {
type = string
description = "Environment to deploy to."
}
4 changes: 4 additions & 0 deletions test_dir/project4/vars/asia-east1/app-one/dev.tfvars.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"environment": "dev"
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"environment": "production"
}

4 changes: 4 additions & 0 deletions test_dir/project4/vars/asia-east1/app-one/staging.tfvars.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"environment": "staging"
}

4 changes: 4 additions & 0 deletions test_dir/project4/vars/asia-east1/app-two/dev.tfvars.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"environment": "dev"
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"environment": "production"
}

4 changes: 4 additions & 0 deletions test_dir/project4/vars/asia-east1/app-two/staging.tfvars.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"environment": "staging"
}

4 changes: 4 additions & 0 deletions test_dir/project4/vars/us-east1/app-one/dev.tfvars.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"environment": "dev"
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"environment": "production"
}

3 changes: 3 additions & 0 deletions test_dir/project4/vars/us-east1/app-one/staging.tfvars.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"environment": "staging"
}
Loading