Skip to content

Commit 622afdc

Browse files
committed
Refactor terraform modules
1 parent f2b7fb7 commit 622afdc

File tree

8 files changed

+110
-65
lines changed

8 files changed

+110
-65
lines changed

deployment/live/gcp/test/terragrunt.hcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
terraform {
2-
source = "${get_repo_root()}/deployment/modules/gcp//storage"
2+
source = "${get_repo_root()}/deployment/modules/gcp//"
33
}
44

55
locals {

deployment/modules/gcp/key/main.tf

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
terraform {
2+
required_providers {
3+
google = {
4+
source = "registry.terraform.io/hashicorp/google"
5+
version = "6.1.0"
6+
}
7+
}
8+
}
9+
10+
# Secret Manager
11+
12+
# ECDSA key with P256 elliptic curve. Do NOT use this in production environment.
13+
#
14+
# Security Notice
15+
# The private key generated by this resource will be stored unencrypted in your
16+
# Terraform state file. Use of this resource for production deployments is not
17+
# recommended. Instead, generate a private key file outside of Terraform and
18+
# distribute it securely to the system where Terraform will be run.
19+
#
20+
# See https://registry.terraform.io/providers/hashicorp/tls/latest/docs/resources/private_key.
21+
resource "tls_private_key" "sctfe_ecdsa_p256" {
22+
algorithm = "ECDSA"
23+
ecdsa_curve = "P256"
24+
}
25+
26+
resource "google_secret_manager_secret" "sctfe_ecdsa_p256_public_key" {
27+
secret_id = "sctfe-ecdsa-p256-public-key"
28+
29+
labels = {
30+
label = "sctfe-public-key"
31+
}
32+
33+
replication {
34+
auto {}
35+
}
36+
}
37+
38+
resource "google_secret_manager_secret_version" "sctfe_ecdsa_p256_public_key" {
39+
secret = google_secret_manager_secret.sctfe_ecdsa_p256_public_key.id
40+
41+
secret_data = tls_private_key.sctfe_ecdsa_p256.public_key_pem
42+
}
43+
44+
resource "google_secret_manager_secret" "sctfe_ecdsa_p256_private_key" {
45+
secret_id = "sctfe-ecdsa-p256-private-key"
46+
47+
labels = {
48+
label = "sctfe-private-key"
49+
}
50+
51+
replication {
52+
auto {}
53+
}
54+
}
55+
56+
resource "google_secret_manager_secret_version" "sctfe_ecdsa_p256_private_key" {
57+
secret = google_secret_manager_secret.sctfe_ecdsa_p256_private_key.id
58+
59+
secret_data = tls_private_key.sctfe_ecdsa_p256.private_key_pem
60+
}

deployment/modules/gcp/key/outputs.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
output "ecdsa_p256_public_key_id" {
2+
description = "Signer public key (P256_SHA256)"
3+
value = google_secret_manager_secret_version.sctfe_ecdsa_p256_public_key.id
4+
}
5+
6+
output "ecdsa_p256_private_key_id" {
7+
description = "Signer private key (P256_SHA256)"
8+
value = google_secret_manager_secret_version.sctfe_ecdsa_p256_private_key.id
9+
}

deployment/modules/gcp/main.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
terraform {
2+
backend "gcs" {}
3+
}
4+
5+
module "storage" {
6+
source = "./storage"
7+
8+
project_id = var.project_id
9+
base_name = var.base_name
10+
location = var.location
11+
}
12+
13+
module "key" {
14+
source = "./key"
15+
}

deployment/modules/gcp/outputs.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
output "ecdsa_p256_public_key_id" {
2+
description = "Signer public key (P256_SHA256)"
3+
value = module.key.ecdsa_p256_public_key_id
4+
}
5+
6+
output "ecdsa_p256_private_key_id" {
7+
description = "Signer private key (P256_SHA256)"
8+
value = module.key.ecdsa_p256_private_key_id
9+
}
Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
terraform {
2-
backend "gcs" {}
3-
42
required_providers {
53
google = {
64
source = "registry.terraform.io/hashicorp/google"
@@ -37,6 +35,7 @@ resource "google_storage_bucket" "log_bucket" {
3735
location = var.location
3836
storage_class = "STANDARD"
3937
uniform_bucket_level_access = true
38+
force_destroy = true
4039
}
4140

4241
# Spanner
@@ -46,6 +45,7 @@ resource "google_spanner_instance" "log_spanner" {
4645
config = "regional-${var.location}"
4746
display_name = var.base_name
4847
processing_units = 100
48+
force_destroy = true
4949
}
5050

5151
resource "google_spanner_database" "log_db" {
@@ -65,55 +65,3 @@ resource "google_spanner_database" "dedup_db" {
6565
"CREATE TABLE IDSeq (id INT64 NOT NULL, h BYTES(MAX) NOT NULL, idx INT64 NOT NULL,) PRIMARY KEY (id, h)",
6666
]
6767
}
68-
69-
# Secret Manager
70-
71-
# ECDSA key with P256 elliptic curve. Do NOT use this in production environment.
72-
#
73-
# Security Notice
74-
# The private key generated by this resource will be stored unencrypted in your
75-
# Terraform state file. Use of this resource for production deployments is not
76-
# recommended. Instead, generate a private key file outside of Terraform and
77-
# distribute it securely to the system where Terraform will be run.
78-
#
79-
# See https://registry.terraform.io/providers/hashicorp/tls/latest/docs/resources/private_key.
80-
resource "tls_private_key" "sctfe_ecdsa_p256" {
81-
algorithm = "ECDSA"
82-
ecdsa_curve = "P256"
83-
}
84-
85-
resource "google_secret_manager_secret" "sctfe_ecdsa_p256_public_key" {
86-
secret_id = "sctfe-ecdsa-p256-public-key"
87-
88-
labels = {
89-
label = "sctfe-public-key"
90-
}
91-
92-
replication {
93-
auto {}
94-
}
95-
}
96-
97-
resource "google_secret_manager_secret_version" "sctfe_ecdsa_p256_public_key" {
98-
secret = google_secret_manager_secret.sctfe_ecdsa_p256_public_key.id
99-
100-
secret_data = tls_private_key.sctfe_ecdsa_p256.public_key_pem
101-
}
102-
103-
resource "google_secret_manager_secret" "sctfe_ecdsa_p256_private_key" {
104-
secret_id = "sctfe-ecdsa-p256-private-key"
105-
106-
labels = {
107-
label = "sctfe-private-key"
108-
}
109-
110-
replication {
111-
auto {}
112-
}
113-
}
114-
115-
resource "google_secret_manager_secret_version" "sctfe_ecdsa_p256_private_key" {
116-
secret = google_secret_manager_secret.sctfe_ecdsa_p256_private_key.id
117-
118-
secret_data = tls_private_key.sctfe_ecdsa_p256.private_key_pem
119-
}

deployment/modules/gcp/storage/outputs.tf

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,3 @@ output "dedup_spanner_db" {
1717
description = "Dedup Spanner database"
1818
value = google_spanner_database.dedup_db
1919
}
20-
21-
output "ecdsa_p256_public_key_id" {
22-
description = "Signer public key (P256_SHA256)"
23-
value = google_secret_manager_secret_version.sctfe_ecdsa_p256_public_key.id
24-
}
25-
26-
output "ecdsa_p256_private_key_id" {
27-
description = "Signer private key (P256_SHA256)"
28-
value = google_secret_manager_secret_version.sctfe_ecdsa_p256_private_key.id
29-
}

deployment/modules/gcp/variables.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
variable "project_id" {
2+
description = "GCP project ID where the log is hosted"
3+
type = string
4+
}
5+
6+
variable "base_name" {
7+
description = "Base name to use when naming resources"
8+
type = string
9+
}
10+
11+
variable "location" {
12+
description = "Location in which to create resources"
13+
type = string
14+
}

0 commit comments

Comments
 (0)