Code Monkey home page Code Monkey logo

terraform-cloudflare-tunnels's Introduction

Header

General outline of the project

  1. Set up a Cloudflare tunnel and configure it remotely. This can be done locally with a config.yaml file but we are doing it through Cloudflare itself. Every time the CloudflareD container starts it will pull down the relevant configuration.

  2. Set up the proper DNS records for our tunnel. Both the tunnel's ingress rules and the DNS records will be defined recusively, based on the predefined variables.

  3. Set up Cloudflared container. Upon starting, it's given a token that was defined in Step 1. It connects to Cloudflare and pulls the config.

The whole setup should take no more than a minute.

๐Ÿ’ก Commands used in this project

# Initializing/upgrading the project
terraform init -upgrade

# Imports the docker nextwork "cloudflared_network" for cloudlared & other containers if it exists.
# On first run, this shouldn't be a problem.
# Here is a one-liner, you need to supply the network name.
docker network inspect cloudflared_network -f "{{json .Id }}" | terraform import docker_network.cloudflared_network _

terraform apply -auto-approve

# Should destroy everything but the Docker network because it's probably used by other containers.
terraform apply -destroy -auto-approve

๐Ÿ“ Variables used in this project

Rename the variables.auto.tfvars.example to variables.auto.tfvars and fill it in.

# Credentials
  # Either
    CF_email = "[email protected]"
    # Use global Global API Key from https://dash.cloudflare.com/profile/api-tokens
    CF_apikey = ""

  # Or
    # Generate an API token from https://dash.cloudflare.com/profile/api-tokens
    # Must have enabled:
    #   Zones.DNS
    #   Account.Cloudflare Tunnel
    #   Account.Account Settings
    CF_apitoken = ""

# Custom tunnel name.
  CF_tunnel_name = "some-cool-name"

# Domain to manage.
  DOMAIN = "yourdomain.tld"

# Map of services and subdomains. The service url is from the docker network.
  SUBDOMAINS = [
    {
      "subdomain":"example1",
      "service":"http://container_name:80"
    },
    {
      "subdomain":"example2",
      "service":"http://container_name:8080"
    }
  ]

๐Ÿ“– Relevant Documentation

๐ŸŒŸ Terraform Docker Provider

๐ŸŒŸ Terraform Cloudflare Provider

๐ŸŒŸ Cloudflare Docs

๐ŸŒŸ Misc useful resources

terraform-cloudflare-tunnels's People

Watchers

 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.