Skip to content

Instantly share code, notes, and snippets.

@tjrivera
Created June 19, 2018 15:18
Show Gist options
  • Save tjrivera/54eb21dc0fb05e533e4052c8e6804c20 to your computer and use it in GitHub Desktop.
Save tjrivera/54eb21dc0fb05e533e4052c8e6804c20 to your computer and use it in GitHub Desktop.

Usage:

conffigen.py test01 | int01 | prod01

$ configgen.py int01

Input:

{
  "static_resources": {
    "listeners": [
      {
        "address": {
          "socket_address": {
            "address": "0.0.0.0",
            "port_value": 10000
          }
        },
        "listener_filters": {
          "name": "envoy.listener.tls_inspector",
          "config": {}
        },
        "filter_chains": [
          {
            "filter_chain_match": {
              "sni_domains": "ams.int01.aws.xfinityhome.com"
            },
            "filters": [
              {
                "name": "envoy.tcp_proxy",
                "config": {
                  "stat_prefix": "ams_tcp",
                  "cluster": "ams"
                }
              }
            ]
          },
          {
            "filter_chain_match": {
              "sni_domains": "releasedb.int01.aws.xfinityhome.com"
            },
            "filters": [
              {
                "name": "envoy.tcp_proxy",
                "config": {
                  "stat_prefix": "releasedb_tcp",
                  "cluster": "releasedb"
                }
              }
            ]
          },
          {
            "filter_chain_match": {
              "sni_domains": "ams-qa3.int01.aws.xfinityhome.com"
            },
            "filters": [
              {
                "name": "envoy.tcp_proxy",
                "config": {
                  "stat_prefix": "ams_qa3_tcp",
                  "cluster": "ams-qa3"
                }
              }
            ]
          },
          {
            "filter_chain_match": {
              "sni_domains": "ams-qa6.int01.aws.xfinityhome.com"
            },
            "filters": [
              {
                "name": "envoy.tcp_proxy",
                "config": {
                  "stat_prefix": "ams_qa6_tcp",
                  "cluster": "ams-qa6"
                }
              }
            ]
          },
          {
            "filter_chain_match": {
              "sni_domains": "insert.int01.aws.xfinityhome.com"
            },
            "filters": [
              {
                "name": "envoy.tcp_proxy",
                "config": {
                  "stat_prefix": "insert_tcp",
                  "cluster": "insert"
                }
              }
            ]
          }
        ]
      }
    ],
    "clusters": {{clusterBlock}}
  },
  "admin": {
    "access_log_path": "/dev/null",
    "address": {
      "socket_address": {
        "address": "0.0.0.0",
        "port_value": 8001
      }
    }
  },
  "stats_sinks": [
    {
      "name": "envoy.statsd",
      "config": {
        "tcp_cluster_name": "statsd"
      }
    }
  ]
}

Output:

{
  "static_resources": {
    "listeners": [
      {
        "address": {
          "socket_address": {
            "address": "0.0.0.0",
            "port_value": 10000
          }
        },
        "listener_filters": {
          "name": "envoy.listener.tls_inspector",
          "config": {}
        },
        "filter_chains": [
          {
            "filter_chain_match": {
              "sni_domains": "ams.int01.aws.xfinityhome.com"
            },
            "filters": [
              {
                "name": "envoy.tcp_proxy",
                "config": {
                  "stat_prefix": "ams_tcp",
                  "cluster": "ams"
                }
              }
            ]
          },
          {
            "filter_chain_match": {
              "sni_domains": "ams-qa3.int01.aws.xfinityhome.com"
            },
            "filters": [
              {
                "name": "envoy.tcp_proxy",
                "config": {
                  "stat_prefix": "ams_qa3_tcp",
                  "cluster": "ams-qa3"
                }
              }
            ]
          },
          {
            "filter_chain_match": {
              "sni_domains": "ams-qa6.int01.aws.xfinityhome.com"
            },
            "filters": [
              {
                "name": "envoy.tcp_proxy",
                "config": {
                  "stat_prefix": "ams_qa6_tcp",
                  "cluster": "ams-qa6"
                }
              }
            ]
          },
          {
            "filter_chain_match": {
              "sni_domains": "insert.int01.aws.xfinityhome.com"
            },
            "filters": [
              {
                "name": "envoy.tcp_proxy",
                "config": {
                  "stat_prefix": "insert_tcp",
                  "cluster": "insert"
                }
              }
            ]
          }
        ]
      }
    ],
    "clusters": [
      {
        "name": "statsd",
        "connect_timeout": "1.00s",
        "type": "strict_dns",
        "lb_policy": "round_robin",
        "hosts": [
          {
            "socket_address": {
              "address": "telegraf.service",
              "port_value": 8125
            }
          }
        ]
      },
      {
        "name": "zipkin",
        "connect_timeout": "1.00s",
        "type": "LOGICAL_DNS",
        "lb_policy": "round_robin",
        "dns_lookup_family": "V4_ONLY",
        "hosts": [
          {
            "socket_address": {
              "address": "zipkin.service",
              "port_value": 8000
            }
          }
        ]
      },
      {
        "name": "telegraf",
        "connect_timeout": "1.00s",
        "type": "LOGICAL_DNS",
        "lb_policy": "round_robin",
        "dns_lookup_family": "V4_ONLY",
        "hosts": [
          {
            "socket_address": {
              "address": "telegraf.service",
              "port_value": 8000
            }
          }
        ]
      },
      {
        "name": "ams-qa6",
        "connect_timeout": "1.00s",
        "type": "LOGICAL_DNS",
        "lb_policy": "round_robin",
        "dns_lookup_family": "V4_ONLY",
        "hosts": [
          {
            "socket_address": {
              "address": "ams-qa6.service",
              "port_value": 8000
            }
          }
        ]
      },
      {
        "name": "insert",
        "connect_timeout": "1.00s",
        "type": "LOGICAL_DNS",
        "lb_policy": "round_robin",
        "dns_lookup_family": "V4_ONLY",
        "hosts": [
          {
            "socket_address": {
              "address": "insert.service",
              "port_value": 8000
            }
          }
        ]
      },
      {
        "name": "ams-qa3",
        "connect_timeout": "1.00s",
        "type": "LOGICAL_DNS",
        "lb_policy": "round_robin",
        "dns_lookup_family": "V4_ONLY",
        "hosts": [
          {
            "socket_address": {
              "address": "ams-qa3.service",
              "port_value": 8000
            }
          }
        ]
      },
      {
        "name": "releasedb",
        "connect_timeout": "1.00s",
        "type": "LOGICAL_DNS",
        "lb_policy": "round_robin",
        "dns_lookup_family": "V4_ONLY",
        "hosts": [
          {
            "socket_address": {
              "address": "releasedb.service",
              "port_value": 8000
            }
          }
        ]
      },
      {
        "name": "ams",
        "connect_timeout": "1.00s",
        "type": "LOGICAL_DNS",
        "lb_policy": "round_robin",
        "dns_lookup_family": "V4_ONLY",
        "hosts": [
          {
            "socket_address": {
              "address": "ams.service",
              "port_value": 8000
            }
          }
        ]
      }
    ]
  },
  "admin": {
    "access_log_path": "/dev/null",
    "address": {
      "socket_address": {
        "address": "0.0.0.0",
        "port_value": 8001
      }
    }
  },
  "stats_sinks": [
    {
      "name": "envoy.statsd",
      "config": {
        "tcp_cluster_name": "statsd"
      }
    }
  ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment