Commit 3da75b43 authored by Adam Lewenberg's avatar Adam Lewenberg
Browse files

first commit

parents
Loading
Loading
Loading
Loading

README.md

0 → 100644
+25 −0
Original line number Diff line number Diff line
# GCP Cloud SQL Proxy Puppet module

This module installs the GCP Cloud SQL Proxy software and configures its
options. This module is a "define" in case you need to install more than
instance of the Cloud SQL Proxy service. For more information on
configuration, see the [Cloud SQL Proxy Github
page](https://github.com/GoogleCloudPlatform/cloudsql-proxy).

Example:
```
gcp_cloudsql_proxy { 'example1':
  instances => ["myg-gcp-project:us-west1:mysql-1=tcp:3306"],
}
```

If you have put the service account JSON credentials in a wallet object,
indicate this by using the `service_credentials_wallet_name` parameter:
```
gcp_cloudsql_proxy { 'example1':
  instances => ["myg-gcp-project:us-west1:mysql-1=tcp:3306"],
  service_credentials_wallet_name
            => 'config/abcd/gcp-service-account/cloud-sql-proxy-1',
}

```
+3 −0
Original line number Diff line number Diff line
cloudsql-proxy.sh: /^\d\d\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d Client closed local connection on 127.0.0.1:\d\d\d\d$/
cloudsql-proxy.sh: /^\d\d\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d New connection for ".*"$/
cloudsql-proxy.sh: /^\d\d\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d ephemeral certificate for instance .* will expire soon, refreshing now[.]$/

manifests/init.pp

0 → 100644
+45 −0
Original line number Diff line number Diff line
# 1. Download the package
# 2. Downloads the service accounts credentials file (JSON)
# 3. Creates the file /etc/cloudsql-proxy/options

define gcp_cloudsql_proxy(
  Enum['present', 'absent'] $ensure                          = 'present',
  Optional[String]          $service_credentials_wallet_name = undef,
  #
  Array[String]             $instances                       = [],
) {

  include gcp_cloudsql_proxy::package

  file { '/etc/cloudsql-proxy':
    ensure  => directory,
  }

  if ($service_credentials_wallet_name) {
    base::wallet { $service_credentials_wallet_name:
      ensure  => $ensure,
      path    => '/etc/cloudsql-proxy/cloudsql.json',
      type    => 'file',
      owner   => root,
      group   => root,
      mode    => '0640',
    }
  }

  file { '/etc/cloudsql-proxy/options':
    ensure  => $ensure,
    content => template('gcp_cloudsql_proxy/etc/cloudsql-proxy/options.erb'),
  }

  # Make Sure cloudsql-proxy service is running.
  service { 'cloudsql-proxy':
    ensure  => running,
    require => Package['cloudsql-proxy'],
  }

  file { '/etc/filter-syslog/cloudsql-proxy':
    ensure => $ensure,
    source => 'puppet:///modules/gcp_cloudsql_proxy/etc/filter-syslog/cloudsql-proxy',
  }

}

manifests/package.pp

0 → 100644
+12 −0
Original line number Diff line number Diff line
class gcp_cloudsql_proxy::package {

  # Install the cloudsql-proxy package. This package contains the binary
  # cloud_sql_proxy packaged here at Stanford to make it more convenient
  # to install. It also contains a systemd service to manage the Cloud SQL
  # Proxy server. See also
  # https://code.stanford.edu/debian-public/cloudsql-proxy
  package { 'cloudsql-proxy':
    ensure => installed
  }

}
+11 −0
Original line number Diff line number Diff line
<%-
  if (@instances.length() == 0) then
    raise "must have at least one instance"
  end

  # Join the instances
  instances_str = @instances.join(",")
-%>
dir=/run/cloudsql
credential_file=/etc/cloudsql-proxy/cloudsql.json
instances=<%= instances_str %>