Skip to content

Commit

Permalink
Merge UDMIF into faucetsdn UDMI (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
slevertbiot committed Apr 21, 2022
1 parent 06569cf commit 0632590
Show file tree
Hide file tree
Showing 189 changed files with 50,402 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ udmi_site_model/
gcp_reflect_key.pkcs8
workspace.xml
codegen/
.DS_Store
tmp/
check_links.out
.gradle/
Expand All @@ -25,6 +26,8 @@ firebase-debug.log
.pubber.pid
__pycache__/

.vscode

cloud/gcp/terraform.tfvars
cloud/gcp/udmi-sites.tf
cloud/gcp/main.tf
Expand Down
56 changes: 56 additions & 0 deletions cloud/gcp/functions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
resource "google_storage_bucket" "function-bucket" {
name = "${var.gcp_project_name}-${var.function_name}"
project = var.gcp_project_id
force_destroy = true
storage_class = "STANDARD"
location = "US"
versioning {
enabled = true
}
}

data "archive_file" "source" {
type = "zip"
source_dir = "./src"
output_path = "./function.zip"
}
# Add the zipped file to the bucket.
resource "google_storage_bucket_object" "function-object" {
# We can avoid unnecessary redeployments by validating the code is unchanged, and forcing
# a redeployment when it has!
name = "index.zip"
bucket = google_storage_bucket.function-bucket.name
source = data.archive_file.source.output_path
lifecycle {
ignore_changes = [detect_md5hash]
}
}
# The cloud function resource.
resource "google_cloudfunctions_function" "enventHandlerFunction" {
available_memory_mb = var.function_memory
entry_point = var.function_entry_point
ingress_settings = "ALLOW_ALL"

name = var.function_name
project = var.gcp_project_id
region = var.gcp_region
runtime = var.function_runtime
event_trigger {
event_type = "providers/cloud.pubsub/eventTypes/topic.publish"
resource = "udmi_target"
}
environment_variables = var.function_environment_variables
source_archive_bucket = google_storage_bucket.function-bucket.name
source_archive_object = google_storage_bucket_object.function-object.name
}


# IAM Configuration. This allows to provied access to the function.
resource "google_cloudfunctions_function_iam_member" "invoker" {
project = google_cloudfunctions_function.enventHandlerFunction.project
region = google_cloudfunctions_function.enventHandlerFunction.region
cloud_function = google_cloudfunctions_function.enventHandlerFunction.name

role = "roles/cloudfunctions.invoker"
member = var.gcp_access_group
}
61 changes: 61 additions & 0 deletions cloud/gcp/gks.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#GKE CLUSTER
resource "google_container_cluster" "udmi" {
name = var.gke_cluster_name
location = var.gke_cluster_location
node_locations = var.gke_node_locations

# We can't create a cluster with no node pool defined, but we want to only use
# separately managed node pools. So we create the smallest possible default
# node pool and immediately delete it.

initial_node_count = var.gke_initial_node_count

network = var.create_vpc ? google_compute_network.vpc[0].name : null
subnetwork = var.create_vpc ? google_compute_subnetwork.subnet[0].name : null
}

# Separately Managed Node Pool
resource "google_container_node_pool" "node_pool" {
name = var.gke_node_pool_name
location = var.gke_cluster_location
cluster = google_container_cluster.udmi.name
node_count = var.gke_num_nodes

node_config {

# preemptible = true
machine_type = var.gke_machine_type
metadata = {
disable-legacy-endpoints = "true"
}
}
}

resource "google_compute_global_address" "udmi_global_address"{
name = "udmi-global-address"
project = var.gcp_project_id
}

resource "google_dns_managed_zone" "udmi_dns_zone" {
name = var.gcp_project_name
dns_name = var.dns_name
project = var.gcp_project_id
}

resource "google_dns_record_set" "dns_record" {
project = var.gcp_project_id
managed_zone = var.gcp_project_name
name = "*.${var.dns_name}"
type = "A"
ttl = 300
rrdatas = ["${google_compute_global_address.udmi_global_address.address}"]
}

resource "google_compute_managed_ssl_certificate" "udmi_ssl_certs" {
name = "udmi-ssl"
project = var.gcp_project_id
managed {
domains = var.ssl_domains
}
}

4 changes: 4 additions & 0 deletions cloud/gcp/main.tf.template
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ terraform {
source = "hashicorp/google"
version = "~> 3.0"
}
mongodbatlas = {
source = "mongodb/mongodbatlas"
version = "~> 1.3.1"
}
}
backend "gcs" {
bucket = "@GCP_PROJECT_ID@-terraform"
Expand Down
40 changes: 40 additions & 0 deletions cloud/gcp/mongodb.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
resource "mongodbatlas_project" "udmi" {
name = var.project_name
org_id = var.atlas_org_id
}
## mongodbatlas cluster
resource "mongodbatlas_cluster" "udmi" {
project_id = mongodbatlas_project.udmi.id
name = var.cluster_name
mongo_db_major_version = var.mongodb_version
cluster_type = "REPLICASET"
replication_specs {
num_shards = 1
regions_config {
region_name = var.cluster_region
electable_nodes = 3
priority = 7
read_only_nodes = 0
}
}
# Provider Settings "block"
provider_name = var.provider_name
disk_size_gb = var.disk_size_gb
provider_instance_size_name = var.instance_size_name
auto_scaling_disk_gb_enabled = true
provider_auto_scaling_compute_max_instance_size = var.auto_scaling_max_instance_size
provider_auto_scaling_compute_min_instance_size = var.auto_scaling_min_instance_size
}

# DATABASE USER
resource "mongodbatlas_database_user" "user" {
username = var.db_username
password = var.db_password
project_id = mongodbatlas_project.udmi.id
auth_database_name = "admin"

roles {
role_name = var.db_role
database_name = var.database_name
}
}
8 changes: 7 additions & 1 deletion cloud/gcp/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@ provider "google" {
credentials = file(var.gcp_auth_file)
project = var.gcp_project_name
region = var.gcp_region
}
}

provider "mongodbatlas" {
public_key = var.public_key
private_key = var.private_key
}

2 changes: 1 addition & 1 deletion cloud/gcp/storage.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Create a GCS Bucket
resource "google_storage_bucket" "tf-bucket" {
project = var.gcp_project_name
project = var.gcp_project_id
name = var.tf-state-bucket-name
force_destroy = true
storage_class = var.tf-state-storage-class
Expand Down
2 changes: 1 addition & 1 deletion cloud/gcp/udmi-sites.tf.template
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module "ZZ-TRI-FECTA" {
source = "./modules/terraform-google-udmi-site"
gcp_project = var.gcp_project_name
gcp_project = var.gcp_region
gcp_region = var.gcp_region
site_name = "@UDMI_SITE_NAME@"
site_region = "@UDMI_SITE_REGION@"
site_group = "group:@UDMI_SITE_GROUP@"
Expand Down
159 changes: 158 additions & 1 deletion cloud/gcp/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,161 @@ variable "gcp_access_group" {
variable "log_level" {
type = string
description = "Log level"
}
}

##GKE variables##
variable "gke_num_nodes" {
type = number
default = 1
description = "number of gke nodes"
}
variable "gke_node_locations" {
type = list(string)
default = []
description = "The list of zones in which the cluster's nodes are located"
}

variable "gke_initial_node_count" {
type = number
default = 0
description = "The number of nodes to create in this cluster"
}

variable "gke_cluster_name" {
type = string
default = "udmi"
description = "gke cluster name"
}

variable "gke_node_pool_name" {
type = string
default = "udmi"
description = "The name of the node pool"
}
variable "gke_cluster_location" {
type = string
default = "us-central1-f"
description = "The location (region or zone) of the cluster"
}
variable "gke_machine_type" {
type = string
default = "e2-standard-2"
description = "Type of machine"
}
#cloud DNS variables
variable "dns_name" {
type = string
description = "DNS name"
}
#ssl variable
variable "ssl_domains" {
type = list(string)
description = "list of domain names"
}
##vpc variables##
variable "gcp_vpc_name" {
type = string
default = "udmi"
description = "vpc name"
}
variable "ip_cidr_range" {
type = string
default = "10.10.0.0/24"
description = "The range of internal addresses that are owned by this subnetwork"
}
variable "create_vpc" {
type = bool
default = false
description = "we can use default vpc or new vpc"
}

## function variables
variable "function_name" {
type = string
description = "functions name"
}
variable "function_memory" {
type = number
description = "The amount of memory in megabytes allotted for the function to use."
}
variable "function_runtime" {
type = string
description = "The runtime in which the function will be executed."
}
variable "function_entry_point" {
type = string
description = "The name of a method in the function source which will be invoked when the function is executed."
}
variable "function_environment_variables" {
type = map(string)
description = "A set of key/value environment variable pairs to assign to the function."
}
## Mongodb variables
variable "public_key" {
type = string
description = "mangodb api public key"
}
variable "private_key" {
type = string
description = "mangodb api private key"
}
variable "project_name" {
type = string
description = "mangodb project name"
}
variable "atlas_org_id" {
type = string
description = "atlas orgination id "
}
variable "cluster_name" {
type = string
description = "Mongodbatlas Cluster Name"
}
variable "mongodb_version" {
type = string
description = "Mongodbatlas version"
}
variable "cluster_region" {
type = string
description = "Mongodbatlas cluster region"
}
variable "provider_name" {
type = string
description = "Mongodbatlas cloud provider"
}
variable "disk_size_gb" {
type = string
description = "mongodb space were we are using for this project"
}
variable "instance_size_name" {
type = string
description = "mongodb space name were we are using for this project"
}
variable "auto_scaling_max_instance_size" {
type = string
description = "auto scalling max instance size when it require"
}
variable "auto_scaling_min_instance_size" {
type = string
description = "auto scalling min instance size when it require"
}
variable "db_username" {
type = string
description = "MongoDB Atlas Database User Name"
}
variable "db_password" {
type = string
description = "MongoDB Atlas Database User Password"
}
variable "database_name" {
type = string
description = "The database in the cluster to limit the database user to, the database does not have to exist yet"
}
variable "db_role" {
type = string
description = "the role where the db user can acess"
}




15 changes: 15 additions & 0 deletions cloud/gcp/vpc.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# VPC
resource "google_compute_network" "vpc" {
count = var.create_vpc ? 1 : 0
name = "${var.gcp_vpc_name}-vpc"
auto_create_subnetworks = "false"
}

# Subnet
resource "google_compute_subnetwork" "subnet" {
count = var.create_vpc ? 1 : 0
name = "${var.gcp_vpc_name}-subnet"
region = var.gcp_region
network = google_compute_network.vpc[count.index].name
ip_cidr_range = var.ip_cidr_range
}
Empty file added cloud/src/index.js
Empty file.
Loading

0 comments on commit 0632590

Please sign in to comment.