From 944ebbe015d2459f81406973f116e10cde17e82f Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Mon, 28 Oct 2019 08:17:57 -0700 Subject: [PATCH 1/2] Fix crash when MSI auth is used --- azurerm/data_source_client_config.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/azurerm/data_source_client_config.go b/azurerm/data_source_client_config.go index 9477877dda0a..d9553ea72023 100644 --- a/azurerm/data_source_client_config.go +++ b/azurerm/data_source_client_config.go @@ -90,10 +90,14 @@ func dataSourceArmClientConfigRead(d *schema.ResourceData, meta interface{}) err } d.Set("object_id", "") - if v, err := client.getAuthenticatedObjectID(ctx); err != nil { - return fmt.Errorf("Error getting authenticated object ID: %v", err) - } else { - d.Set("object_id", v) + + // TODO remove this when we confirm that MSI no longer returns nil with getAuthenticatedObjectID + if client.getAuthenticatedObjectID != nil { + if v, err := client.getAuthenticatedObjectID(ctx); err != nil { + return fmt.Errorf("Error getting authenticated object ID: %v", err) + } else { + d.Set("object_id", v) + } } return nil From f51339d11c572256385666459ad3e4c7214d013b Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Mon, 28 Oct 2019 08:25:24 -0700 Subject: [PATCH 2/2] Address review --- azurerm/data_source_client_config.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/azurerm/data_source_client_config.go b/azurerm/data_source_client_config.go index d9553ea72023..de2dffc32cc5 100644 --- a/azurerm/data_source_client_config.go +++ b/azurerm/data_source_client_config.go @@ -92,13 +92,15 @@ func dataSourceArmClientConfigRead(d *schema.ResourceData, meta interface{}) err d.Set("object_id", "") // TODO remove this when we confirm that MSI no longer returns nil with getAuthenticatedObjectID + objectId := "" if client.getAuthenticatedObjectID != nil { - if v, err := client.getAuthenticatedObjectID(ctx); err != nil { + v, err := client.getAuthenticatedObjectID(ctx) + if err != nil { return fmt.Errorf("Error getting authenticated object ID: %v", err) - } else { - d.Set("object_id", v) } + objectId = v } + d.Set("object_id", objectId) return nil }