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_fabric_capacity #28080

Merged
merged 6 commits into from
Dec 10, 2024

Conversation

sinbai
Copy link
Contributor

@sinbai sinbai commented Nov 21, 2024

Community Note

  • Please vote on this PR by adding a 👍 reaction to the original PR to help the community and maintainers prioritize for review
  • Please do not leave comments along the lines of "+1", "me too" or "any updates", they generate extra noise for PR followers and do not help prioritize for review

Description

New resource azurerm_fabric_capacity.

Swagger: https://github.com/Azure/azure-rest-api-specs/blob/fc215e47785166d4c1103909380705a2dfd06a55/specification/fabric/resource-manager/Microsoft.Fabric/stable/2023-11-01/fabric.json#L303

PR Checklist

  • I have followed the guidelines in our Contributing Documentation.
  • I have checked to ensure there aren't other open Pull Requests for the same update/change.
  • I have checked if my changes close any open issues. If so please include appropriate closing keywords below.
  • I have updated/added Documentation as required written in a helpful and kind way to assist users that may be unfamiliar with the resource / data source.
  • I have used a meaningful PR title to help maintainers and other users understand this change and help prevent duplicate work.
    For example: “resource_name_here - description of change e.g. adding property new_property_name_here

Changes to existing Resource / Data Source

  • I have added an explanation of what my changes do and why I'd like you to include them (This may be covered by linking to an issue above, but may benefit from additional explanation).
  • I have written new tests for my resource or datasource changes & updated any relevent documentation.
  • I have successfully run tests with my changes locally. If not, please provide details on testing challenges that prevented you running the tests.
  • (For changes that include a state migration only). I have manually tested the migration path between relevant versions of the provider.

Testing

  • My submission includes Test coverage as described in the Contribution Guide and the tests pass. (if this is not possible for any reason, please include details of why you did or could not add test coverage)

PASS: TestAccFabricFabricCapacity_basic (323.79s)
PASS: TestAccFabricFabricCapacity_requiresImport (215.83s)
PASS: TestAccFabricFabricCapacity_update (551.16s)
PASS: TestAccFabricFabricCapacity_complete (315.63s)

Change Log

Below please provide what should go into the changelog (if anything) conforming to the Changelog Format documented here.

  • New Resource : azurerm_fabric_capacity

This is a (please select all that apply):

  • Bug Fix
  • New Feature (ie adding a service, resource, or data source)
  • Enhancement
  • Breaking Change

Copy link
Contributor

@ms-zhenhua ms-zhenhua left a comment

Choose a reason for hiding this comment

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

Hi @sinbai,

Thanks for this PR - I've taken a look through and left some comments inline. If we can fix those up, this should be good to go 👍

func NewClient(o *common.ClientOptions) (*Client, error) {
fabricCapacitiesClient, err := fabriccapacities.NewFabricCapacitiesClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building fabric client: %+v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return nil, fmt.Errorf("building fabric client: %+v", err)
return nil, fmt.Errorf("building fabric client: %+v", err)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Required: true,
ForceNew: true,
ValidateFunc: validation.StringMatch(
regexp.MustCompile(`^[a-z]([a-z\d]{1,61}[a-z\d])$`),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
regexp.MustCompile(`^[a-z]([a-z\d]{1,61}[a-z\d])$`),
regexp.MustCompile(`^[a-z]([a-z\d]{2,62})$`),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

"administration_members": {
Type: pluginsdk.TypeList,
Optional: true,
MaxItems: 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

each instance can have only 1 administration member ?

Choose a reason for hiding this comment

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

@ms-zhenhua @sinbai Fabric Capacity can have multiple admin members (UPNs for users, GUIDs for Service Principals)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

}

if len(model.AdministrationMembers) == 0 {
return fmt.Errorf("`administration_members` is required when creating a fabric capacity")
Copy link
Contributor

Choose a reason for hiding this comment

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

why not set administration_members as Required and require at least one member?

Choose a reason for hiding this comment

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

administration_members should be required. At least one admin member is expected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Set administration_members to Optional and add a required check in create function. This is because after verifying the behavior of the API, it was found that administration_members is required when creating resource, but administration_members can be unspecified or cleared when updating resource. In addition, administration_members can also be deleted on the Azure Portal.

Copy link
Member

Choose a reason for hiding this comment

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

What happens when we update the resource to delete administration_members, is this resource still manageable/usable in the Portal or via Terraform?


properties.Properties.Administration = pointer.From(expandCapacityAdministrationModel(model.AdministrationMembers))

properties.Sku = pointer.From(expandSkuModel(model.Sku))
Copy link
Contributor

@ms-zhenhua ms-zhenhua Nov 25, 2024

Choose a reason for hiding this comment

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

seems it can be put where initialize properties

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

}
}

func expandCapacityAdministrationModel(inputList []string) *fabriccapacities.CapacityAdministration {
Copy link
Contributor

Choose a reason for hiding this comment

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

expand and flatten should appear in pair. Shall we directly put this logic in Create/Update ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

`, template, data.RandomInteger, data.Locations.Primary)
}

func (r FabricFabricCapacityResource) update(data acceptance.TestData) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

does it make sense to remove all administration_members?

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 test is added because the API allows to remove all administration_members and this is also allowed on the Azure Portal.

})
}

func TestAccFabricFabricCapacity_update(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggest add complete -> basic -> complete to test add/remove properties

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

sorry, I may not say it clearly. The update testcase should be complete -> update -> basic -> complete. complete -> update will test updating optional properties. update -> basic will test removing optional properties and basic -> complete will test adding optional properties

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.


* `name` - (Required) The name of the SKU to use for the Fabric Capacity.

* `tier` - (Required) The tier of the SKU to use for the Fabric Capacity. Possible value is `Fabric`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* `tier` - (Required) The tier of the SKU to use for the Fabric Capacity. Possible value is `Fabric`.
* `tier` - (Required) The tier of the SKU to use for the Fabric Capacity. The only possible value is `Fabric`.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.


## Import

Fabric Capacity can be imported using the `resource id`, e.g.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Fabric Capacity can be imported using the `resource id`, e.g.
Fabric Capacities can be imported using the `resource id`, e.g.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@sinbai
Copy link
Contributor Author

sinbai commented Nov 27, 2024

Hi @sinbai,

Thanks for this PR - I've taken a look through and left some comments inline. If we can fix those up, this should be good to go 👍

Hi @ms-zhenhua thanks for your feedback. I have fixed/replied the comments. Could you please take another look?

Copy link
Contributor

@ms-zhenhua ms-zhenhua 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 the update. LGTM~

@sinbai sinbai marked this pull request as ready for review November 27, 2024 08:24
@sinbai sinbai requested a review from a team as a code owner November 27, 2024 08:24
@sinbai
Copy link
Contributor Author

sinbai commented Nov 29, 2024

Thanks @sinbai and @ms-zhenhua for the review.

Overall this looks good, could you take a look at the questions and comments left in-line?

Hi @stephybun thanks for your time and feedback. I have fixed/replied the comments, could you please take another look?

For What happens when we update the resource to delete administration_members, is this resource still manageable/usable in the Portal or via Terraform?, the answer is yes. Both Portal and terraform could continue to manage after deleting administration_members.

Copy link
Member

@stephybun stephybun left a comment

Choose a reason for hiding this comment

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

Thanks @sinbai. One minor comment that @ms-zhenhua pointed out about the tests needs to be fixed up, but then this should be good to go.

Comment on lines 102 to 103
client := clients.Fabric.FabricCapacitiesClient
resp, err := client.Get(ctx, *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
client := clients.Fabric.FabricCapacitiesClient
resp, err := client.Get(ctx, *id)
resp, err := clients.Fabric.FabricCapacitiesClient(ctx, *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.

Fixed.

Comment on lines 105 to 107
if response.WasNotFound(resp.HttpResponse) {
return pointer.To(false), nil
}
Copy link
Member

Choose a reason for hiding this comment

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

That's right, thanks for pointing that out @ms-zhenhua

@sinbai
Copy link
Contributor Author

sinbai commented Dec 2, 2024

Thanks @sinbai. One minor comment that @ms-zhenhua pointed out about the tests needs to be fixed up, but then this should be good to go.

Hi @stephybun the comment pointed out by Zhenhua have been fixed along with the removal of the resource not found comment, see below for details. Could you please take another look?
image

Comment on lines 16 to 18
type FabricFabricCapacityResource struct{}

func TestAccFabricFabricCapacity_basic(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Just noticed the naming of this, I don't think it's necessary to repeat the service name here..

Please rename the remaining tests

Suggested change
type FabricFabricCapacityResource struct{}
func TestAccFabricFabricCapacity_basic(t *testing.T) {
type FabricCapacityResource struct{}
func TestAccFabricCapacity_basic(t *testing.T) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your feedback, fixed.


* `sku` - (Required) A `sku` block as defined below.

* `administration_members` - (Optional) An array of administrator user identities. The member must be a member user or a service principal.
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 qualify this as

Suggested change
* `administration_members` - (Optional) An array of administrator user identities. The member must be a member user or a service principal.
* `administration_members` - (Optional) An array of administrator user identities. The member must be an Entra member user or a service principal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Member

@stephybun stephybun left a comment

Choose a reason for hiding this comment

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

Last thing @sinbai, we can't seem to run the tests in TC:

------- Stdout: -------
=== RUN   TestAccFabricFabricCapacity_basic
=== PAUSE TestAccFabricFabricCapacity_basic
=== CONT  TestAccFabricFabricCapacity_basic
    testcase.go:173: Step 1/3 error: Error running apply: exit status 1
        Error: creating Capacity (Subscription: "*******"
        Resource Group Name: "acctest-rg-241203102435562466"
        Capacity Name: "acctestffc241203102435562466"): performing CreateOrUpdate: unexpected status 400 (400 Bad Request) with error: BadRequest: Tenant '*******' wasn't recognized by Microsoft Fabric. Sign up for Microsoft Fabric and try again.

It looks like we can only sign up using one of our user accounts. Can you ask the service team how can proceed here to get our tenant registered without signing up with our a specific user account?

administration_members = [data.azurerm_client_config.current.object_id]

sku {
name = "F32"
Copy link
Member

Choose a reason for hiding this comment

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

Also why aren't we using a cheaper sku here like F2?

F32 can cost up to 5139 USD a month if the test fails or there's a problem with deletion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

administration_members = []

sku {
name = "F64"
Copy link
Member

Choose a reason for hiding this comment

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

Likewise here, there are cheaper skus available like F2/F4/F6

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@sinbai
Copy link
Contributor Author

sinbai commented Dec 4, 2024

Last thing @sinbai, we can't seem to run the tests in TC:

------- Stdout: -------
=== RUN   TestAccFabricFabricCapacity_basic
=== PAUSE TestAccFabricFabricCapacity_basic
=== CONT  TestAccFabricFabricCapacity_basic
    testcase.go:173: Step 1/3 error: Error running apply: exit status 1
        Error: creating Capacity (Subscription: "*******"
        Resource Group Name: "acctest-rg-241203102435562466"
        Capacity Name: "acctestffc241203102435562466"): performing CreateOrUpdate: unexpected status 400 (400 Bad Request) with error: BadRequest: Tenant '*******' wasn't recognized by Microsoft Fabric. Sign up for Microsoft Fabric and try again.

It looks like we can only sign up using one of our user accounts. Can you ask the service team how can proceed here to get our tenant registered without signing up with our a specific user account?

Hi @stephybun sure. However, I found the documentation for enabling tenant for microsoft fabric. Could you please try to follow the documentation before asking the service team?

@stephybun
Copy link
Member

stephybun commented Dec 5, 2024

@sinbai we followed the documentation but the requesting user must be signed up as well as enabled on the Tenant. The signup link is bound to an Entra ID user, we need to be able to configure for an SP.

image

image

@sinbai
Copy link
Contributor Author

sinbai commented Dec 6, 2024

@sinbai we followed the documentation but the requesting user must be signed up as well as enabled on the Tenant. The signup link is bound to an Entra ID user, we need to be able to configure for an SP.

image

image

Hi @stephybun thanks for your feedback. I have contacted the service team and look forward to their response.

@badeamarjieh
Copy link

The sign-up is a one-time setup for Microsoft Fabric that needs to be done by a user, preferably Fabric admin, on behalf of the tenant.
Once the sign-up is completed, then users and SPs in this tenant can use Fabric (and capacities). However, note that SPs will be disabled by default, and to enable them, you need to explicitly enable service principals to use Fabric APIs. see documentation

1 similar comment
@badeamarjieh
Copy link

The sign-up is a one-time setup for Microsoft Fabric that needs to be done by a user, preferably Fabric admin, on behalf of the tenant.
Once the sign-up is completed, then users and SPs in this tenant can use Fabric (and capacities). However, note that SPs will be disabled by default, and to enable them, you need to explicitly enable service principals to use Fabric APIs. see documentation

Copy link
Member

@stephybun stephybun left a comment

Choose a reason for hiding this comment

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

Thanks @sinbai tests are passing 👍

@stephybun stephybun merged commit 7a2f40e into hashicorp:main Dec 10, 2024
36 checks passed
@github-actions github-actions bot added this to the v4.14.0 milestone Dec 10, 2024
stephybun added a commit that referenced this pull request Dec 10, 2024
jackofallops added a commit that referenced this pull request Dec 13, 2024
* Update CHANGELOG.md for #26304

* Update CHANGELOG.md for #28211

* Update for #28016

* Update for #28139

* Update for #27776

* Update for #28227

* Update for #28080

* Update for #28228

* Update for #27915

* reword nginx api upgrade

* Update for #28160

* Update for #28043

* run changelog-update-for-release.sh

---------

Co-authored-by: stephybun <steph@hashicorp.com>
Co-authored-by: kt <kt@katbyte.me>
@Lachlan-White
Copy link
Contributor

image

Hey, @sinbai currently getting the below error when following the documented example.

@sinbai
Copy link
Contributor Author

sinbai commented Dec 24, 2024

image

Hey, @sinbai currently getting the below error when following the documented example.

Hi @Lachlan-White Terraform creates fabric by calling Azure API. The error seems to be returned by Azure API. Perhaps you could try calling the API directly to see if the same error occurs?

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.

7 participants