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

fix: Capture Container Name/Prefix not used in Artifact #344

Merged
merged 3 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions builder/azure/arm/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,16 @@ func NewSharedImageArtifact(osType, destinationSharedImageGalleryId string, loca
}, nil
}

func NewArtifact(vmInternalID string, storageAccountUrl string, storageAccountLocation string, osType string, additionalDiskCount int, generatedData map[string]interface{}) (*Artifact, error) {
vhdUri := fmt.Sprintf("%ssystem/Microsoft.Compute/Images/images/packer-osDisk.%s.vhd", storageAccountUrl, vmInternalID)
func NewArtifact(vmInternalID string, captureContainerPrefix string, captureContainerName string, storageAccountUrl string, storageAccountLocation string, osType string, additionalDiskCount int, generatedData map[string]interface{}) (*Artifact, error) {
vhdUri := fmt.Sprintf("%ssystem/Microsoft.Compute/Images/%s/%s-osDisk.%s.vhd", storageAccountUrl, captureContainerName, captureContainerPrefix, vmInternalID)

templateUri := fmt.Sprintf("%ssystem/Microsoft.Compute/Images/images/packer-vmTemplate.%s.json", storageAccountUrl, vmInternalID)
templateUri := fmt.Sprintf("%ssystem/Microsoft.Compute/Images/%s/%s-vmTemplate.%s.json", storageAccountUrl, captureContainerName, captureContainerPrefix, vmInternalID)

var additional_disks *[]AdditionalDiskArtifact
if additionalDiskCount > 0 {
data_disks := make([]AdditionalDiskArtifact, additionalDiskCount)
for i := 0; i < additionalDiskCount; i++ {
data_disks[i].AdditionalDiskUri = fmt.Sprintf("%ssystem/Microsoft.Compute/Images/images/packer-datadisk-%d.%s.vhd", storageAccountUrl, i+1, vmInternalID)
data_disks[i].AdditionalDiskUri = fmt.Sprintf("%ssystem/Microsoft.Compute/Images/%s/%s-datadisk-%d.%s.vhd", storageAccountUrl, captureContainerName, captureContainerPrefix, i, vmInternalID)
}
additional_disks = &data_disks
}
Expand Down
20 changes: 10 additions & 10 deletions builder/azure/arm/artifact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func generatedData() map[string]interface{} {
}

func TestArtifactIdVHD(t *testing.T) {
artifact, err := NewArtifact("4085bb15-3644-4641-b9cd-f575918640b4", "https://storage.blob.core.windows.net/", "southcentralus", "Linux", 0, generatedData())
artifact, err := NewArtifact("4085bb15-3644-4641-b9cd-f575918640b4", "packer", "images", "https://storage.blob.core.windows.net/", "southcentralus", "Linux", 0, generatedData())
if err != nil {
t.Fatalf("err=%s", err)
}
Expand Down Expand Up @@ -306,7 +306,7 @@ SharedImageGalleryReplicatedRegions: fake-region-1, fake-region-2
}

func TestArtifactString(t *testing.T) {
artifact, err := NewArtifact("4085bb15-3644-4641-b9cd-f575918640b4", "https://storage.blob.core.windows.net/", "southcentralus", "Linux", 0, generatedData())
artifact, err := NewArtifact("4085bb15-3644-4641-b9cd-f575918640b4", "packer", "images", "https://storage.blob.core.windows.net/", "southcentralus", "Linux", 0, generatedData())
if err != nil {
t.Fatalf("err=%s", err)
}
Expand All @@ -327,16 +327,16 @@ func TestArtifactString(t *testing.T) {
}

func TestAdditionalDiskArtifactString(t *testing.T) {
artifact, err := NewArtifact("4085bb15-3644-4641-b9cd-f575918640b4", "https://storage.blob.core.windows.net/", "southcentralus", "Linux", 1, generatedData())
artifact, err := NewArtifact("4085bb15-3644-4641-b9cd-f575918640b4", "anotherprefix", "anothercontainername", "https://storage.blob.core.windows.net/", "southcentralus", "Linux", 1, generatedData())
if err != nil {
t.Fatalf("err=%s", err)
}

testSubject := artifact.String()
if !strings.Contains(testSubject, "OSDiskUri: https://storage.blob.core.windows.net/system/Microsoft.Compute/Images/images/packer-osDisk.4085bb15-3644-4641-b9cd-f575918640b4.vhd") {
if !strings.Contains(testSubject, "OSDiskUri: https://storage.blob.core.windows.net/system/Microsoft.Compute/Images/anothercontainername/anotherprefix-osDisk.4085bb15-3644-4641-b9cd-f575918640b4.vhd") {
t.Errorf("Expected String() output to contain OSDiskUri")
}
if !strings.Contains(testSubject, "TemplateUri: https://storage.blob.core.windows.net/system/Microsoft.Compute/Images/images/packer-vmTemplate.4085bb15-3644-4641-b9cd-f575918640b4.json") {
if !strings.Contains(testSubject, "TemplateUri: https://storage.blob.core.windows.net/system/Microsoft.Compute/Images/anothercontainername/anotherprefix-vmTemplate.4085bb15-3644-4641-b9cd-f575918640b4.json") {
t.Errorf("Expected String() output to contain TemplateUri")
}
if !strings.Contains(testSubject, "StorageAccountLocation: southcentralus") {
Expand All @@ -345,13 +345,13 @@ func TestAdditionalDiskArtifactString(t *testing.T) {
if !strings.Contains(testSubject, "OSType: Linux") {
t.Errorf("Expected String() output to contain OSType")
}
if !strings.Contains(testSubject, "AdditionalDiskUri (datadisk-1): https://storage.blob.core.windows.net/system/Microsoft.Compute/Images/images/packer-datadisk-1.4085bb15-3644-4641-b9cd-f575918640b4.vhd") {
if !strings.Contains(testSubject, "AdditionalDiskUri (datadisk-1): https://storage.blob.core.windows.net/system/Microsoft.Compute/Images/anothercontainername/anotherprefix-datadisk-0.4085bb15-3644-4641-b9cd-f575918640b4.vhd") {
t.Errorf("Expected String() output to contain AdditionalDiskUri")
}
}

func TestArtifactProperties(t *testing.T) {
testSubject, err := NewArtifact("4085bb15-3644-4641-b9cd-f575918640b4", "https://storage.blob.core.windows.net/", "southcentralus", "Linux", 0, generatedData())
testSubject, err := NewArtifact("4085bb15-3644-4641-b9cd-f575918640b4", "packer", "images", "https://storage.blob.core.windows.net/", "southcentralus", "Linux", 0, generatedData())
if err != nil {
t.Fatalf("err=%s", err)
}
Expand All @@ -371,7 +371,7 @@ func TestArtifactProperties(t *testing.T) {
}

func TestAdditionalDiskArtifactProperties(t *testing.T) {
testSubject, err := NewArtifact("4085bb15-3644-4641-b9cd-f575918640b4", "https://storage.blob.core.windows.net/", "southcentralus", "Linux", 1, generatedData())
testSubject, err := NewArtifact("4085bb15-3644-4641-b9cd-f575918640b4", "packer", "images", "https://storage.blob.core.windows.net/", "southcentralus", "Linux", 1, generatedData())
if err != nil {
t.Fatalf("err=%s", err)
}
Expand All @@ -394,8 +394,8 @@ func TestAdditionalDiskArtifactProperties(t *testing.T) {
if len(*testSubject.AdditionalDisks) != 1 {
t.Errorf("Expected AdditionalDisks to have one additional disk, but got %d", len(*testSubject.AdditionalDisks))
}
if (*testSubject.AdditionalDisks)[0].AdditionalDiskUri != "https://storage.blob.core.windows.net/system/Microsoft.Compute/Images/images/packer-datadisk-1.4085bb15-3644-4641-b9cd-f575918640b4.vhd" {
t.Errorf("Expected additional disk uri to be 'https://storage.blob.core.windows.net/system/Microsoft.Compute/Images/images/packer-datadisk-1.4085bb15-3644-4641-b9cd-f575918640b4.vhd', but got %s", (*testSubject.AdditionalDisks)[0].AdditionalDiskUri)
if (*testSubject.AdditionalDisks)[0].AdditionalDiskUri != "https://storage.blob.core.windows.net/system/Microsoft.Compute/Images/images/packer-datadisk-0.4085bb15-3644-4641-b9cd-f575918640b4.vhd" {
t.Errorf("Expected additional disk uri to be 'https://storage.blob.core.windows.net/system/Microsoft.Compute/Images/images/packer-datadisk-0.4085bb15-3644-4641-b9cd-f575918640b4.vhd', but got %s", (*testSubject.AdditionalDisks)[0].AdditionalDiskUri)
}
}

Expand Down
2 changes: 2 additions & 0 deletions builder/azure/arm/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
ui.Say(fmt.Sprintf("%d", len(b.config.AdditionalDiskSize)))
return NewArtifact(
b.stateBag.Get(constants.ArmBuildVMInternalId).(string),
b.config.CaptureNamePrefix,
b.config.CaptureContainerName,
b.config.storageAccountBlobEndpoint,
b.config.StorageAccount,
b.config.OSType,
Expand Down
Loading