Skip to content

Commit

Permalink
azurerm_client_config - add authenticated_object_idproperty (#4486)
Browse files Browse the repository at this point in the history
fixes #3234
  • Loading branch information
katbyte authored Oct 3, 2019
1 parent 6df5b17 commit 0c85ec8
Show file tree
Hide file tree
Showing 40 changed files with 6,860 additions and 164 deletions.
13 changes: 9 additions & 4 deletions azurerm/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package azurerm

import (
"context"
"fmt"
"time"

Expand Down Expand Up @@ -74,11 +75,14 @@ type ArmClient struct {
// inherit the fields from the parent, so that we should be able to set/access these at either level
clients.Client

clientId string
tenantId string
subscriptionId string
partnerId string
clientId string
tenantId string
subscriptionId string
partnerId string

getAuthenticatedObjectID func(context.Context) (string, error)
usingServicePrincipal bool

environment azure.Environment
skipProviderRegistration bool

Expand Down Expand Up @@ -162,6 +166,7 @@ func getArmClient(authConfig *authentication.Config, skipProviderRegistration bo
partnerId: partnerId,
environment: *env,
usingServicePrincipal: authConfig.AuthenticatedAsAServicePrincipal,
getAuthenticatedObjectID: authConfig.GetAuthenticatedObjectID,
skipProviderRegistration: skipProviderRegistration,
}

Expand Down
25 changes: 21 additions & 4 deletions azurerm/data_source_client_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,31 @@ func dataSourceArmClientConfig() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},

"tenant_id": {
Type: schema.TypeString,
Computed: true,
},

"subscription_id": {
Type: schema.TypeString,
Computed: true,
},
"service_principal_application_id": {

"object_id": {
Type: schema.TypeString,
Computed: true,
},

"service_principal_application_id": {
Type: schema.TypeString,
Computed: true,
Deprecated: "This has been deprecated in favour of the `client_id` property",
},
"service_principal_object_id": {
Type: schema.TypeString,
Computed: true,
Type: schema.TypeString,
Computed: true,
Deprecated: "This has been deprecated in favour of the unified `authenticated_object_id` property",
},
},
}
Expand Down Expand Up @@ -66,12 +76,19 @@ func dataSourceArmClientConfigRead(d *schema.ResourceData, meta interface{}) err
d.Set("subscription_id", client.subscriptionId)

if principal := servicePrincipal; principal != nil {
d.Set("service_principal_application_id", principal.AppID)
d.Set("service_principal_application_id", client.clientId)
d.Set("service_principal_object_id", principal.ObjectID)
} else {
d.Set("service_principal_application_id", "")
d.Set("service_principal_object_id", "")
}

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)
}

return nil
}
1 change: 1 addition & 0 deletions azurerm/data_source_client_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func TestAccDataSourceAzureRMClientConfig_basic(t *testing.T) {
resource.TestCheckResourceAttr(dataSourceName, "client_id", clientId),
resource.TestCheckResourceAttr(dataSourceName, "tenant_id", tenantId),
resource.TestCheckResourceAttr(dataSourceName, "subscription_id", subscriptionId),
testAzureRMClientConfigGUIDAttr(dataSourceName, "object_id"),
testAzureRMClientConfigGUIDAttr(dataSourceName, "service_principal_application_id"),
testAzureRMClientConfigGUIDAttr(dataSourceName, "service_principal_object_id"),
),
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/btubbs/datetime v0.1.0
github.com/davecgh/go-spew v1.1.1
github.com/google/uuid v1.1.1
github.com/hashicorp/go-azure-helpers v0.7.0
github.com/hashicorp/go-azure-helpers v0.9.0
github.com/hashicorp/go-getter v1.3.1-0.20190627223108-da0323b9545e
github.com/hashicorp/go-multierror v1.0.0
github.com/hashicorp/go-uuid v1.0.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ github.com/hashicorp/go-azure-helpers v0.4.1 h1:aEWYW4hxAVVmxmq7nPXGK8F44A6HBXQ4
github.com/hashicorp/go-azure-helpers v0.4.1/go.mod h1:lu62V//auUow6k0IykxLK2DCNW8qTmpm8KqhYVWattA=
github.com/hashicorp/go-azure-helpers v0.7.0 h1:wxGpOyWYp15bjBMeL3pXKP5X3oFLZbThAMcJcU6x4FA=
github.com/hashicorp/go-azure-helpers v0.7.0/go.mod h1:3xdjhbL7qs69rnwxA0UENOzkPJjtTFIRb5aRyrEpbCU=
github.com/hashicorp/go-azure-helpers v0.9.0 h1:KERW4n9AukvQ6kXGJdqXLaR0S2yxH3Xwj+rio/3/uLI=
github.com/hashicorp/go-azure-helpers v0.9.0/go.mod h1:3xdjhbL7qs69rnwxA0UENOzkPJjtTFIRb5aRyrEpbCU=
github.com/hashicorp/go-checkpoint v0.5.0 h1:MFYpPZCnQqQTE18jFwSII6eUQrD/oxMFp3mlgcqk5mU=
github.com/hashicorp/go-checkpoint v0.5.0/go.mod h1:7nfLNL10NsxqO4iWuW6tWW0HjZuDrwkBuEQsVcpCOgg=
github.com/hashicorp/go-cleanhttp v0.5.0 h1:wvCrVc9TjDls6+YGAF2hAifE1E5U1+b4tH6KdvN3Gig=
Expand Down
Loading

0 comments on commit 0c85ec8

Please sign in to comment.