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

Add Named Location support #441

Merged
merged 7 commits into from
Sep 7, 2021
Merged

Conversation

alexwilcox9
Copy link
Contributor

Hi @manicminer
I'm trying to build on the great msgraph work you recently did to enable named locations support post V2.0 of the provider.
I've aimed to replicate the layout we decided on in hamilton by having one named location resource and then decide which functions to call based on its properties.

The code in this PR is far from ready but could you glance over it and let me know if this is the right direction to be going in or if I should be taking a completely different approach like two different resource types

Thanks!
Alex

@alexwilcox9 alexwilcox9 changed the title first draft Add Named Location support May 23, 2021
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.

Hi @alexwilcox9, thanks for working on this! I've had a quick look through and I think this is the right approach.

To avoid conflicts, we'll be able to look at merging once the v2 changes are in, but I've left a few comments in the meantime. Feel free to leave this open and we'll rebase it closer to the time.

Comment on lines 41 to 44
"id": {
Type: schema.TypeString,
Computed: true,
},
Copy link
Member

Choose a reason for hiding this comment

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

We don't need to include id in the schema, the plugin SDK manages it implicitly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noted and removed

Copy link

Choose a reason for hiding this comment

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

@manicminer tests fail without this as a result of panic: Invalid address to set: []string{"id"} from what I can see- Unless the branch needs updating with the latest sdk

Copy link
Member

Choose a reason for hiding this comment

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

Ah I see, you need to use the d.SetId() method rather than d.Set("id") / tf.Set(d, "id")

Copy link

Choose a reason for hiding this comment

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

Ah thanks, that makes more sense now

Type: schema.TypeString,
},
},
"is_trusted": {
Copy link
Member

Choose a reason for hiding this comment

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

I'd probably just call this field trusted

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

Comment on lines 99 to 330
func namedLocationResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
if useMsGraph := meta.(*clients.Client).EnableMsGraphBeta; useMsGraph {
return namedLocationResourceCreateMsGraph(ctx, d, meta)
}
return tf.ErrorDiagF(nil, "azuread_conditional_access_policy does not support AAD Graph. Please enable `EnableMsGraphBeta`")
}

func namedLocationResourceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
if useMsGraph := meta.(*clients.Client).EnableMsGraphBeta; useMsGraph {
return namedLocationResourceUpdateMsGraph(ctx, d, meta)
}
return tf.ErrorDiagF(nil, "azuread_conditional_access_policy does not support AAD Graph. Please enable `EnableMsGraphBeta`")
}

func namedLocationResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
if useMsGraph := meta.(*clients.Client).EnableMsGraphBeta; useMsGraph {
return namedLocationResourceReadMsGraph(ctx, d, meta)
}
return tf.ErrorDiagF(nil, "azuread_conditional_access_policy does not support AAD Graph. Please enable `EnableMsGraphBeta`")
}

func namedLocationResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
if useMsGraph := meta.(*clients.Client).EnableMsGraphBeta; useMsGraph {
return namedLocationResourceDeleteMsGraph(ctx, d, meta)
}
return tf.ErrorDiagF(nil, "azuread_conditional_access_policy does not support AAD Graph. Please enable `EnableMsGraphBeta`")
}
Copy link
Member

Choose a reason for hiding this comment

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

In v2, these shim functions will go away as we will no longer support AAD Graph

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Understood, once there's a PR for removing AAD support I'll refactor all of this to be inline with the new layout

config := in[0].(map[string]interface{})

ipRanges := config["ip_ranges"].([]interface{})
isTrusted := config["is_trusted"].(interface{})
Copy link
Member

Choose a reason for hiding this comment

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

This will already be returned as type interface{} so no need for the assertion here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've removed the last assertion there but left in the slice of interface assertion as that's the only way I could get the expand function to work
If there's a cleaner way to do it let me know and I'll give it another shot

@alexwilcox9
Copy link
Contributor Author

Thanks for all the notes @manicminer
I'm scratching my head at the moment as I can't work out why my update function doesn't work.. It updates the display_name no problem but if I add an extra cidr range or country nothing seems to happen!

Could you glance over it and see if there's anything blatantly wrong with it? Thanks in advance

@alexwilcox9 alexwilcox9 changed the base branch from main to v2 May 27, 2021 09:46
@kaovd
Copy link

kaovd commented May 27, 2021

Currently trying to write some tests and the Import tests are hitting a Snag, not sure if its the way I've wrote the tests or if its in the read func although will review tommorow


2021/05/27 22:21:26 [DEBUG] Importing Resource - parsing "0217228f-9c8a-4c30-a95c-35947fc2362f"
    testcase.go:45: ImportStateVerify attributes not equivalent. Difference is shown below. Top is actual, bottom is expected.
        
        (map[string]string) {
        }
        
        
        (map[string]string) (len=6) {
         (string) (len=12) "display_name": (string) (len=40) "acctest-NAMEDLOCATION-210527222102151362",
         (string) (len=4) "ip.#": (string) (len=1) "1",
         (string) (len=6) "ip.0.%": (string) (len=1) "2",
         (string) (len=16) "ip.0.ip_ranges.#": (string) (len=1) "1",
         (string) (len=16) "ip.0.ip_ranges.0": (string) (len=10) "10.0.0.0/8",
         (string) (len=12) "ip.0.trusted": (string) (len=4) "true"
        }

@alexwilcox9
Copy link
Contributor Author

@kaovd could you try your test again?

I think because it's an import I can't use the d.GetOk("ip") function. Instead I'm now using the client.List function filtering it to one ID and that seems to work

@kaovd
Copy link

kaovd commented May 28, 2021

@kaovd could you try your test again?

I think because it's an import I can't use the d.GetOk("ip") function. Instead I'm now using the client.List function filtering it to one ID and that seems to work

Sure will pull and retest. Also have you seen this for the ID param setting? #441 (comment)

@alexwilcox9
Copy link
Contributor Author

alexwilcox9 commented May 28, 2021

Ah I hadn't, thanks for that
Wondering if I need the setID at all in the read function as this is needed for the function to work at all..

@manicminer do you think I should add a generic Get function to hamilton that works similar to the list function?

@kaovd
Copy link

kaovd commented May 28, 2021

Ah I hadn't, thanks for that
Wondering if I need the setID at all in the read function as this is needed for the function to work at all..

@manicminer do you think I should add a generic Get function to hamilton that works similar to the list function?

that would probably make the exists check a whole lot easier tbf, in agreement with this. While it can be pulled via list a dedicated get function would be less intensive and a better solution.

Also those two fixes did the trick on my tests, currently just got a basic test up as follows:

func (NamedLocationResource) basic(data acceptance.TestData) string {
	return fmt.Sprintf(`
resource "azuread_named_location" "test" {
  display_name = "acctest-NAMEDLOCATION-%[1]d"
  
  ip {
	  ip_ranges = ["10.0.0.0/8", "11.11.11.11/8"]
	  trusted = true
  }
}
`, data.RandomInteger)
}
 $ TF_LOG=TRACE TF_ACC=1 go test -v -timeout=2h ./internal/services/namedlocations                                                                                                                                                                    [±named-locations ●]
=== RUN   TestAccNamedLocation_basic
=== PAUSE TestAccNamedLocation_basic
=== CONT  TestAccNamedLocation_basic
2021/05/28 18:31:17 [DEBUG] Importing Resource - parsing "0c737cef-7278-4609-822b-3196b2f79111"
--- PASS: TestAccNamedLocation_basic (12.86s)
PASS
ok      github.com/hashicorp/terraform-provider-azuread/internal/services/namedlocations        12.871s

my exists function is just checking for the IP right now. Without a generic get function I was thinking of just trying to get them both, see what exists and verify based off that but thats a bit more sloppy than a singular get func. For now im just going to return true and write a few more tests.

Also I can see what you mean in regards to the issues with updating the ip array. Dosen't seem to be getting updated on MS's end might be a issue with the function

--- PASS: TestAccNamedLocation_basic (23.37s)
=== CONT  TestAccNamedLocation_update
    testcase.go:45: Step 3/4 error: After applying this test step and performing a `terraform refresh`, the plan was not empty.
        stdout
        
        
        Terraform used the selected providers to generate the following execution
        plan. Resource actions are indicated with the following symbols:
          ~ update in-place
        
        Terraform will perform the following actions:
        
          # azuread_named_location.test will be updated in-place
          ~ resource "azuread_named_location" "test" {
                id           = "0dfb451f-3e06-4bb2-87bc-270ac9039f2f"
                # (1 unchanged attribute hidden)
        
              ~ ip {
                  ~ ip_ranges = [
                        # (1 unchanged element hidden)
                        "11.11.11.21/8",
                      + "50.50.50.50/8",
                    ]
                    # (1 unchanged attribute hidden)
                }
            }
        
        Plan: 0 to add, 1 to change, 0 to destroy.
--- FAIL: TestAccNamedLocation_update (42.26s)

@kaovd
Copy link

kaovd commented May 28, 2021

Ok done some more debugging and found the problem, the Update functions in hamilton aren't setting the Odata types and therefore the request is ill formed although dosen't spit an error out. Whacking in

ipNamedLocation.ODataType = utils.StringPtr("#microsoft.graph.ipNamedLocation")

In UpdateIp / UpdateCountry seems to fix this from what I can see. Will go make a PR. Post this I can request changes to add in my go tests or you can write your own whatevers good

=== RUN   TestAccNamedLocation_basic
=== PAUSE TestAccNamedLocation_basic
=== RUN   TestAccNamedLocation_complete
=== PAUSE TestAccNamedLocation_complete
=== RUN   TestAccNamedLocation_update
=== PAUSE TestAccNamedLocation_update
=== CONT  TestAccNamedLocation_basic
=== CONT  TestAccNamedLocation_update
=== CONT  TestAccNamedLocation_complete
2021/05/28 22:25:21 [DEBUG] Importing Resource - parsing "0e5f1b3e-d77c-4f10-a62a-aaeebc1643a7"
2021/05/28 22:25:33 [DEBUG] Importing Resource - parsing "084ce618-09bb-4289-bd06-63637e9e7d56"
2021/05/28 22:25:35 [DEBUG] Importing Resource - parsing "04958d54-0bd5-4430-845d-080f7bd87de7"
--- PASS: TestAccNamedLocation_basic (33.93s)
--- PASS: TestAccNamedLocation_complete (36.60s)
2021/05/28 22:25:59 [DEBUG] Importing Resource - parsing "084ce618-09bb-4289-bd06-63637e9e7d56"
2021/05/28 22:26:09 [DEBUG] Importing Resource - parsing "084ce618-09bb-4289-bd06-63637e9e7d56"
--- PASS: TestAccNamedLocation_update (69.16s)
PASS
ok      github.com/hashicorp/terraform-provider-azuread/internal/services/namedlocations        69.171s

kaovd added a commit to kaovd/hamilton that referenced this pull request May 28, 2021
The Odata type functions are missed in the update functions which causes the requests to be ill formed and updates are not applied. See hashicorp/terraform-provider-azuread#441
@alexwilcox9
Copy link
Contributor Author

Great spot @kaovd!
I've now created that generic get function and have a PR open for that manicminer/hamilton#56

@alexwilcox9
Copy link
Contributor Author

I've had a go at writing some tests myself but the results are very inconsistent. This lines up with my experience of testing named locations in the hamilton client. It seems graph lags behind for whatever reason
I've added a fairly significant delay to the exists function which improves the odds of a successful test but it's still not perfect

Also when I try to run all of the tests together make testacc TESTARGS='-run=TestAccNamedLocation' it seems to have a bad time

}

func TestAccNamedLocation_completeCountry(t *testing.T) {
data := acceptance.BuildTestData(t, "azuread_named_location", "test-country")
Copy link

Choose a reason for hiding this comment

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

Suggested change
data := acceptance.BuildTestData(t, "azuread_named_location", "test-country")
data := acceptance.BuildTestData(t, "azuread_named_location", "test-complete-country")

Here's the bug. Change this and I get

> $ TF_LOG=TRACE TF_ACC=1 go test -v -timeout=2h ./internal/services/namedlocations                                                                             [±named-locations ●]
=== RUN   TestAccNamedLocation_basicIP
=== PAUSE TestAccNamedLocation_basicIP
=== RUN   TestAccNamedLocation_completeIP
=== PAUSE TestAccNamedLocation_completeIP
=== RUN   TestAccNamedLocation_basicCountry
=== PAUSE TestAccNamedLocation_basicCountry
=== RUN   TestAccNamedLocation_completeCountry
=== PAUSE TestAccNamedLocation_completeCountry
=== CONT  TestAccNamedLocation_basicIP
=== CONT  TestAccNamedLocation_completeCountry
=== CONT  TestAccNamedLocation_basicCountry
=== CONT  TestAccNamedLocation_completeIP
2021/06/02 19:23:29 [DEBUG] Importing Resource - parsing "0cc4a4a9-dfb3-425f-8ed1-70365cc7acdd"
2021/06/02 19:23:30 [DEBUG] Importing Resource - parsing "18b64bcf-75b4-40c0-865c-eecfb2016076"
2021/06/02 19:23:32 [DEBUG] Importing Resource - parsing "101afc99-0c08-48d7-b365-13fbf838d8bb"
2021/06/02 19:23:32 [DEBUG] Importing Resource - parsing "0dc61f25-134e-4bfe-853e-6db25f168dd6"
--- PASS: TestAccNamedLocation_basicIP (62.86s)
--- PASS: TestAccNamedLocation_basicCountry (62.96s)
--- PASS: TestAccNamedLocation_completeCountry (64.50s)
--- PASS: TestAccNamedLocation_completeIP (64.55s)
PASS
ok      github.com/hashicorp/terraform-provider-azuread/internal/services/namedlocations        64.563s

Put two update tests in there for basic > complete on both ip / country and should be good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So for the update test do all of the test data sets have to have the same resource label? Looking at other test functions for other resources I see that all of the resource labels are "test" but when I switch over to this I start getting inconsistent errors

 TF_LOG=TRACE TF_ACC=1 go test -v -timeout=2h ./internal/services/namedlocations
=== RUN   TestAccNamedLocation_basicIP
=== PAUSE TestAccNamedLocation_basicIP
=== RUN   TestAccNamedLocation_completeIP
=== PAUSE TestAccNamedLocation_completeIP
=== RUN   TestAccNamedLocation_basicCountry
=== PAUSE TestAccNamedLocation_basicCountry
=== RUN   TestAccNamedLocation_completeCountry
=== PAUSE TestAccNamedLocation_completeCountry
=== RUN   TestAccNamedLocation_updateIP
=== PAUSE TestAccNamedLocation_updateIP
=== CONT  TestAccNamedLocation_basicIP
=== CONT  TestAccNamedLocation_completeCountry
=== CONT  TestAccNamedLocation_basicCountry
=== CONT  TestAccNamedLocation_completeIP
=== CONT  TestAccNamedLocation_updateIP
2021/06/02 19:42:12 [DEBUG] Named Location with Object ID "02f3ea6a-9dac-4b36-930e-75e93e8c361a" was not found - removing from state
2021/06/02 19:42:12 [WARN] Got error running Terraform: exit status 1

Error: Provider produced inconsistent result after apply

When applying changes to azuread_named_location.test, provider
"provider[\"registry.terraform.io/hashicorp/azuread\"]" produced an
unexpected new value: Root resource was present, but now absent.

This is a bug in the provider, which should be reported in the provider's own
issue tracker.
=== CONT  TestAccNamedLocation_completeIP
    testcase.go:45: Step 1/2 error: Error running apply: exit status 1
        
        Error: Provider produced inconsistent result after apply
        
        When applying changes to azuread_named_location.test, provider
        "provider[\"registry.terraform.io/hashicorp/azuread\"]" produced an
        unexpected new value: Root resource was present, but now absent.
        
        This is a bug in the provider, which should be reported in the provider's own
        issue tracker.
--- FAIL: TestAccNamedLocation_completeIP (4.16s)
2021/06/02 19:42:12 [DEBUG] Named Location with Object ID "00b71689-e358-4489-8b13-1a88eb2654ef" was not found - removing from state
2021/06/02 19:42:12 [WARN] Got error running Terraform: exit status 1

Error: Provider produced inconsistent result after apply

When applying changes to azuread_named_location.test, provider
"provider[\"registry.terraform.io/hashicorp/azuread\"]" produced an
unexpected new value: Root resource was present, but now absent.

This is a bug in the provider, which should be reported in the provider's own
issue tracker.
=== CONT  TestAccNamedLocation_basicIP
    testcase.go:45: Step 1/2 error: Error running apply: exit status 1
        
        Error: Provider produced inconsistent result after apply
        
        When applying changes to azuread_named_location.test, provider
        "provider[\"registry.terraform.io/hashicorp/azuread\"]" produced an
        unexpected new value: Root resource was present, but now absent.
        
        This is a bug in the provider, which should be reported in the provider's own
        issue tracker.
--- FAIL: TestAccNamedLocation_basicIP (4.58s)
=== CONT  TestAccNamedLocation_completeCountry
    testcase.go:45: Step 1/2 error: Check failed: Check 1/1 error: running exists func for "azuread_named_location.test": Named Location with object ID "1ed56c5c-fd26-4097-b409-268a44e51865" does not exist
=== CONT  TestAccNamedLocation_updateIP
    testcase.go:45: Step 1/6 error: Check failed: Check 1/1 error: running exists func for "azuread_named_location.test": Named Location with object ID "092314fc-10d1-4311-a1ff-04af26a696bb" does not exist
2021/06/02 19:42:32 [DEBUG] Named Location with ID "092314fc-10d1-4311-a1ff-04af26a696bb" already deleted
2021/06/02 19:42:33 [DEBUG] Importing Resource - parsing "1c163a0b-c3a9-404c-bcf7-c841a4e80bdc"
    testing_new.go:63: Error running post-test destroy, there may be dangling resources: "azuread_named_location.test" still exists
--- FAIL: TestAccNamedLocation_updateIP (44.98s)
--- FAIL: TestAccNamedLocation_completeCountry (45.37s)
--- PASS: TestAccNamedLocation_basicCountry (47.75s)
FAIL
FAIL    github.com/hashicorp/terraform-provider-azuread/internal/services/namedlocations        47.761s
FAIL

@kaovd
Copy link

kaovd commented Jun 2, 2021

See what you mean on inconsistency now - So the update tests are fine indivdually same with all others tests (although is some weirdness sometimes with MS Online rejecting conns or the remote breaking) but when I run together / after another test it starts complaining. Is graph rate limiting here? Oddly once I run things indivdually or a few times then go run them all together again its fine.

@alexwilcox9
Copy link
Contributor Author

Yup that lines up with what I've been seeing apart from the last bit; I haven't managed to get them all to run together successfully.
A quick Google on graph rate limits I can't find anything suggesting specific limits for Named Locations

When I compile the provider and actually use it it performs brilliantly. Will the tests passing inconsistently be a blocker for getting this merged post V2?

@manicminer
Copy link
Member

manicminer commented Jun 2, 2021

I haven't run this yet - what is the actual API error? is it rate limiting proper, or perhaps related to replication delay? I've seen the latter a lot with named locations and hoping to have a workaround in the SDK soon.

(We will need reliable tests before merging)

@kaovd
Copy link

kaovd commented Jun 3, 2021

@manicminer For me sometimes graph straight resets my conn but might be a me issue. The main issue has a likeness to this #407 actually. First test run will have that occur although if i run a few more times in different orders everything passes eventually. Could be multitude of problems? I've gone to test it some more and country tests are fine, all of a sudden IP tests are breaking for me with 500, however running the sample MS query from the docs in graph explorer does the same so guessing my environment is currently broke so until thats working not going to be able to keep testing. Not sure if itll just fix itself tommorow

@alexwilcox9
Copy link
Contributor Author

I'm wondering if something has improved on Microsoft's end now. Thought I'd just try running the tests again and have managed to successfully run them all concurrently five times over.
This is still with a fairly hefty sleep in the Exists function but trying without this did fail. Would be great to know if the tests now run reliably for both of you as well.

--- Test 1 ---
$ TF_LOG=TRACE TF_ACC=1 go test -v -timeout=2h ./internal/services/namedlocations
=== RUN   TestAccNamedLocation_basicIP
=== PAUSE TestAccNamedLocation_basicIP
=== RUN   TestAccNamedLocation_completeIP
=== PAUSE TestAccNamedLocation_completeIP
=== RUN   TestAccNamedLocation_updateIP
=== PAUSE TestAccNamedLocation_updateIP
=== RUN   TestAccNamedLocation_basicCountry
=== PAUSE TestAccNamedLocation_basicCountry
=== RUN   TestAccNamedLocation_completeCountry
=== PAUSE TestAccNamedLocation_completeCountry
=== RUN   TestAccNamedLocation_updateCountry
=== PAUSE TestAccNamedLocation_updateCountry
=== CONT  TestAccNamedLocation_basicIP
=== CONT  TestAccNamedLocation_completeCountry
=== CONT  TestAccNamedLocation_updateIP
=== CONT  TestAccNamedLocation_basicCountry
=== CONT  TestAccNamedLocation_updateCountry
=== CONT  TestAccNamedLocation_completeIP
2021/06/04 19:35:19 [DEBUG] Importing Resource - parsing "15ef8c94-6ae3-4c59-af84-f5ed51beaf86"
2021/06/04 19:35:19 [DEBUG] Importing Resource - parsing "0b93ac77-d4dc-43ac-b6ce-fc2c8c33fc3e"
2021/06/04 19:35:19 [DEBUG] Importing Resource - parsing "1363dff3-03fa-4c2e-96c2-3b5ea04fff3f"
2021/06/04 19:35:19 [DEBUG] Importing Resource - parsing "0f024757-9b4b-4c3f-bf02-a468c475e9ae"
2021/06/04 19:35:19 [DEBUG] Importing Resource - parsing "0511bf77-fa69-4d99-b789-52c3313655d1"
2021/06/04 19:35:19 [DEBUG] Importing Resource - parsing "15f82a8b-0357-4e3f-a230-0a69bc368eae"
--- PASS: TestAccNamedLocation_completeCountry (48.21s)
--- PASS: TestAccNamedLocation_basicCountry (48.27s)
--- PASS: TestAccNamedLocation_basicIP (48.50s)
--- PASS: TestAccNamedLocation_completeIP (49.62s)
2021/06/04 19:35:43 [DEBUG] Importing Resource - parsing "0b93ac77-d4dc-43ac-b6ce-fc2c8c33fc3e"
2021/06/04 19:35:44 [DEBUG] Importing Resource - parsing "15f82a8b-0357-4e3f-a230-0a69bc368eae"
2021/06/04 19:36:07 [DEBUG] Importing Resource - parsing "0b93ac77-d4dc-43ac-b6ce-fc2c8c33fc3e"
2021/06/04 19:36:07 [DEBUG] Importing Resource - parsing "15f82a8b-0357-4e3f-a230-0a69bc368eae"
--- PASS: TestAccNamedLocation_updateIP (96.00s)
--- PASS: TestAccNamedLocation_updateCountry (96.75s)
PASS
ok      github.com/hashicorp/terraform-provider-azuread/internal/services/namedlocations        96.763s
--- Test 2 ---
$ go clean -testcache
$ TF_LOG=TRACE TF_ACC=1 go test -v -timeout=2h ./internal/services/namedlocations
=== RUN   TestAccNamedLocation_basicIP
=== PAUSE TestAccNamedLocation_basicIP
=== RUN   TestAccNamedLocation_completeIP
=== PAUSE TestAccNamedLocation_completeIP
=== RUN   TestAccNamedLocation_updateIP
=== PAUSE TestAccNamedLocation_updateIP
=== RUN   TestAccNamedLocation_basicCountry
=== PAUSE TestAccNamedLocation_basicCountry
=== RUN   TestAccNamedLocation_completeCountry
=== PAUSE TestAccNamedLocation_completeCountry
=== RUN   TestAccNamedLocation_updateCountry
=== PAUSE TestAccNamedLocation_updateCountry
=== CONT  TestAccNamedLocation_basicIP
=== CONT  TestAccNamedLocation_completeCountry
=== CONT  TestAccNamedLocation_updateIP
=== CONT  TestAccNamedLocation_completeIP
=== CONT  TestAccNamedLocation_basicCountry
=== CONT  TestAccNamedLocation_updateCountry
2021/06/04 19:40:54 [DEBUG] Importing Resource - parsing "0b5c1256-c5c5-4cb9-84e8-65d10cc89590"
2021/06/04 19:40:54 [DEBUG] Importing Resource - parsing "1be27443-e2bd-492f-95fd-412a46ea1653"
2021/06/04 19:40:54 [DEBUG] Importing Resource - parsing "03f89933-c7db-4628-adb6-2ec964322745"
2021/06/04 19:40:54 [DEBUG] Importing Resource - parsing "1c5870aa-cdc2-42ed-96d9-96c632ddf943"
2021/06/04 19:40:54 [DEBUG] Importing Resource - parsing "1c8b845b-6083-429e-8aab-377cde9bf2cd"
2021/06/04 19:40:54 [DEBUG] Importing Resource - parsing "064c0015-909e-4021-8362-b466d443fcd6"
--- PASS: TestAccNamedLocation_completeCountry (46.21s)
--- PASS: TestAccNamedLocation_completeIP (46.34s)
--- PASS: TestAccNamedLocation_basicIP (46.54s)
--- PASS: TestAccNamedLocation_basicCountry (46.66s)
2021/06/04 19:41:18 [DEBUG] Importing Resource - parsing "1c8b845b-6083-429e-8aab-377cde9bf2cd"
2021/06/04 19:41:18 [DEBUG] Importing Resource - parsing "064c0015-909e-4021-8362-b466d443fcd6"
2021/06/04 19:41:41 [DEBUG] Importing Resource - parsing "1c8b845b-6083-429e-8aab-377cde9bf2cd"
2021/06/04 19:41:42 [DEBUG] Importing Resource - parsing "064c0015-909e-4021-8362-b466d443fcd6"
--- PASS: TestAccNamedLocation_updateCountry (93.91s)
--- PASS: TestAccNamedLocation_updateIP (94.19s)
PASS
ok      github.com/hashicorp/terraform-provider-azuread/internal/services/namedlocations        94.210s
--- Test 3 ---
$ go clean -testcache
$ TF_LOG=TRACE TF_ACC=1 go test -v -timeout=2h ./internal/services/namedlocations
=== RUN   TestAccNamedLocation_basicIP
=== PAUSE TestAccNamedLocation_basicIP
=== RUN   TestAccNamedLocation_completeIP
=== PAUSE TestAccNamedLocation_completeIP
=== RUN   TestAccNamedLocation_updateIP
=== PAUSE TestAccNamedLocation_updateIP
=== RUN   TestAccNamedLocation_basicCountry
=== PAUSE TestAccNamedLocation_basicCountry
=== RUN   TestAccNamedLocation_completeCountry
=== PAUSE TestAccNamedLocation_completeCountry
=== RUN   TestAccNamedLocation_updateCountry
=== PAUSE TestAccNamedLocation_updateCountry
=== CONT  TestAccNamedLocation_basicIP
=== CONT  TestAccNamedLocation_completeCountry
=== CONT  TestAccNamedLocation_basicCountry
=== CONT  TestAccNamedLocation_updateIP
=== CONT  TestAccNamedLocation_completeIP
=== CONT  TestAccNamedLocation_updateCountry
2021/06/04 19:43:49 [DEBUG] Importing Resource - parsing "1a511598-6759-4467-8b25-51cc37588bfc"
2021/06/04 19:43:49 [DEBUG] Importing Resource - parsing "17897d8a-39df-4364-b5a4-3af4b15c5512"
2021/06/04 19:43:49 [DEBUG] Importing Resource - parsing "04ad5784-5955-4636-84ca-c6415c5f3bed"
2021/06/04 19:43:49 [DEBUG] Importing Resource - parsing "13ccc77d-baa4-478b-a05f-5fa4a980276f"
2021/06/04 19:43:49 [DEBUG] Importing Resource - parsing "0494b698-888c-4dfd-a495-a19ba5edcde7"
2021/06/04 19:43:49 [DEBUG] Importing Resource - parsing "05c1269e-dbba-4fd2-ada3-db28b6cea6de"
--- PASS: TestAccNamedLocation_basicIP (48.90s)
--- PASS: TestAccNamedLocation_basicCountry (49.43s)
2021/06/04 19:44:16 [DEBUG] Importing Resource - parsing "05c1269e-dbba-4fd2-ada3-db28b6cea6de"
--- PASS: TestAccNamedLocation_completeCountry (55.85s)
--- PASS: TestAccNamedLocation_completeIP (56.33s)
2021/06/04 19:44:23 [DEBUG] Importing Resource - parsing "13ccc77d-baa4-478b-a05f-5fa4a980276f"
2021/06/04 19:44:40 [DEBUG] Importing Resource - parsing "05c1269e-dbba-4fd2-ada3-db28b6cea6de"
2021/06/04 19:44:47 [DEBUG] Importing Resource - parsing "13ccc77d-baa4-478b-a05f-5fa4a980276f"
--- PASS: TestAccNamedLocation_updateIP (97.12s)
--- PASS: TestAccNamedLocation_updateCountry (103.98s)
PASS
ok      github.com/hashicorp/terraform-provider-azuread/internal/services/namedlocations        103.995s
--- Test 4 ---
$ go clean -testcache
$ TF_LOG=TRACE TF_ACC=1 go test -v -timeout=2h ./internal/services/namedlocations
=== RUN   TestAccNamedLocation_basicIP
=== PAUSE TestAccNamedLocation_basicIP
=== RUN   TestAccNamedLocation_completeIP
=== PAUSE TestAccNamedLocation_completeIP
=== RUN   TestAccNamedLocation_updateIP
=== PAUSE TestAccNamedLocation_updateIP
=== RUN   TestAccNamedLocation_basicCountry
=== PAUSE TestAccNamedLocation_basicCountry
=== RUN   TestAccNamedLocation_completeCountry
=== PAUSE TestAccNamedLocation_completeCountry
=== RUN   TestAccNamedLocation_updateCountry
=== PAUSE TestAccNamedLocation_updateCountry
=== CONT  TestAccNamedLocation_basicIP
=== CONT  TestAccNamedLocation_completeCountry
=== CONT  TestAccNamedLocation_updateIP
=== CONT  TestAccNamedLocation_updateCountry
=== CONT  TestAccNamedLocation_basicCountry
=== CONT  TestAccNamedLocation_completeIP
2021/06/04 19:47:59 [DEBUG] Importing Resource - parsing "0a6dbc27-59d8-4947-b734-6811654a7bb8"
2021/06/04 19:48:00 [DEBUG] Importing Resource - parsing "00e3553e-a66d-4b30-9864-e6278bdad3cf"
2021/06/04 19:48:00 [DEBUG] Importing Resource - parsing "1e30f703-5bc8-411c-b5d3-2084297299a7"
2021/06/04 19:48:00 [DEBUG] Importing Resource - parsing "14afea8d-5fd4-4bbf-936f-fa581f59902a"
2021/06/04 19:48:00 [DEBUG] Importing Resource - parsing "1cb72427-176c-428d-b761-d17acaf086d9"
2021/06/04 19:48:00 [DEBUG] Importing Resource - parsing "005682a3-5ee6-4d40-9b0e-d765db5697dd"
--- PASS: TestAccNamedLocation_basicIP (46.21s)
--- PASS: TestAccNamedLocation_completeCountry (46.34s)
--- PASS: TestAccNamedLocation_basicCountry (46.48s)
--- PASS: TestAccNamedLocation_completeIP (46.72s)
2021/06/04 19:48:23 [DEBUG] Importing Resource - parsing "00e3553e-a66d-4b30-9864-e6278bdad3cf"
2021/06/04 19:48:24 [DEBUG] Importing Resource - parsing "1cb72427-176c-428d-b761-d17acaf086d9"
2021/06/04 19:48:47 [DEBUG] Importing Resource - parsing "00e3553e-a66d-4b30-9864-e6278bdad3cf"
2021/06/04 19:48:48 [DEBUG] Importing Resource - parsing "1cb72427-176c-428d-b761-d17acaf086d9"
--- PASS: TestAccNamedLocation_updateIP (94.00s)
--- PASS: TestAccNamedLocation_updateCountry (94.18s)
PASS
ok      github.com/hashicorp/terraform-provider-azuread/internal/services/namedlocations        94.214s
--- Test 5 ---
$ go clean -testcache
$ TF_LOG=TRACE TF_ACC=1 go test -v -timeout=2h ./internal/services/namedlocations
=== RUN   TestAccNamedLocation_basicIP
=== PAUSE TestAccNamedLocation_basicIP
=== RUN   TestAccNamedLocation_completeIP
=== PAUSE TestAccNamedLocation_completeIP
=== RUN   TestAccNamedLocation_updateIP
=== PAUSE TestAccNamedLocation_updateIP
=== RUN   TestAccNamedLocation_basicCountry
=== PAUSE TestAccNamedLocation_basicCountry
=== RUN   TestAccNamedLocation_completeCountry
=== PAUSE TestAccNamedLocation_completeCountry
=== RUN   TestAccNamedLocation_updateCountry
=== PAUSE TestAccNamedLocation_updateCountry
=== CONT  TestAccNamedLocation_basicIP
=== CONT  TestAccNamedLocation_completeCountry
=== CONT  TestAccNamedLocation_updateIP
=== CONT  TestAccNamedLocation_basicCountry
=== CONT  TestAccNamedLocation_completeIP
=== CONT  TestAccNamedLocation_updateCountry
2021/06/04 19:50:01 [DEBUG] Importing Resource - parsing "01ca8fbd-e9ca-4dc8-ba28-c8c352c09cec"
2021/06/04 19:50:01 [DEBUG] Importing Resource - parsing "0cfb75f3-0ac9-46d1-9563-9917646a0ab0"
2021/06/04 19:50:01 [DEBUG] Importing Resource - parsing "135f4d00-4d29-409f-aefa-12313f90d332"
2021/06/04 19:50:02 [DEBUG] Importing Resource - parsing "0ca9137f-c870-42b0-86f2-7e31973ebf69"
2021/06/04 19:50:02 [DEBUG] Importing Resource - parsing "164ff92b-82a8-4bf8-84e3-67dfd4932807"
2021/06/04 19:50:02 [DEBUG] Importing Resource - parsing "1c23cff8-262a-4099-838d-2b5806b72b0e"
--- PASS: TestAccNamedLocation_completeIP (47.97s)
--- PASS: TestAccNamedLocation_basicCountry (48.29s)
--- PASS: TestAccNamedLocation_basicIP (48.33s)
2021/06/04 19:50:27 [DEBUG] Importing Resource - parsing "164ff92b-82a8-4bf8-84e3-67dfd4932807"
2021/06/04 19:50:27 [DEBUG] Importing Resource - parsing "01ca8fbd-e9ca-4dc8-ba28-c8c352c09cec"
--- PASS: TestAccNamedLocation_completeCountry (66.30s)
2021/06/04 19:50:51 [DEBUG] Importing Resource - parsing "164ff92b-82a8-4bf8-84e3-67dfd4932807"
2021/06/04 19:50:51 [DEBUG] Importing Resource - parsing "01ca8fbd-e9ca-4dc8-ba28-c8c352c09cec"
--- PASS: TestAccNamedLocation_updateCountry (95.35s)
--- PASS: TestAccNamedLocation_updateIP (95.48s)
PASS
ok      github.com/hashicorp/terraform-provider-azuread/internal/services/namedlocations        95.501s

@kaovd
Copy link

kaovd commented Jun 5, 2021

Yep can confirm the tests are running fine off the bat for me too now as well. Not sure what MS where doing there.

@manicminer manicminer deleted the branch hashicorp:main July 2, 2021 08:40
@manicminer manicminer reopened this Jul 2, 2021
@manicminer manicminer changed the base branch from v2 to main July 2, 2021 08:44
@alexwilcox9 alexwilcox9 force-pushed the named-locations branch 2 times, most recently from 9e43c86 to f1387a3 Compare July 30, 2021 21:55
@manicminer manicminer modified the milestones: v2.1.0, v2.2.0 Sep 2, 2021
@manicminer manicminer self-requested a review September 7, 2021 10:31
@manicminer manicminer self-assigned this Sep 7, 2021
@manicminer
Copy link
Member

@alexwilcox9 Thanks again for your early and continued work on this! 🚀

I rebased to resolve the conflicts, and added a few fixes. I used WaitForState funcs to smooth out the API delays when updating and deleting, and the tests are passing for me now. There's much inconsistency with this endpoint; after updating it will return both the old and new versions for awhile, and likewise after deleting it returns a mixture of 404 and 200 responses until the backend replication is seemingly completed. WaitForState has a useful ContinuousTargetOccurence option which ensures the API returns the expected result x times in a row.

Since my changes are substantial, I've pinged the rest of our team for further review.

Test results:

Screenshot 2021-09-07 at 12 31 19

Comment on lines 143 to 146
return namedLocationResourceRead(ctx, d, meta)
}

return tf.ErrorDiagF(errors.New("one of `ip` or `country` must be specified"), "Unable to determine named location type")
Copy link

Choose a reason for hiding this comment

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

I would move the error message in an else branch of the if block and move the return statement outside of it.

Copy link
Member

Choose a reason for hiding this comment

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

Good call, I played with this func so much I neglected to tidy that :)

properties := expandIPNamedLocation(v.([]interface{}))
properties.BaseNamedLocation = &base

location, _, err := client.CreateIP(ctx, *properties)
Copy link

Choose a reason for hiding this comment

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

I think it would be easier to understand this if location was renamed to ipLocation here and countryLocation in line 133.

Copy link

@koikonom koikonom left a comment

Choose a reason for hiding this comment

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

LGTM!

@manicminer manicminer merged commit 941f1e1 into hashicorp:main Sep 7, 2021
manicminer added a commit that referenced this pull request Sep 7, 2021
@github-actions
Copy link

This functionality has been released in v2.2.0 of the Terraform Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 10, 2021
@alexwilcox9 alexwilcox9 deleted the named-locations branch January 12, 2023 22:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants