From f2a4efbcb42fdfaa27fd846dc23fabdb493e9326 Mon Sep 17 00:00:00 2001 From: Anders Bruun Olsen Date: Tue, 13 Mar 2018 20:40:17 +0100 Subject: [PATCH] =?UTF-8?q?Auto-detect=20google-project=20if=20provider=20?= =?UTF-8?q?is=20Google=20and=20no=20project=20is=20su=E2=80=A6=20(#492)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Auto-detect google-project if provider is Google and no project is supplied. * Add changelog entry. --- CHANGELOG.md | 1 + provider/google.go | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66015e361e..76cdd0369c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ + - Google Provider: Add auto-detection of Google Project when running on GCP (#492) @drzero42 - Add custom TTL support for DNSimple (#477) @jbowes - Fix docker build and delete vendor files which were not deleted (#473) @njuettner - DigitalOcean: DigitalOcean creates entries with host in them twice (#459) @njuettner diff --git a/provider/google.go b/provider/google.go index c1b6b2b8d9..e7a2a93409 100644 --- a/provider/google.go +++ b/provider/google.go @@ -21,6 +21,7 @@ import ( "sort" "strings" + "cloud.google.com/go/compute/metadata" "github.com/linki/instrumented_http" log "github.com/sirupsen/logrus" @@ -133,6 +134,14 @@ func NewGoogleProvider(project string, domainFilter DomainFilter, zoneIDFilter Z return nil, err } + if project == "" { + mProject, mErr := metadata.ProjectID() + if mErr == nil { + log.Infof("Google project auto-detected: %s", mProject) + project = mProject + } + } + provider := &GoogleProvider{ project: project, domainFilter: domainFilter,