Skip to content

Commit

Permalink
azure: expose regional replication as config field (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
malt3 authored Jan 26, 2024
1 parent 30aaaf8 commit 9730d61
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 38 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,13 @@ The primary Azure region to upload the image to. Example: `northeurope`.
This region is used for the resource group, disk and gallery.
Subsequent images are replicated to all other regions specified in `replicationRegions`.

### `base.azure.replicationRegions` / `variant.<name>.azure.replicationRegions`

- Default: `[]`
- Required: no

Additional Azure regions that the image will be replicated in. Example: `["northeurope", "eastus2"]`.

### `base.azure.resourceGroup` / `variant.<name>.azure.resourceGroup`

- Default: none
Expand Down
45 changes: 19 additions & 26 deletions azure/uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ func (u *Uploader) createImageVersion(ctx context.Context, imageID string) (stri
PublishingProfile: &armcomputev5.GalleryImageVersionPublishingProfile{
ReplicaCount: toPtr[int32](1),
ReplicationMode: toPtr(armcomputev5.ReplicationModeFull),
TargetRegions: targetRegions,
TargetRegions: replication(u.config.Azure.Location, u.config.Azure.ReplicationRegions, 1),
},
},
}
Expand Down Expand Up @@ -609,29 +609,22 @@ func toPtr[T any](t T) *T {
return &t
}

var targetRegions = []*armcomputev5.TargetRegion{
{
Name: toPtr("germanywestcentral"),
RegionalReplicaCount: toPtr[int32](1),
},
{
Name: toPtr("northeurope"),
RegionalReplicaCount: toPtr[int32](1),
},
{
Name: toPtr("eastus"),
RegionalReplicaCount: toPtr[int32](1),
},
{
Name: toPtr("westeurope"),
RegionalReplicaCount: toPtr[int32](1),
},
{
Name: toPtr("westus"),
RegionalReplicaCount: toPtr[int32](1),
},
{
Name: toPtr("southeastasia"),
RegionalReplicaCount: toPtr[int32](1),
},
func replication(location string, regions []string, count int32) []*armcomputev5.TargetRegion {
targetRegions := []*armcomputev5.TargetRegion{
{
Name: toPtr(location),
RegionalReplicaCount: toPtr[int32](count),
},
}
for _, region := range regions {
if region == location {
continue
}
targetRegions = append(targetRegions, &armcomputev5.TargetRegion{
Name: toPtr(region),
RegionalReplicaCount: toPtr[int32](count),
})
}

return targetRegions
}
25 changes: 13 additions & 12 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,19 @@ type AWSConfig struct {
}

type AzureConfig struct {
SubscriptionID string `toml:"subscriptionID,omitempty"`
Location string `toml:"location,omitempty"`
ResourceGroup string `toml:"resourceGroup,omitempty" template:"true"`
AttestationVariant string `toml:"attestationVariant,omitempty" template:"true"`
SharedImageGallery string `toml:"sharedImageGallery,omitempty" template:"true"`
SharingProfile string `toml:"sharingProfile,omitempty" template:"true"`
SharingNamePrefix string `toml:"sharingNamePrefix,omitempty" template:"true"`
ImageDefinitionName string `toml:"imageDefinitionName,omitempty" template:"true"`
Offer string `toml:"offer,omitempty" template:"true"`
SKU string `toml:"sku,omitempty" template:"true"`
Publisher string `toml:"publisher,omitempty" template:"true"`
DiskName string `toml:"diskName,omitempty" template:"true"`
SubscriptionID string `toml:"subscriptionID,omitempty"`
Location string `toml:"location,omitempty"`
ReplicationRegions []string `toml:"replicationRegions,omitempty"`
ResourceGroup string `toml:"resourceGroup,omitempty" template:"true"`
AttestationVariant string `toml:"attestationVariant,omitempty" template:"true"`
SharedImageGallery string `toml:"sharedImageGallery,omitempty" template:"true"`
SharingProfile string `toml:"sharingProfile,omitempty" template:"true"`
SharingNamePrefix string `toml:"sharingNamePrefix,omitempty" template:"true"`
ImageDefinitionName string `toml:"imageDefinitionName,omitempty" template:"true"`
Offer string `toml:"offer,omitempty" template:"true"`
SKU string `toml:"sku,omitempty" template:"true"`
Publisher string `toml:"publisher,omitempty" template:"true"`
DiskName string `toml:"diskName,omitempty" template:"true"`
}

type GCPConfig struct {
Expand Down
1 change: 1 addition & 0 deletions config/validation.rego
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ required_fields := {
"azure": {
"subscriptionID": input.Azure.SubscriptionID,
"location": input.Azure.Location,
"replicationRegions": input.Azure.ReplicationRegions,
"resourceGroup": input.Azure.ResourceGroup,
"attestationVariant": input.Azure.AttestationVariant,
"sharedImageGallery": input.Azure.SharedImageGallery,
Expand Down

0 comments on commit 9730d61

Please sign in to comment.