Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azure: zone name as environment variable #1433

Merged
merged 14 commits into from
Aug 7, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/zz_gen_cmd_dnshelp.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ func displayDNSHelp(name string) error {
ew.writeln(` - "AZURE_POLLING_INTERVAL": Time between DNS propagation check`)
ew.writeln(` - "AZURE_PROPAGATION_TIMEOUT": Maximum waiting time for DNS propagation`)
ew.writeln(` - "AZURE_TTL": The TTL of the TXT record used for the DNS challenge`)
ew.writeln(` - "AZURE_ZONE_NAME": Zone name to use inside Azure DNS service to add the TXT record in`)

ew.writeln()
ew.writeln(`More information: https://go-acme.github.io/lego/dns/azure`)
Expand Down
1 change: 1 addition & 0 deletions docs/content/dns/zz_gen_azure.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ More information [here](/lego/dns/#configuration-and-credentials).
| `AZURE_POLLING_INTERVAL` | Time between DNS propagation check |
| `AZURE_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation |
| `AZURE_TTL` | The TTL of the TXT record used for the DNS challenge |
| `AZURE_ZONE_NAME` | Zone name to use inside Azure DNS service to add the TXT record in |

The environment variable names can be suffixed by `_FILE` to reference a file instead of a value.
More information [here](/lego/dns/#configuration-and-credentials).
Expand Down
26 changes: 20 additions & 6 deletions providers/dns/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
EnvTenantID = envNamespace + "TENANT_ID"
EnvClientID = envNamespace + "CLIENT_ID"
EnvClientSecret = envNamespace + "CLIENT_SECRET"
EnvZoneName = envNamespace + "ZONE_NAME"

EnvTTL = envNamespace + "TTL"
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
Expand Down Expand Up @@ -169,9 +170,15 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
ctx := context.Background()
fqdn, value := dns01.GetRecord(domain, keyAuth)

zone, err := d.getHostedZoneID(ctx, fqdn)
if err != nil {
return fmt.Errorf("azure: %w", err)
var zone string
if env.GetOrFile(EnvZoneName) != "" {
zone = env.GetOrFile(EnvZoneName)
} else {
var err error
zone, err = d.getHostedZoneID(ctx, fqdn)
if err != nil {
return fmt.Errorf("azure: %w", err)
}
fibbs marked this conversation as resolved.
Show resolved Hide resolved
}

rsc := dns.NewRecordSetsClientWithBaseURI(d.config.ResourceManagerEndpoint, d.config.SubscriptionID)
Expand Down Expand Up @@ -224,9 +231,16 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
ctx := context.Background()
fqdn, _ := dns01.GetRecord(domain, keyAuth)

zone, err := d.getHostedZoneID(ctx, fqdn)
if err != nil {
return fmt.Errorf("azure: %w", err)

var zone string
var err error
if env.GetOrFile(EnvZoneName) != "" {
zone = env.GetOrFile(EnvZoneName)
} else {
zone, err = d.getHostedZoneID(ctx, fqdn)
if err != nil {
return fmt.Errorf("azure: %w", err)
}
}

relative := toRelativeRecord(fqdn, dns01.ToFqdn(zone))
Expand Down
1 change: 1 addition & 0 deletions providers/dns/azure/azure.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Example = ''''''
AZURE_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation"
AZURE_TTL = "The TTL of the TXT record used for the DNS challenge"
AZURE_METADATA_ENDPOINT = "Metadata Service endpoint URL"
AZURE_ZONE_NAME = "Zone name to use inside Azure DNS service to add the TXT record in"
fibbs marked this conversation as resolved.
Show resolved Hide resolved

[Links]
API = "https://docs.microsoft.com/en-us/go/azure/"
Expand Down