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

make subscription_id configurable in cli #465

Merged
merged 1 commit into from
Jan 27, 2025

Conversation

mogrogan
Copy link
Contributor

@mogrogan mogrogan commented Jan 23, 2025

This changes will make the plugin use the subscription_id at the root even when using the cli auth mode

2 packer build were done to test the feature:

packer {
  required_plugins {
    azure = {
      source  = "github.com/hashicorp/azure"
      version = "~> 2"
    }
  }
}

source "azure-arm" "ubuntu" {
  use_azure_cli_auth = true

  # subscription_id = "eeb6d260-e6c0-4ec6-83e0-492c8272798c"

  managed_image_name                = "ubuntu-20-04-{{timestamp}}"
  managed_image_resource_group_name = "packer_test"

  os_type         = "Linux"
  image_publisher = "Canonical"
  image_offer     = "0001-com-ubuntu-server-focal"
  image_sku       = "20_04-lts"

  location = "East US"
  vm_size  = "Standard_DS2_v2"

  azure_tags = {
    Environment = "Dev"
    Created_By  = "Packer"
  }
}

build {
  sources = ["source.azure-arm.ubuntu"]

  provisioner "shell" {
    inline = [
      "echo 'Installing updates...'",
      "sudo apt-get update",
      "sudo apt-get upgrade -y",
      "sudo apt-get install -y nginx",
      "echo 'Installation complete'"
    ]
  }
}

and ...

packer {
  required_plugins {
    azure = {
      source  = "github.com/hashicorp/azure"
      version = "~> 2"
    }
  }
}

source "azure-arm" "ubuntu" {
  use_azure_cli_auth = true

  subscription_id = "eeb6d260-e6c0-4ec6-83e0-492c8272798c"

  managed_image_name                = "ubuntu-20-04-{{timestamp}}"
  managed_image_resource_group_name = "packer_test"

  os_type         = "Linux"
  image_publisher = "Canonical"
  image_offer     = "0001-com-ubuntu-server-focal"
  image_sku       = "20_04-lts"

  location = "East US"
  vm_size  = "Standard_DS2_v2"

  azure_tags = {
    Environment = "Dev"
    Created_By  = "Packer"
  }
}

build {
  sources = ["source.azure-arm.ubuntu"]

  provisioner "shell" {
    inline = [
      "echo 'Installing updates...'",
      "sudo apt-get update",
      "sudo apt-get upgrade -y",
      "sudo apt-get install -y nginx",
      "echo 'Installation complete'"
    ]
  }
}

both build were successful and we have both images in respective subscription

image

image

Closes #461

@mogrogan mogrogan changed the title make subscription_id configurable in cli make subscription_id configurable in cli Jan 23, 2025
@mogrogan mogrogan force-pushed the configurable_subscription_id_cli_mode branch from f1cdf5c to 84f72ca Compare January 23, 2025 20:16
@mogrogan mogrogan marked this pull request as ready for review January 27, 2025 19:52
@mogrogan mogrogan requested a review from a team as a code owner January 27, 2025 19:52
@mogrogan mogrogan force-pushed the configurable_subscription_id_cli_mode branch from 84f72ca to 366f237 Compare January 27, 2025 19:56
@JenGoldstrich
Copy link
Contributor

Nice work @mogrogan thanks for your first contribution to the Azure plugin!

@JenGoldstrich JenGoldstrich merged commit c842f2a into main Jan 27, 2025
12 checks passed
@JenGoldstrich JenGoldstrich deleted the configurable_subscription_id_cli_mode branch January 27, 2025 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Explicit setting of subscription_id is ignored when using use_azure_cli_auth
2 participants