Git Product home page Git Product logo

terraform-rancher-project-collection's Introduction

Rancher2 terraform module for project

Rancher2 terraform module for deploying a project and its resources. This terraform module is using the Rancher2 terraform provider to create and manage apps, config maps, namespaces, project role bindings and secrets

Module will do following tasks:

  • Connect to Rancher2 server
  • Wait until the cluster is active and all catalgos are downloaded (wait_for_catalogs variable)
  • Create Rancher2 project and its resources:
    • apps
    • config maps
    • namespaces
    • project role bindings
    • secrets

Variables

Input

This module accept the following variables as input:

# Required variables
variable "project" {
  type = object({
    cluster_id = string
    name = string
    project_limit = map(string)
    namespace_default_limit = map(string)
    container_resource_limit = map(string)
    role_bindings = map(map(string))
  })
  description = "Rancher2 project to be created"
}

# Optional variables
variable "config_maps" {
  type = map(object({
    namespace = string
    data = map(string)
  }))
  default = {}
  description = "Add config maps to be created within a project namespace"
}
variable "disable_prefix" {
  type = bool
  default = false
  description = "By default, all project resources names will have the prefix `<project_name>-`. Set this to true to disable it."
}
variable "wait_for_catalogs" {
  type        = bool
  default     = true
  description = "By default, project will wait until all catalogs are downloaded. Set this to false to disable it."
}
variable "namespaces" {
  type = map(object({
    limit = map(string)
    container_resource_limit = map(string)
  }))
  default     = {}
  description = "Add namespaces to be created within the project"
}
variable "secrets" {
  type = map(object({
    namespace = string  # namespace should be added first at variable namespaces
    type = string 
    data = map(string)
  }))
  default = {}
  description = "Add secrets to be created within a project namespace"
}
variable "apps" {
  type = map(object({
    namespace = string  # namespace should be added first at variable namespaces
    repo_name = string
    chart_name = string
    chart_version = string
    values = string
  }))
  default = {}
  description = "Add apps to be created within a project namespace"
}

Output

This module use the following variables as ouput:

output "rancher2_project" {
  value = rancher2_project.project
}

output "rancher2_project_role_template_bindings" {
  value = rancher2_project_role_template_binding.project_role_template_bindings
  sensitive = true
}

output "rancher2_namespaces" {
  value = rancher2_namespace.namespaces
  sensitive = true
}

output "rancher2_config_maps" {
  value = rancher2_config_map_v2.config_maps
  sensitive = true
}

output "rancher2_secrets" {
  value = rancher2_secret_v2.secrets
  sensitive = true
}

output "rancher2_apps" {
  value = rancher2_app_v2.apps
  sensitive = true
}

How to use

This tf module can be used standalone or combined with other tf modules.

Requirements for use standalone:

  • Rancher2 server up and running
  • Rancher2 url and access token
  • Input project info with required variables
  • Input project additional resources info with optional variables

Add the following to your tf file:

# Rancher2 provider should be configured here or using env vars
provider "rancher2" {
  api_url = <RANCHER_URL>
  token_key = <RANCHER_TOKEN>
}

module "rancher2-project" {
  source = "github.com/rancher/terraform-rancher2-project"

  # Required variables
  project = {
    cluster_id = "local"
    disable_prefix = true
    name = "test"
    project_limit = {
      limits_cpu = "2"
      limits_memory = "2Gi"
      requests_storage = "10Gi"
    }
    namespace_default_limit = {
      limits_cpu = "1"
      limits_memory = "1Gi"
      requests_storage = "10Gi"
    }
    container_resource_limit = {
      limits_cpu = "20m"
      limits_memory = "20Mi"
      requests_cpu = "1m"
      requests_memory = "1Mi"
    }
    role_bindings = {
      admin = {
        role_template_id = "admin"
        user_principal_id = "local://<user>"
      }
    }
  }
  # Optional variables
  namespaces = {
    myapp: {
      limit = {
        limits_cpu = "2"
        limits_memory = "2Gi"
        requests_storage = "10Gi"
      }
      container_resource_limit = {
        limits_cpu = "20m"
        limits_memory = "20Mi"
        requests_cpu = "1m"
        requests_memory = "1Mi"
      }
    }
    grafana = {
      limit = null
      container_resource_limit = null
    }
  }
  config_maps = {
    myapp-config = {
      namespace = "myapp"  # namespace should be added first at variable namespaces
      data = {
        "v1.json" = "[{\"foo\": \"var\"}]"
        "v2.json" = file("config/myapp/v2.json")
      }
    }
  }
  secrets = {
    myapp-admin = {
      namespace = "myapp"  # namespace should be added first at variable namespaces
      type = null
      data = {
        "admin-user" = "myapp_user"
        "admin-password" = "myapp_pass"
      }
    }
  }
  apps = {
    myapp = {
      namespace = "myapp"  # namespace should be added first at variable namespaces
      repo_name = "myapp_repo"
      chart_name = "myapp_chart"
      chart_version = "myapp_version"
      values = file("config/grafana.yaml")
    }
  }
}

License

Copyright (c) 2014-2021 Rancher Labs, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

terraform-rancher-project-collection's People

Contributors

paraglade avatar rawmind0 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.