Compare commits

...

8 Commits

Author SHA1 Message Date
hezijie
a39f70e47a set prevent_deletion_if_contains_resources to false 2024-09-14 13:51:29 +08:00
hezijie
a855962fb2 switch to new testing environment 2024-09-14 13:45:38 +08:00
hezijie
784a1aba72 fix broken config 2024-09-14 13:29:00 +08:00
hezijie
1ff77143ef bump azurerm to v3 so we can use oidc 2024-09-14 13:17:14 +08:00
hezijie
521970084e try to fix 201-vmss-packer-jumpbox 2024-09-14 12:30:32 +08:00
hezijie
1b66215af1 try to fix 201-vmss-packer-jumpbox 2024-09-14 12:23:05 +08:00
hezijie
39dcf38e31 try to fix 201-vmss-packer-jumpbox 2024-09-14 11:28:42 +08:00
hezijie
3c3a07e589 try to fix 201-vmss-packer-jumpbox 2024-09-14 11:27:16 +08:00
5 changed files with 37 additions and 26 deletions

View File

@ -17,7 +17,7 @@ jobs:
e2e-check: e2e-check:
runs-on: ubuntu-latest runs-on: ubuntu-latest
environment: environment:
name: acctests name: test
steps: steps:
- name: Checking for Fork - name: Checking for Fork
shell: pwsh shell: pwsh

View File

@ -5,10 +5,10 @@ terraform {
required_providers { required_providers {
azurerm = { azurerm = {
source = "hashicorp/azurerm" source = "hashicorp/azurerm"
version = "~>2.0" version = "~>3.0"
} }
azapi = { azapi = {
source = "Azure/azapi" source = "Azure/azapi"
version = "~> 1.0" version = "~> 1.0"
} }
local = { local = {
@ -27,7 +27,11 @@ terraform {
} }
provider "azurerm" { provider "azurerm" {
features {} features {
resource_group {
prevent_deletion_if_contains_resources = false
}
}
} }
resource "random_pet" "id" {} resource "random_pet" "id" {}
@ -88,20 +92,18 @@ resource "azurerm_lb_backend_address_pool" "bpepool" {
} }
resource "azurerm_lb_probe" "vmss" { resource "azurerm_lb_probe" "vmss" {
resource_group_name = azurerm_resource_group.vmss.name loadbalancer_id = azurerm_lb.vmss.id
loadbalancer_id = azurerm_lb.vmss.id name = "ssh-running-probe"
name = "ssh-running-probe" port = var.application_port
port = var.application_port
} }
resource "azurerm_lb_rule" "lbnatrule" { resource "azurerm_lb_rule" "lbnatrule" {
resource_group_name = azurerm_resource_group.vmss.name
loadbalancer_id = azurerm_lb.vmss.id loadbalancer_id = azurerm_lb.vmss.id
name = "http" name = "http"
protocol = "Tcp" protocol = "Tcp"
frontend_port = var.application_port frontend_port = var.application_port
backend_port = var.application_port backend_port = var.application_port
backend_address_pool_id = azurerm_lb_backend_address_pool.bpepool.id backend_address_pool_ids = [azurerm_lb_backend_address_pool.bpepool.id]
frontend_ip_configuration_name = "PublicIPAddress" frontend_ip_configuration_name = "PublicIPAddress"
probe_id = azurerm_lb_probe.vmss.id probe_id = azurerm_lb_probe.vmss.id
} }
@ -217,7 +219,7 @@ resource "azurerm_network_interface" "jumpbox" {
ip_configuration { ip_configuration {
name = "IPConfiguration" name = "IPConfiguration"
subnet_id = azurerm_subnet.vmss.id subnet_id = azurerm_subnet.vmss.id
private_ip_address_allocation = "dynamic" private_ip_address_allocation = "Dynamic"
public_ip_address_id = azurerm_public_ip.jumpbox.id public_ip_address_id = azurerm_public_ip.jumpbox.id
} }

View File

@ -8,21 +8,21 @@ packer {
} }
variable client_id { variable client_id {
type = string type = string
default = null default = null
} }
variable client_secret { variable client_secret {
type = string type = string
default = null default = null
} }
variable subscription_id { variable subscription_id {
type = string type = string
default = null default = null
} }
variable tenant_id { variable tenant_id {
type = string type = string
default = null default = null
} }
@ -35,6 +35,15 @@ variable "image_resource_group_name" {
default = "myPackerImages" default = "myPackerImages"
} }
variable "oidc_request_url" {
default = null
}
variable "oidc_request_token" {
default = null
}
# arm builder
source "azure-arm" "builder" { source "azure-arm" "builder" {
client_id = var.client_id client_id = var.client_id
client_secret = var.client_secret client_secret = var.client_secret
@ -47,8 +56,10 @@ source "azure-arm" "builder" {
os_type = "Linux" os_type = "Linux"
subscription_id = var.subscription_id subscription_id = var.subscription_id
tenant_id = var.tenant_id tenant_id = var.tenant_id
oidc_request_url = var.oidc_request_url
oidc_request_token = var.oidc_request_token
vm_size = "Standard_DS2_v2" vm_size = "Standard_DS2_v2"
azure_tags = { azure_tags = {
"dept" : "Engineering", "dept" : "Engineering",
"task" : "Image deployment", "task" : "Image deployment",
} }

View File

@ -21,7 +21,7 @@ variable "location" {
variable "tags" { variable "tags" {
description = "Map of the tags to use for the resources that are deployed" description = "Map of the tags to use for the resources that are deployed"
type = map(string) type = map(string)
default = { default = {
environment = "codelab" environment = "codelab"
} }
} }

View File

@ -27,10 +27,6 @@ var speicalTests = map[string]func(*testing.T){
func Test_Quickstarts(t *testing.T) { func Test_Quickstarts(t *testing.T) {
t.Parallel() t.Parallel()
msiId := os.Getenv("MSI_ID")
if msiId != "" {
_ = os.Setenv("TF_VAR_msi_id", msiId)
}
input := os.Getenv("CHANGED_FOLDERS") input := os.Getenv("CHANGED_FOLDERS")
folders := strings.Split(input, ",") folders := strings.Split(input, ",")
if input == "" { if input == "" {
@ -115,22 +111,24 @@ func test201VmssPackerJumpbox(t *testing.T) {
packerVars := map[string]string{ packerVars := map[string]string{
"image_resource_group_name": imageResourceGroupName, "image_resource_group_name": imageResourceGroupName,
} }
useMsi := false
if clientId := os.Getenv("ARM_CLIENT_ID"); clientId != "" { if clientId := os.Getenv("ARM_CLIENT_ID"); clientId != "" {
packerVars["client_id"] = clientId packerVars["client_id"] = clientId
} }
if os.Getenv("MSI_ID") != "" {
useMsi = true
}
if clientSecret := os.Getenv("ARM_CLIENT_SECRET"); clientSecret != "" { if clientSecret := os.Getenv("ARM_CLIENT_SECRET"); clientSecret != "" {
packerVars["client_secret"] = clientSecret packerVars["client_secret"] = clientSecret
} }
if subscriptionId := os.Getenv("ARM_SUBSCRIPTION_ID"); subscriptionId != "" { if subscriptionId := os.Getenv("ARM_SUBSCRIPTION_ID"); subscriptionId != "" {
packerVars["subscription_id"] = subscriptionId packerVars["subscription_id"] = subscriptionId
} }
if tenantId := os.Getenv("ARM_TENANT_ID"); !useMsi && tenantId != "" { if tenantId := os.Getenv("ARM_TENANT_ID"); tenantId != "" {
packerVars["tenant_id"] = tenantId packerVars["tenant_id"] = tenantId
} }
if oidcRequestToken := os.Getenv("ARM_OIDC_REQUEST_TOKEN"); oidcRequestToken != "" {
packerVars["oidc_request_token"] = oidcRequestToken
}
if oidcRequestUrl := os.Getenv("ARM_OIDC_REQUEST_URL"); oidcRequestUrl != "" {
packerVars["oidc_request_url"] = oidcRequestUrl
}
patches := gomonkey.ApplyFunc(shell.RunCommandAndGetOutputE, func(t terratest.TestingT, command shell.Command) (string, error) { patches := gomonkey.ApplyFunc(shell.RunCommandAndGetOutputE, func(t terratest.TestingT, command shell.Command) (string, error) {
output, err := shell.RunCommandAndGetStdOutE(t, command) output, err := shell.RunCommandAndGetStdOutE(t, command)
if err != nil { if err != nil {