Skip to content

Commit

Permalink
Merge pull request #459 from NixOS/terraform-iam-cleanups
Browse files Browse the repository at this point in the history
Terraform cleanups
  • Loading branch information
Mic92 authored Aug 18, 2024
2 parents 6748675 + cd9350e commit 33acac7
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 218 deletions.
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
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
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 "$@"

0 comments on commit 33acac7

Please sign in to comment.