Sfoglia il codice sorgente

Stands up pretty good

Fred Damstra (Macbook 2015) 2 anni fa
parent
commit
9a7891d9ec
5 ha cambiato i file con 67 aggiunte e 24 eliminazioni
  1. 9 2
      .gitignore
  2. 28 0
      client/test.py
  3. 24 22
      terraform/output.tf
  4. 5 0
      terraform/required_providers.tf
  5. 1 0
      terraform/test_instance.tf

+ 9 - 2
.gitignore

@@ -1,10 +1,17 @@
+# The resources config is generated via terraform
+terraform/terraform_resources.json
+
+# Ignore the virtualenv
+env/
+
+# No backups or temp files
 *.bak
 *.swp*
-
 tmp*
 
+# No zip Files or terraform cache
 terraform/lambda_scripts/*.zip
 .terraform/
 
-# Stupidest thing they ever did
+# Stupidest thing terraform ever did
 .terraform.lock.hcl

+ 28 - 0
client/test.py

@@ -0,0 +1,28 @@
+#! /usr/bin/env python3
+import json
+import logging
+import sys
+
+from redis import Redis
+
+logging.basicConfig(level=logging.INFO)
+
+
+def main():
+    redis = RedisCluster(
+        startup_nodes=[
+            {"host": "xxx.yyy.clustercfg.zzz1.cache.amazonaws.com", "port": "6379"}
+        ],
+        decode_responses=True,
+        skip_full_coverage_check=True,
+    )
+
+    if redis.ping():
+        logging.info("Connected to Redis")
+    else:
+        logging.error("Could not connect to Redis")
+        sys.exit(-1)
+
+
+if __name__ == "__main__":
+    main()

+ 24 - 22
terraform/output.tf

@@ -1,28 +1,30 @@
 locals {
+  tmp_output = {
+    "cognito" : {
+      "user_pool" : aws_cognito_user_pool.pool.id,
+      "client_id" : aws_cognito_user_pool_client.client.id,
+      "api_endpoint" : aws_apigatewayv2_api.gateway.api_endpoint
+    },
+    "api_gateway" : {
+      "test_endpoint" : aws_apigatewayv2_stage.test.invoke_url
+    },
+    "test_instances" : {
+      "dns" : aws_instance.test[*].public_dns,
+      "public_ip" : aws_instance.test[*].public_ip,
+      "private_ip" : aws_instance.test[*].private_ip
+    },
+    "elasticache" : {
+      "endpoints" : aws_elasticache_cluster.redis.cache_nodes[*]["address"]
+    }
+  }
 }
 
-output "cognito_user_pool" {
-  value = aws_cognito_user_pool.pool.id
-}
-
-output "cognito_client_id" {
-  value = aws_cognito_user_pool_client.client.id
-}
-
-output "api_endpoint" {
-  value = aws_apigatewayv2_api.gateway.api_endpoint
-}
-
-output "test_api_endpoint" {
-  value = aws_apigatewayv2_stage.test.invoke_url
+# Create a file other scripts can read
+resource "local_file" "output" {
+  filename = "${path.module}/terraform_resources.json"
+  content  = jsonencode(local.tmp_output)
 }
 
-output "test_instances_dns" {
-  value = {
-    "DNS" : aws_instance.test[*].public_dns,
-    "IP" : aws_instance.test[*].public_ip
-  }
+output "resources" {
+  value = local.tmp_output
 }
-
-#output "elasticache_endpoint" {
-#  value = aws_elasticache_cluster.redis.

+ 5 - 0
terraform/required_providers.tf

@@ -10,5 +10,10 @@ terraform {
       source  = "hashicorp/archive"
       version = "> 1.0"
     }
+
+    local = {
+      source  = "hashicorp/local"
+      version = "> 1.0"
+    }
   }
 }

+ 1 - 0
terraform/test_instance.tf

@@ -5,6 +5,7 @@ resource "aws_instance" "test" {
   associate_public_ip_address = true
   key_name                    = "fred-ed25519"
   subnet_id                   = module.vpc.public_subnets[count.index % 2]
+  vpc_security_group_ids      = [aws_security_group.allow_all.id]
 
   tags = merge(local.tags, { "index" : count.index })
 }