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

Terraform cleanups #459

Merged
merged 8 commits into from
Aug 18, 2024
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
5 changes: 4 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
"x86_64-darwin"
"aarch64-darwin"
];
imports = [ ./formatter/default.nix ];
imports = [
./formatter/flake-module.nix
./terraform/flake-module.nix
];
};

}
File renamed without changes.
2 changes: 1 addition & 1 deletion terraform-iam/.envrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use flake
use flake .#terraform

export AWS_CONFIG_FILE=$PWD/aws-config
export AWS_PROFILE=nixos-prod
Expand Down
21 changes: 9 additions & 12 deletions terraform-iam/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# For the bits that are not nixops-able
# User & permission management

This module is for superadmins in the team.

This terraform root module manages:
* IAM roles
* fastly log module
* infrastructure for archeologist team

## Setup

Expand All @@ -15,26 +17,21 @@ Run `aws sso login` to acquire a temporary token.

## Usage

The first time the following command has to be run to initialize the state
file and plugins:

```sh
terraform init
```
We use opentofu, which is a fork of https://www.terraform.io/ maintained by the Linux foundation.

Then run the following command to diff the changes and then apply if approved:

```sh
terraform apply
./tf.sh apply
```

## Terraform workflow

Write the Terraform code and test the changes using `terraform validate`.
Write the Tofu code and test the changes using `./tf.sh validate`.

Before committing run `terraform fmt`.
Before committing run `nix fmt`.

Once the code is ready to be deployed, create a new PR with the attached
output of `terraform plan`.
output of `./tf.sh plan`.

Once the PR is merged, run `terraform apply` to apply the changes.
Once the PR is merged, run `./tf.sh apply` to apply the changes.
26 changes: 0 additions & 26 deletions terraform-iam/flake.lock

This file was deleted.

30 changes: 0 additions & 30 deletions terraform-iam/flake.nix

This file was deleted.

7 changes: 7 additions & 0 deletions terraform-iam/tf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -euo pipefail

cd "$(dirname "$0")"
rm -f .terraform.lock.hcl
tofu init
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this slow down each terraform invocation?

tofu "$@"
2 changes: 1 addition & 1 deletion terraform/.envrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use flake
use flake .#terraform

export AWS_CONFIG_FILE=$PWD/aws-config
export AWS_PROFILE=nixos-prod
Expand Down
80 changes: 0 additions & 80 deletions terraform/.terraform.lock.hcl

This file was deleted.

17 changes: 6 additions & 11 deletions terraform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,21 @@ Run `aws sso login` to acquire a temporary token.

## Usage

The first time the following command has to be run to initialize the state
file and plugins:

```sh
terraform init
```
We use opentofu, which is a fork of https://www.terraform.io/ maintained by the Linux foundation.

Then run the following command to diff the changes and then apply if approved:

```sh
terraform apply
./tf.sh apply
```

## Terraform workflow

Write the Terraform code and test the changes using `terraform validate`.
Write the Tofu code and test the changes using `./tf.sh validate`.

Before committing run `terraform fmt`.
Before committing run `nix fmt`.

Once the code is ready to be deployed, create a new PR with the attached
output of `terraform plan`.
output of `./tf.sh plan`.

Once the PR is merged, run `terraform apply` to apply the changes.
Once the PR is merged, run `./tf.sh apply` to apply the changes.
36 changes: 36 additions & 0 deletions terraform/flake-module.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
let
convert2Tofu =
provider:
provider.override (prev: {
homepage = builtins.replaceStrings [ "registry.terraform.io/providers" ] [
"registry.opentofu.org"
] prev.homepage;
});
in
{
perSystem =
{ pkgs, ... }:
{
devShells.terraform = pkgs.mkShellNoCC {
packages = [
pkgs.awscli2
(pkgs.opentofu.withPlugins (
p:
builtins.map convert2Tofu [
p.aws
p.fastly
p.netlify
p.secret
]
++ [
# FIXME: for our `terraform` target our state file still uses the old registry prefix
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to patch the state after this pull request is merged to not break the existing setup.

p.aws
p.fastly
p.netlify
p.secret
]
))
];
};
};
}
26 changes: 0 additions & 26 deletions terraform/flake.lock

This file was deleted.

30 changes: 0 additions & 30 deletions terraform/flake.nix

This file was deleted.

7 changes: 7 additions & 0 deletions terraform/tf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -euo pipefail

cd "$(dirname "$0")"
rm -f .terraform.lock.hcl
tofu init
tofu "$@"