github.com/raghuse92/packer@v1.3.2/post-processor/vagrant/azure.go (about) 1 package vagrant 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/hashicorp/packer/packer" 8 ) 9 10 type AzureProvider struct{} 11 12 func (p *AzureProvider) KeepInputArtifact() bool { 13 return true 14 } 15 16 func (p *AzureProvider) Process(ui packer.Ui, artifact packer.Artifact, dir string) (vagrantfile string, metadata map[string]interface{}, err error) { 17 // Create the metadata 18 metadata = map[string]interface{}{"provider": "azure"} 19 20 var AzureImageProps map[string]string 21 AzureImageProps = make(map[string]string) 22 23 // HACK(double16): It appears we can not access the Azure Artifact directly, so parse String() 24 artifactString := artifact.String() 25 ui.Message(fmt.Sprintf("artifact string: '%s'", artifactString)) 26 lines := strings.Split(artifactString, "\n") 27 for l := 0; l < len(lines); l++ { 28 split := strings.Split(lines[l], ": ") 29 if len(split) > 1 { 30 AzureImageProps[strings.TrimSpace(split[0])] = strings.TrimSpace(split[1]) 31 } 32 } 33 ui.Message(fmt.Sprintf("artifact string parsed: %+v", AzureImageProps)) 34 35 if AzureImageProps["ManagedImageId"] != "" { 36 vagrantfile = fmt.Sprintf(managedImageVagrantfile, AzureImageProps["ManagedImageLocation"], AzureImageProps["ManagedImageId"]) 37 } else if AzureImageProps["OSDiskUri"] != "" { 38 vagrantfile = fmt.Sprintf(vhdVagrantfile, AzureImageProps["StorageAccountLocation"], AzureImageProps["OSDiskUri"], AzureImageProps["OSType"]) 39 } else { 40 err = fmt.Errorf("No managed image nor VHD URI found in artifact: %s", artifactString) 41 return 42 } 43 return 44 } 45 46 var managedImageVagrantfile = ` 47 Vagrant.configure("2") do |config| 48 config.vm.provider :azure do |azure, override| 49 azure.location = "%s" 50 azure.vm_managed_image_id = "%s" 51 override.winrm.transport = :ssl 52 override.winrm.port = 5986 53 end 54 end 55 ` 56 57 var vhdVagrantfile = ` 58 Vagrant.configure("2") do |config| 59 config.vm.provider :azure do |azure, override| 60 azure.location = "%s" 61 azure.vm_vhd_uri = "%s" 62 azure.vm_operating_system = "%s" 63 override.winrm.transport = :ssl 64 override.winrm.port = 5986 65 end 66 end 67 `