Skip to content

Commit 6ba495e

Browse files
authored
Update production workflow and backend configuration for OpenTofu migration (#30)
1 parent 20c5d93 commit 6ba495e

File tree

4 files changed

+68
-6
lines changed

4 files changed

+68
-6
lines changed

.github/workflows/production.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ permissions:
1818
jobs:
1919
main:
2020
name: "Main"
21-
uses: osinfra-io/github-opentofu-gcp-called-workflows/.github/workflows/plan-and-apply.yml@367d86eecaab18bb7fae7f5fa17fe7001df13f16
21+
uses: osinfra-io/github-opentofu-gcp-called-workflows/.github/workflows/plan-and-apply.yml@e3c59e43f2458550c7f13b6369fb6978b6f42c6e # v0.2.9
2222
if: github.actor != 'osinfra-sa'
2323
with:
2424
checkout_ref: ${{ github.ref }}
2525
github_environment: "Production: Main"
2626
service_account: plt-dd-organization-github@plt-lz-backend-tf5f-prod.iam.gserviceaccount.com
27+
opentofu_kms_encryption_key: projects/plt-lz-backend-tf5f-prod/locations/us/keyRings/state-encryption/cryptoKeys/default
2728
opentofu_plan_args: -var-file=tfvars/production.tfvars
2829
opentofu_state_bucket: plt-dd-organization-d3c2-prod
2930
opentofu_version: ${{ vars.OPENTOFU_VERSION }}
3031
opentofu_workspace: main-production
3132
workload_identity_provider: projects/134040294660/locations/global/workloadIdentityPools/github-actions/providers/github-actions-oidc
3233
secrets:
33-
gpg_passphrase: ${{ secrets.GPG_PASSPHRASE }}
3434
opentofu_plan_secret_args: >-
3535
-var=datadog_api_key=${{ secrets.DATADOG_API_KEY }}
3636
-var=datadog_app_key=${{ secrets.DATADOG_APP_KEY }}

backend.tofu

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# Backend Configuration
2-
# https://www.terraform.io/language/settings/backends/configuration
2+
# https://opentofu.org/docs/language/settings/backends/configuration
33

44
terraform {
5-
65
# Google Cloud Storage
7-
# https://www.terraform.io/language/settings/backends/gcs
6+
# https://opentofu.org/docs/language/settings/backends/gcs
87

98
backend "gcs" {
10-
prefix = "datadog-organization-management"
9+
bucket = var.state_bucket
10+
kms_encryption_key = var.state_kms_encryption_key
11+
prefix = var.state_prefix
1112
}
1213
}

main.tofu

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,43 @@
22
# https://registry.terraform.io/providers/DataDog/datadog/latest/docs
33

44
terraform {
5+
# State and Plan Encryption
6+
# https://opentofu.org/docs/language/state/encryption
7+
8+
# The commented out sections below demonstrate how to configure
9+
# fallback encryption methods for state and plan files for bootstrapping.
10+
11+
encryption {
12+
method "unencrypted" "migrate" {}
13+
14+
key_provider "gcp_kms" "default" {
15+
kms_encryption_key = var.state_kms_encryption_key
16+
key_length = 32
17+
}
18+
19+
method "aes_gcm" "default" {
20+
keys = key_provider.gcp_kms.default
21+
}
22+
23+
plan {
24+
method = method.aes_gcm.default
25+
# enforced = true
26+
27+
fallback {
28+
method = method.unencrypted.migrate
29+
}
30+
}
31+
32+
state {
33+
method = method.aes_gcm.default
34+
# enforced = true
35+
36+
fallback {
37+
method = method.unencrypted.migrate
38+
}
39+
}
40+
}
41+
542
required_providers {
643
datadog = {
744
source = "datadog/datadog"
@@ -162,3 +199,9 @@ resource "datadog_user" "this" {
162199
name = each.value.name
163200
roles = [data.datadog_role.this[each.value.role].id]
164201
}
202+
203+
resource "null_resource" "force_apply" {
204+
triggers = {
205+
always_run = timestamp()
206+
}
207+
}

variables.tofu

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,24 @@ variable "log_indexes" {
2929
}))
3030
}
3131

32+
# These three state_* variables are required for early variable evaluation for backend and provider configuration.
33+
# They are defined in the GitHub Actions called workflows and should NOT be set in the OpenTofu configuration.
34+
35+
variable "state_bucket" {
36+
description = "The name of the GCS bucket to store state files"
37+
type = string
38+
}
39+
40+
variable "state_kms_encryption_key" {
41+
description = "The KMS encryption key for state and plan files"
42+
type = string
43+
}
44+
45+
variable "state_prefix" {
46+
description = "The prefix for state files in the GCS bucket"
47+
type = string
48+
}
49+
3250
variable "teams" {
3351
description = "Map of Datadog teams to create"
3452
type = map(object({

0 commit comments

Comments
 (0)