Skip to content

Commit

Permalink
Add Subscription ID and Tenant ID to build variables
Browse files Browse the repository at this point in the history
  • Loading branch information
JenGoldstrich committed Aug 23, 2024
1 parent b7642d6 commit 85725c8
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .web-docs/components/builder/arm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,10 @@ The generated variables available for this builder are:
shared images the resulting name will point to the actual source used to create the said version.
building the AMI.

- `SubscriptionID` - The ID of the Azure Subscription where the build takes place.

- `TenantID` - The ID of the Azure Tenant where the build takes place.

Usage example:

**HCL2**
Expand Down
6 changes: 5 additions & 1 deletion builder/azure/arm/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
b.setTemplateParameters(b.stateBag)
b.setImageParameters(b.stateBag)

generatedDataKeys := []string{"SourceImageName"}
generatedDataKeys := []string{"SourceImageName", "TenantID", "SubscriptionID"}

return generatedDataKeys, warnings, nil
}
Expand Down Expand Up @@ -390,6 +390,10 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
)
}
steps = append(steps,
&StepSetGeneratedData{
GeneratedData: generatedData,
Config: &b.config,
},
NewStepValidateTemplate(azureClient, ui, &b.config, deploymentName, getVirtualMachineDeploymentFunction),
NewStepDeployTemplate(azureClient, ui, &b.config, deploymentName, getVirtualMachineDeploymentFunction, VirtualMachineTemplate),
NewStepGetIPAddress(azureClient, ui, endpointConnectType),
Expand Down
27 changes: 27 additions & 0 deletions builder/azure/arm/step_set_generated_data.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package arm

import (
"context"

"github.com/hashicorp/packer-plugin-sdk/multistep"
"github.com/hashicorp/packer-plugin-sdk/packerbuilderdata"
)

type StepSetGeneratedData struct {
GeneratedData *packerbuilderdata.GeneratedData
Config *Config
}

func (s *StepSetGeneratedData) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {

s.GeneratedData.Put("TenantID", s.Config.ClientConfig.TenantID)
s.GeneratedData.Put("SubscriptionID", s.Config.ClientConfig.SubscriptionID)
return multistep.ActionContinue
}

func (s *StepSetGeneratedData) Cleanup(state multistep.StateBag) {
// No cleanup...
}
4 changes: 4 additions & 0 deletions docs/builders/arm.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ The generated variables available for this builder are:
shared images the resulting name will point to the actual source used to create the said version.
building the AMI.

- `SubscriptionID` - The ID of the Azure Subscription where the build takes place.

- `TenantID` - The ID of the Azure Tenant where the build takes place.

Usage example:

**HCL2**
Expand Down

0 comments on commit 85725c8

Please sign in to comment.