-
-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
343 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Azure | ||
|
||
## Configuration | ||
|
||
### Example | ||
|
||
```json | ||
{ | ||
"settings": [ | ||
{ | ||
"provider": "azure", | ||
"domain": "domain.com", | ||
"host": "@", | ||
"tenant_id": "", | ||
"client_id": "", | ||
"client_secret": "", | ||
"subscription_id": "", | ||
"resource_group_name": "" | ||
} | ||
] | ||
} | ||
``` | ||
|
||
### Compulsory parameters | ||
|
||
- `"domain"` | ||
- `"host"` | ||
- `"tenant_id"` | ||
- `"client_id"` | ||
- `"client_secret"` | ||
- `"subscription_id"` found in the properties section of Azure DNS | ||
- `"resource_group_name"` found in the properties section of Azure DNS | ||
|
||
### Optional parameters | ||
|
||
- `"ip_version"` can be `ipv4` (A records) or `ipv6` (AAAA records), defaults to `ipv4 or ipv6` | ||
|
||
## Domain setup | ||
|
||
Thanks to @danimart1991 for describing the following steps! | ||
|
||
1. Create Domain | ||
1. Activate Azure DNS Zone for that domain | ||
1. Find the following parameters in the Properties section of Azure DNS: | ||
- The name or URL `AnyNameOrUrl` for the query below **TODO** | ||
- `subscription_id` | ||
- `resource_group_name` | ||
1. In the Azure Console (inside the portal), run: | ||
|
||
```sh | ||
az ad sp create-for-rbac -n "$AnyNameOrUrl" --scopes "/subscriptions/$subscription_id/resourceGroups/$resource_group_name/providers/Microsoft.Network/dnszones/$zone_name" | ||
``` | ||
|
||
This gives you the rest of the parameters: | ||
|
||
```json | ||
{ | ||
"appId": "{app_id/client_id}", | ||
"displayName": "not important", | ||
"name": "not important", | ||
"password": "{app_password}", | ||
"tenant": "not important" | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package azure | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/netip" | ||
|
||
"github.com/Azure/azure-sdk-for-go/sdk/azidentity" | ||
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/dns/armdns" | ||
) | ||
|
||
func (p *Provider) createClient() (client *armdns.RecordSetsClient, err error) { | ||
credential, err := azidentity.NewClientSecretCredential(p.tenantID, p.clientID, p.clientSecret, nil) | ||
if err != nil { | ||
return nil, fmt.Errorf("creating client secret credential: %w", err) | ||
} | ||
|
||
client, err = armdns.NewRecordSetsClient(p.subscriptionID, credential, nil) | ||
if err != nil { | ||
return nil, fmt.Errorf("creating record sets client: %w", err) | ||
} | ||
|
||
return client, nil | ||
} | ||
|
||
func (p *Provider) getRecordSet(ctx context.Context, client *armdns.RecordSetsClient, | ||
recordType armdns.RecordType) (response armdns.RecordSetsClientGetResponse, err error) { | ||
return client.Get(ctx, p.resourceGroupName, p.domain, p.owner, recordType, nil) | ||
} | ||
|
||
func (p *Provider) createRecordSet(ctx context.Context, client *armdns.RecordSetsClient, | ||
ip netip.Addr) (err error) { | ||
rrSet := armdns.RecordSet{Properties: &armdns.RecordSetProperties{}} | ||
recordType := armdns.RecordTypeA | ||
if ip.Is4() { | ||
rrSet.Properties.ARecords = []*armdns.ARecord{{IPv4Address: ptrTo(ip.String())}} | ||
} else { | ||
recordType = armdns.RecordTypeAAAA | ||
rrSet.Properties.AaaaRecords = []*armdns.AaaaRecord{{IPv6Address: ptrTo(ip.String())}} | ||
} | ||
_, err = client.CreateOrUpdate(ctx, p.resourceGroupName, p.domain, | ||
p.owner, recordType, rrSet, nil) | ||
if err != nil { | ||
return fmt.Errorf("creating record set: %w", err) | ||
} | ||
return nil | ||
} | ||
|
||
func (p *Provider) updateRecordSet(ctx context.Context, client *armdns.RecordSetsClient, | ||
response armdns.RecordSetsClientGetResponse, ip netip.Addr) (err error) { | ||
properties := response.Properties | ||
recordType := armdns.RecordTypeA | ||
if ip.Is4() { | ||
if len(properties.ARecords) == 0 { | ||
properties.ARecords = make([]*armdns.ARecord, 1) | ||
} | ||
for i := range properties.ARecords { | ||
properties.ARecords[i].IPv4Address = ptrTo(ip.String()) | ||
} | ||
} else { | ||
recordType = armdns.RecordTypeAAAA | ||
if len(properties.AaaaRecords) == 0 { | ||
properties.AaaaRecords = make([]*armdns.AaaaRecord, 1) | ||
} | ||
for i := range properties.AaaaRecords { | ||
properties.AaaaRecords[i].IPv6Address = ptrTo(ip.String()) | ||
} | ||
} | ||
rrSet := armdns.RecordSet{ | ||
Etag: response.Etag, | ||
Properties: properties, | ||
} | ||
|
||
_, err = client.CreateOrUpdate(ctx, p.resourceGroupName, p.domain, | ||
p.owner, recordType, rrSet, nil) | ||
return err | ||
} |
Oops, something went wrong.