GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Merge pull request #39 from commitdev/remote-state-env · commitdev/zero-aws-eks-stack@fbc9d9e

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Makefile
  • terraform
    • bootstrap
      • remote-state
        • main.tf
      • secrets
        • main.tf
    • modules/secret
      • main.tf
      • variables.tf
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Makefile‎

Copy file name to clipboardExpand all lines: Makefile
+10-6Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ ENV ?= staging
22

33
apply: apply-remote-state apply-secrets apply-env apply-k8s-utils
44

5+
## remove state file only if exit code 0 from terraform apply
56
apply-remote-state:
67
pushd terraform/bootstrap/remote-state; \
78
terraform init; \
8-
terraform apply -var "environment=$(ENV)"
9+
terraform apply -var "environment=$(ENV)" && rm ./terraform.tfstate;
910

1011
apply-secrets:
1112
pushd terraform/bootstrap/secrets; \
1213
terraform init; \
13-
terraform apply
14+
terraform apply && rm terraform.tfstate;
1415

1516
apply-env:
1617
pushd terraform/environments/$(ENV); \
@@ -28,12 +29,15 @@ update-k8s-conf:
2829
teardown: teardown-k8s-utils teardown-env teardown-secrets teardown-remote-state
2930

3031
teardown-remote-state:
31-
pushd terraform/bootstrap/remote-state; \
32-
terraform destroy -auto-approve -var "environment=$(ENV)";
32+
export AWS_PAGER=''; \
33+
aws s3 rb s3://<% .Name %>-$(ENV)-terraform-state --force; \
34+
aws dynamodb delete-table --table-name <% .Name %>-$(ENV)-terraform-state-locks;
3335

3436
teardown-secrets:
35-
pushd terraform/bootstrap/secrets; \
36-
terraform destroy -auto-approve;
37+
export AWS_PAGER=''; \
38+
aws secretsmanager list-secrets --query "SecretList[?Tags[?Key=='project' && Value=='<% .Name %>']].[Name]" | jq '.[] [0]' | xargs aws secretsmanager delete-secret --secret-id; \
39+
aws iam delete-access-key --user-name <% .Name %>-ci-user --access-key-id $(shell aws iam list-access-keys --user-name <% .Name %>-ci-user --query "AccessKeyMetadata[0].AccessKeyId" | sed 's/"//g'); \
40+
aws iam delete-user --user-name <% .Name %>-ci-user;
3741

3842
teardown-env:
3943
pushd terraform/environments/$(ENV); \
Collapse file

‎terraform/bootstrap/remote-state/main.tf‎

Copy file name to clipboardExpand all lines: terraform/bootstrap/remote-state/main.tf
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ resource "aws_dynamodb_table" "terraform_state_locks" {
3434
}
3535

3636
variable "environment" {
37-
description = "The environment (development/staging/production)"
37+
description = "The environment (staging/production)"
3838
}
Collapse file

‎terraform/bootstrap/secrets/main.tf‎

Copy file name to clipboardExpand all lines: terraform/bootstrap/secrets/main.tf
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ module "ci_user_keys" {
2929
name_prefix = "ci-user-aws-keys"
3030
type = "map"
3131
values = map("access_key_id", aws_iam_access_key.ci_user.id, "secret_key", aws_iam_access_key.ci_user.secret)
32+
tags = map("project", local.project)
3233
}
Collapse file

‎terraform/modules/secret/main.tf‎

Copy file name to clipboardExpand all lines: terraform/modules/secret/main.tf
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Add the keys to AWS secrets manager
22
resource "aws_secretsmanager_secret" "secret" {
33
name_prefix = var.name_prefix
4+
tags = var.tags
45
}
56

67
resource "aws_secretsmanager_secret_version" "string_secret" {
Collapse file

‎terraform/modules/secret/variables.tf‎

Copy file name to clipboardExpand all lines: terraform/modules/secret/variables.tf
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,9 @@ variable "random_length" {
2222
description = "The length of the generated string if type is random. Suitable for a db master password for example"
2323
default = 16
2424
}
25+
26+
variable "tags" {
27+
description = "Tags to include in the secret"
28+
type = map
29+
default = {}
30+
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.