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

Add module #1

Merged
merged 35 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
82cd964
initial commit with the module
Phil-Thoennissen Jul 22, 2024
784ae81
docs updated
Phil-Thoennissen Jul 22, 2024
58baf21
docs updated
Phil-Thoennissen Jul 22, 2024
9d29ddd
required_providers updated
Phil-Thoennissen Jul 22, 2024
2d9900d
example updated
Phil-Thoennissen Jul 22, 2024
c3dd69a
Add note to readme
rswrz Jul 25, 2024
9054220
Add and run pre-commit
rswrz Jul 25, 2024
3348db1
add module
Phil-Thoennissen Sep 3, 2024
ba06af6
add module
Phil-Thoennissen Sep 3, 2024
0ca44f7
add module
Phil-Thoennissen Sep 3, 2024
7eb4705
adjusted docu
Phil-Thoennissen Sep 3, 2024
71a0481
remote test added
Phil-Thoennissen Sep 3, 2024
0f1c916
added pre-commit, new tagging method, adjusted tests and exmaple
Phil-Thoennissen Sep 3, 2024
235f891
updated due to upstream updates
Phil-Thoennissen Sep 17, 2024
7d81d66
one tab was missing
Phil-Thoennissen Sep 17, 2024
7862112
adding mssing output descriptions + adding all locations as short name
Phil-Thoennissen Sep 17, 2024
87da618
PullRequest Discussions Resolved
Phil-Thoennissen Sep 20, 2024
452b391
PullRequest Discussions Resolved
Phil-Thoennissen Sep 20, 2024
93eeaf9
PullRequest Discussions Resolved
Phil-Thoennissen Sep 24, 2024
be23f9a
set provider versions in test to lowest supported version
Phil-Thoennissen Sep 24, 2024
f1ee695
revert as the new change is not in Github-action@main
Phil-Thoennissen Sep 24, 2024
614e962
changing grace_period to "PT10M" as the default value is invalid
Phil-Thoennissen Sep 24, 2024
963afba
Remove "prevent_deletion" add Azure lock instead
Phil-Thoennissen Sep 24, 2024
7f8dc97
set providers to lowest version we support
Phil-Thoennissen Oct 1, 2024
545ed2b
set Terraform to a specific version in remote test
Phil-Thoennissen Oct 1, 2024
6bf135f
Apply suggestions from code review
Phil-Thoennissen Oct 8, 2024
0a03213
Review feedback applied
Phil-Thoennissen Oct 15, 2024
3cbc6f3
Apply suggestions from code review
Phil-Thoennissen Oct 15, 2024
1663852
Review feedback applied
Phil-Thoennissen Oct 15, 2024
2601073
Review feedback applied
Phil-Thoennissen Oct 15, 2024
a0b5cae
unable to delete secret as the role assignment is already deleted
Phil-Thoennissen Oct 17, 2024
521e7f8
Suggestions are applied
Phil-Thoennissen Nov 12, 2024
b56afbc
Suggestions are applied
Phil-Thoennissen Nov 12, 2024
4c429f9
Suggestions are applied
Phil-Thoennissen Nov 12, 2024
1097ad3
remove INSTALL.md
Phil-Thoennissen Nov 12, 2024
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
9 changes: 1 addition & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@
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
Expand All @@ -25,7 +18,7 @@ override.tf.json
*_override.tf.json

# Include override files you do wish to add to version control using negated pattern
# !example_override.tf
!tests_override.tf

# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*
Expand Down
33 changes: 33 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/terraform-docs/terraform-docs
rev: v0.18.0
hooks:
- id: terraform-docs-system
args: ["."]
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: "v1.92.0"
hooks:
- id: terraform_fmt
- id: terraform_tflint
exclude: ^examples/
args:
- --args=--config=__GIT_WORKING_DIR__/.tflint.hcl
- --hook-config=--delegate-chdir
- id: terraform_tflint
alias: terraform_tflint_examples
name: Terraform validate examples with tflint
files: ^examples/
args:
- --args=--config=__GIT_WORKING_DIR__/.tflint.examples.hcl
- --hook-config=--delegate-chdir
- id: terraform_trivy
exclude: ^(examples|tests)/
args:
- --args=--skip-dirs="examples/"
- --args=--skip-dirs="tests/"
6 changes: 4 additions & 2 deletions .terraform-docs.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
formatter: markdown
formatter: markdown document

settings:
anchor: false
hide-empty: true
lockfile: false

output:
Expand All @@ -14,6 +14,8 @@ sort:
content: |-
## Usage

{{ include "examples/usage/main.md" }}

```hcl
{{ include "examples/usage/main.tf" }}
```
Expand Down
21 changes: 21 additions & 0 deletions .tflint.examples.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
tflint {
required_version = "~> 0.50"
}

plugin "azurerm" {
enabled = true
version = "0.27.0"
source = "github.com/terraform-linters/tflint-ruleset-azurerm"
}

rule "terraform_required_version" {
enabled = false
}

rule "terraform_required_providers" {
enabled = false
}

rule "terraform_module_version" {
enabled = false
}
9 changes: 9 additions & 0 deletions .tflint.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
tflint {
required_version = "~> 0.50"
}

plugin "azurerm" {
enabled = true
version = "0.27.0"
source = "github.com/terraform-linters/tflint-ruleset-azurerm"
}
36 changes: 0 additions & 36 deletions CHANGELOG.md
rswrz marked this conversation as resolved.
Show resolved Hide resolved

This file was deleted.

2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Contribution

Find our contribution guide at [terraform-governance/docs/Module - CONTRIBUTING](https://github.com/cloudeteer/terraform-governance/blob/main/docs/Module%20-%20CONTRIBUTING.md)
Find our contribution guide at [terraform-governance/docs/Module - CONTRIBUTING](https://github.com/cloudeteer/terraform-governance/blob/main/docs/Module%20-%20CONTRIBUTING.md)
117 changes: 117 additions & 0 deletions INSTALL.md
Phil-Thoennissen marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
## Pre Requirements

- Access to a Azure subscription of the customer with `Owner` permissions (service principal or human user)
- Successfully authenticated with `az` CLI
- GitHub team [service-accounts](https://github.com/orgs/cloudeteer/teams/service-accounts) must be `admin` of the squad repo
- [Firewall approvals](./docs/firewall-approvals.md)

## Install CDT IaC Launchpad

> [!NOTE]
> Do the following steps first, then you can use this module with only a few variables as we show in our [example](https://github.com/cloudeteer/terraform-azurerm-launchpad/blob/main/examples/usage/main.tf).

### 1. Create GitHub Personal Access Token (PAT)

The Launchpad Virtual Machine needs permission to register GitHub runners in the squad repository. To be able to do this automatically, a GitHub Personal Access Token (PAT) is required.

Login as GitHub user [cloudeteerbot](https://keepersecurity.eu/vault/#detail/4y33tgsK_Yuv8mJUXDUPrQ) and create a organization-owned GitHub PAT with the following configuration:
Phil-Thoennissen marked this conversation as resolved.
Show resolved Hide resolved

> [!IMPORTANT]
> The resource owner must be the Cloudeteer organization, and it cannot be changed after the PAT is created.

| Property | Value |
|-------------------|---------------------------------------------------------------------|
| Token name | `squad<...>/launchpad` (replace `<...>` with the actual squad name) |
| Expiration | Custom: 1 year |
| Description | `Used to generate GitHub Runner access tokens` |
| Resource owner: | `cloudeteer` – The organization |
| Repository access | "Only selected repositories" – Select the Squad repository |
| Permissions | Repository permissions: Actions: `read`, Administration: `write` |

<details>
<summary>Screenshot: GitHub PAT Settings</summary>

![Screenshot: GitHub PAT Settings](images/github-pat-settings.png)
</details>

Save the PAT in Keeper as custom field in the Keeper item [GitHub cloudeteerbot](https://keepersecurity.eu/vault/#detail/4y33tgsK_Yuv8mJUXDUPrQ).

For the initial Launchpad installation set the GitHub PAT and squad repository as `TF_VAR_` environment variables.

```shell
export TF_VAR_runner_github_pat=github_pat_<...>
export TF_VAR_runner_github_repo=cloudeteer/squad-<...>
```

Finally, set the GitHub secret `CDT_IAC_LAUNCHPAD_RUNNER_GITHUB_PAT` in the squad repository that contains this PAT:

```shell
gh secret set CDT_IAC_LAUNCHPAD_RUNNER_GITHUB_PAT --repo "$TF_VAR_runner_github_repo"
```

### 2. Initial deployment

Make the following code adjustments:

- CAN BE DELETED--> Set the `subscription_id` in `main.tf` file.
- CAN BE DELETED--> Set the `ARM_TENANT_ID` in `terraform-iac-launchpad.yaml`
- CAN BE DELETED--> Set the `tenant_id` in the `main.tf` file.

Then deploy initially:

```sh
# This IP address will be utilized for the initial network rules for the storage account and key vault.
export TF_VAR_init_access_ip_address=$(curl -s https://ipinfo.io/ip)

terraform init
terraform apply -var 'init=true' -var 'runner_public_ip_address=true'
```

Add the module output `ARM_CLIENT_ID` as GitHub secret to your repository:

```shell
gh secret set CDT_IAC_LAUNCHPAD_AZURE_CLIENT_ID --repo "$TF_VAR_runner_github_repo"
```

### 3. Configure Terraform Backend

Update the following Terraform backend parameters in the `main.tf` file:

- Set the `stroage_account_name` to the value of the Terraform output `tfstate_storage_account_name`
- Uncomment the entire `backend.azurerm` block to enable Azure backend configuration.

To complete this step commit your changes and push them to remote.

### 4. Migrate Terraform State File

Run:

```sh
terraform init -migrate-state
```

### 5. Remove Local State

Finally, delete the local state file:

```sh
rm terraform.tfstate terraform.tfstate.backup
```

### 6. Final Terraform Apply

After successfully registering the GitHub Action runner, proceed to apply the Terraform code for the last time locally without passing the `init=true`

> [!CAUTION]
> Ensure the specified managed identity has the necessary permissions. Recommended: Assign the `Owner` role at a management group level.

> [!CAUTION]
> Running Terraform locally will no longer be possible after this step.

Run the following command locally:

```sh
terraform apply -var 'runner_public_ip_address=true'
```

Omit the `-var 'runner_public_ip_address=true'` if the virtual network has internet access through an HUB without a dedicated public IP address.
Loading