Skip to content

Commit

Permalink
Added Cloudflare resources (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
spietras authored Feb 25, 2024
1 parent cbd0c15 commit d4eefcd
Show file tree
Hide file tree
Showing 21 changed files with 977 additions and 13 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/apply.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
name: main
env:
NIX_CACHE_DIR: /home/runner/.nixcache/
TERRAFORM_BACKEND_CONFIG: /home/runner/config.s3.tfbackend
TERRAFORM_CACHE_DIR: /home/runner/.terraformcache/
permissions:
# Needed to checkout code
Expand Down Expand Up @@ -73,6 +74,32 @@ jobs:
nix-store
--import
< ${{ env.NIX_CACHE_DIR }}/archive.nar
- name: Create backend configuration
run: |
cat <<EOF > ${{ env.TERRAFORM_BACKEND_CONFIG }}
access_key = "${{ secrets.TERRAFORM_BACKEND_ACCESS_KEY }}"
endpoints = {
s3 = "${{ secrets.TERRAFORM_BACKEND_ENDPOINT }}"
}
secret_key = "${{ secrets.TERRAFORM_BACKEND_SECRET_KEY }}"
EOF
- name: Initialize
env:
SOPS_AGE_KEY: ${{ secrets.SOPS_AGE_KEY }}
TF_PLUGIN_CACHE_DIR: ${{ env.TERRAFORM_CACHE_DIR }}
# yamllint disable rule:line-length
run: >
nix
develop
./#terraform
--command
--
task
init
--
-input=false
-backend-config=${{ env.TERRAFORM_BACKEND_CONFIG }}
# yamllint enable rule:line-length
- name: Apply
env:
SOPS_AGE_KEY: ${{ secrets.SOPS_AGE_KEY }}
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/plan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
name: main
env:
NIX_CACHE_DIR: /home/runner/.nixcache/
TERRAFORM_BACKEND_CONFIG: /home/runner/config.s3.tfbackend
TERRAFORM_CACHE_DIR: /home/runner/.terraformcache/
permissions:
# Needed to checkout code
Expand Down Expand Up @@ -67,6 +68,32 @@ jobs:
nix-store
--import
< ${{ env.NIX_CACHE_DIR }}/archive.nar
- name: Create backend configuration
run: |
cat <<EOF > ${{ env.TERRAFORM_BACKEND_CONFIG }}
access_key = "${{ secrets.TERRAFORM_BACKEND_ACCESS_KEY }}"
endpoints = {
s3 = "${{ secrets.TERRAFORM_BACKEND_ENDPOINT }}"
}
secret_key = "${{ secrets.TERRAFORM_BACKEND_SECRET_KEY }}"
EOF
- name: Initialize
env:
SOPS_AGE_KEY: ${{ secrets.SOPS_AGE_KEY }}
TF_PLUGIN_CACHE_DIR: ${{ env.TERRAFORM_CACHE_DIR }}
# yamllint disable rule:line-length
run: >
nix
develop
./#terraform
--command
--
task
init
--
-input=false
-backend-config=${{ env.TERRAFORM_BACKEND_CONFIG }}
# yamllint enable rule:line-length
- name: Plan
env:
SOPS_AGE_KEY: ${{ secrets.SOPS_AGE_KEY }}
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@
# Terraform state
*.tfstate
*.tfstate.*

# Terraform backend configuration
*.tfbackend
9 changes: 8 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
{}
{
"[terraform]": {
"editor.tabSize": 2
},
"[terraform-vars]": {
"editor.tabSize": 2
}
}
12 changes: 0 additions & 12 deletions Taskfile.dist.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,21 +137,10 @@ tasks:
-chdir=src/
init
{{ .CLI_ARGS }}
init-internal:
desc: Initialize Terraform quietly
internal: true
env:
TF_IN_AUTOMATION: "true"
cmds:
- task: init
vars:
CLI_ARGS: >
-input=false
plan:
desc: Create an execution plan
interactive: true
cmds:
- task: init-internal
- >
terraform
-chdir=src/
Expand All @@ -161,7 +150,6 @@ tasks:
desc: Apply changes
interactive: true
cmds:
- task: init-internal
- >
terraform
-chdir=src/
Expand Down
40 changes: 40 additions & 0 deletions src/.terraform.lock.hcl

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

22 changes: 22 additions & 0 deletions src/cloudflare/accounts.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Add main account
resource "cloudflare_account" "main" {
# Name of the account
name = local.account.name
}

# Add me as a member to the account
resource "cloudflare_account_member" "spietras" {
# Identifier of the account to add the member to
account_id = cloudflare_account.main.id

# Email address of the member
email_address = local.account.members.spietras.email

# Role IDs to assign to the member
role_ids = [
local.roles["Super Administrator - All Privileges"],
]

# Member is accepted
status = "accepted"
}
4 changes: 4 additions & 0 deletions src/cloudflare/data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Data source with account roles
data "cloudflare_account_roles" "account_roles" {
account_id = cloudflare_account.main.id
}
Loading

0 comments on commit d4eefcd

Please sign in to comment.