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

new resource azurerm_graph_account #22334

Merged
merged 11 commits into from Jul 18, 2023
Merged

Conversation

teowa
Copy link
Contributor

@teowa teowa commented Jun 30, 2023

reference:


resource "azurerm_graph_account" "test" {
name = "acctesta-%[2]d"
app_id = azuread_application.test.application_id
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this resource is depend on an azuread_application, however through my local test the resource creation may fail occationally with error even after the ad app is created: performing AccountsCreateAndUpdate: unexpected status 400 with error: BadRequest: The application was not found in this tenant.. The service team told that this is hard to change and advices to use a predefined azure ad app, can we do this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a common issue particularly when crossing service boundaries such as this. We can use the calling principal to work around this for now - you can grab this from the environment variable ARM_CLIENT_ID in the test function, see the following suggestion.

Type: pluginsdk.TypeString,
},
"resource_group_name": commonschema.ResourceGroupName(),
"app_id": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this to application_id to align with AzureAD resources


resource "azurerm_graph_account" "test" {
name = "acctesta-%[2]d"
app_id = azuread_application.test.application_id
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a common issue particularly when crossing service boundaries such as this. We can use the calling principal to work around this for now - you can grab this from the environment variable ARM_CLIENT_ID in the test function, see the following suggestion.


resource "azurerm_graph_account" "test" {
name = "acctesta-%[2]d"
app_id = azuread_application.test.application_id
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
app_id = azuread_application.test.application_id
application_id = "%[3]s"

app_id = azuread_application.test.application_id
resource_group_name = azurerm_resource_group.test.name
}
`, r.template(data), data.RandomInteger)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`, r.template(data), data.RandomInteger)
`, r.template(data), data.RandomInteger, clientId)

@teowa
Copy link
Contributor Author

teowa commented Jul 4, 2023

Hi @manicminer , thanks for reviewing this. I have modified the testcases, but we cannot create two graph account for single ad application, so I have made the test running in serial.

TF_ACC=1 go test -v ./internal/services/graph -parallel 50 -test.run=TestAccGraph -timeout 1440m -ldflags="-X=github.com/hashicorp/terraform-provider-azurerm/version.ProviderVersion=acc"
=== RUN   TestAccGraphAccount
=== RUN   TestAccGraphAccount/account
=== RUN   TestAccGraphAccount/account/requiresImport
=== RUN   TestAccGraphAccount/account/basic
=== RUN   TestAccGraphAccount/account/update
=== RUN   TestAccGraphAccount/account/complete
--- PASS: TestAccGraphAccount (586.13s)
    --- PASS: TestAccGraphAccount/account (586.13s)
        --- PASS: TestAccGraphAccount/account/requiresImport (150.75s)
        --- PASS: TestAccGraphAccount/account/basic (144.59s)
        --- PASS: TestAccGraphAccount/account/update (150.11s)
        --- PASS: TestAccGraphAccount/account/complete (140.68s)
PASS
ok      github.com/hashicorp/terraform-provider-azurerm/internal/services/graph 587.394s

@teowa
Copy link
Contributor Author

teowa commented Jul 12, 2023

Hi @manicminer, kindly ping. The service team is asking for this.

@manicminer
Copy link
Member

Apologies @teowa, will look at this today

Copy link
Member

@manicminer manicminer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @teowa, this mostly LGTM. If you can take a look at the comments below, then this should be good to merge.

Tests look good for me:

Screenshot 2023-07-13 at 13 04 23

"name": {
ForceNew: true,
Required: true,
Type: pluginsdk.TypeString,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should validate this property

Comment on lines 96 to 100
Location: pointer.To(location.Normalize("global")),
Properties: graphservicesprods.AccountResourceProperties{
AppId: config.ApplicationId,
},
Tags: tags.Expand(config.Tags),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we tidy this up? i.e. move Properties to the end and align the others

Comment on lines 138 to 140
ApplicationId: model.Properties.AppId,
Name: id.AccountName, ResourceGroupName: id.ResourceGroupName,
Tags: tags.Flatten(model.Tags),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, can this be tidied up (one field per line, all aligned for readability)

Copy link
Member

@manicminer manicminer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making the changes, this LGTM 👍

@manicminer manicminer added this to the v3.66.0 milestone Jul 18, 2023
@manicminer manicminer merged commit 08c72f7 into hashicorp:main Jul 18, 2023
24 checks passed
manicminer added a commit that referenced this pull request Jul 18, 2023
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.

None yet

2 participants