Skip to content

Commit

Permalink
azurerm_stream_analytics_output_powerbi - support for `token_user_p…
Browse files Browse the repository at this point in the history
…rincipal_name` and `token_user_display_name` properties (#18117)
  • Loading branch information
jiaweitao001 authored Aug 30, 2022
1 parent 52b53dc commit bf81809
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ type OutputPowerBIResource struct{}
var _ sdk.ResourceWithCustomImporter = OutputPowerBIResource{}

type OutputPowerBIResourceModel struct {
Name string `tfschema:"name"`
StreamAnalyticsJob string `tfschema:"stream_analytics_job_id"`
DataSet string `tfschema:"dataset"`
Table string `tfschema:"table"`
GroupID string `tfschema:"group_id"`
GroupName string `tfschema:"group_name"`
Name string `tfschema:"name"`
StreamAnalyticsJob string `tfschema:"stream_analytics_job_id"`
DataSet string `tfschema:"dataset"`
Table string `tfschema:"table"`
GroupID string `tfschema:"group_id"`
GroupName string `tfschema:"group_name"`
TokenUserPrincipalName string `tfschema:"token_user_principal_name"`
TokenUserDisplayName string `tfschema:"token_user_display_name"`
}

func (r OutputPowerBIResource) Arguments() map[string]*pluginsdk.Schema {
Expand Down Expand Up @@ -68,6 +70,18 @@ func (r OutputPowerBIResource) Arguments() map[string]*pluginsdk.Schema {
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"token_user_principal_name": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"token_user_display_name": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
},
}
}

Expand Down Expand Up @@ -115,9 +129,18 @@ func (r OutputPowerBIResource) Create() sdk.ResourceFunc {
Table: utils.String(model.Table),
GroupID: utils.String(model.GroupID),
GroupName: utils.String(model.GroupName),
RefreshToken: utils.String("someRefreshToken"), // A valid refresh token is currently only obtainable via the Azure Portal. Put a dummy string value here when creating the data source and then going to the Azure Portal to authenticate the data source which will update this property with a valid refresh token.
AuthenticationMode: streamanalytics.AuthenticationMode("Msi"), // Set authentication mode as "Msi" here since other modes requires params obtainable from portal only.
}

if model.TokenUserDisplayName != "" {
powerbiOutputProps.TokenUserDisplayName = utils.String(model.TokenUserDisplayName)
}

if model.TokenUserPrincipalName != "" {
powerbiOutputProps.TokenUserPrincipalName = utils.String(model.TokenUserPrincipalName)
}

props := streamanalytics.Output{
Name: utils.String(model.Name),
OutputProperties: &streamanalytics.OutputProperties{
Expand Down Expand Up @@ -178,6 +201,16 @@ func (r OutputPowerBIResource) Update() sdk.ResourceFunc {
dataSourceProps.GroupID = &state.GroupID
}

if d.HasChange("token_user_principal_name") {
needUpdateDataSourceProps = true
dataSourceProps.TokenUserPrincipalName = &state.TokenUserPrincipalName
}

if d.HasChange("token_user_display_name") {
needUpdateDataSourceProps = true
dataSourceProps.TokenUserDisplayName = &state.TokenUserDisplayName
}

if !needUpdateDataSourceProps {
return nil
}
Expand Down Expand Up @@ -249,6 +282,9 @@ func (r OutputPowerBIResource) Read() sdk.ResourceFunc {
state.GroupName = *v.GroupName
}

state.TokenUserDisplayName = metadata.ResourceData.Get("token_user_display_name").(string)
state.TokenUserPrincipalName = metadata.ResourceData.Get("token_user_principal_name").(string)

return metadata.Encode(&state)
}
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ func TestAccStreamAnalyticsOutputPowerBI_update(t *testing.T) {
})
}

func TestAccStreamAnalyticsOutputPowerBI_complete(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_stream_analytics_output_powerbi", "test")
r := StreamAnalyticsOutputPowerBIResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.complete(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
})
}

func (r StreamAnalyticsOutputPowerBIResource) basic(data acceptance.TestData) string {
template := r.template(data)
return fmt.Sprintf(`
Expand Down Expand Up @@ -99,6 +113,24 @@ resource "azurerm_stream_analytics_output_powerbi" "test" {
`, template, data.RandomInteger)
}

func (r StreamAnalyticsOutputPowerBIResource) complete(data acceptance.TestData) string {
template := r.template(data)
return fmt.Sprintf(`
%s
resource "azurerm_stream_analytics_output_powerbi" "test" {
name = "acctestoutput-%d"
stream_analytics_job_id = azurerm_stream_analytics_job.test.id
dataset = "complete-dataset"
table = "complete-table"
group_id = "e18ff5df-fb66-4f6d-8f27-88c4dcbfc002"
group_name = "some-test-group-name"
token_user_principal_name = "bobsmith@contoso.com"
token_user_display_name = "Bob Smith"
}
`, template, data.RandomInteger)
}

func (r StreamAnalyticsOutputPowerBIResource) template(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/stream_analytics_output_powerbi.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ The following arguments are supported:

* `group_name` - (Required) The name of the Power BI group. Use this property to help remember which specific Power BI group id was used.

* `token_user_principal_name` - (Optional) The user principal name (UPN) of the user that was used to obtain the refresh token.

* `token_user_display_name` - (Optional) The user display name of the user that was used to obtain the refresh token.

## Timeouts

The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/language/resources/syntax#operation-timeouts) for certain actions:
Expand Down

0 comments on commit bf81809

Please sign in to comment.