Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/data-sources/named_location.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ The following attributes are exported:
* `country` - A `country` block as documented below, which describes a country-based named location.
* `id` - The ID of the named location.
* `ip` - An `ip` block as documented below, which describes an IP-based named location.
*
* `object_id` - The object ID of the named location.

---

`country` block exports the following:
Expand Down
1 change: 1 addition & 0 deletions docs/resources/named_location.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ The following arguments are supported:
In addition to all arguments above, the following attributes are exported:

* `id` - The ID of the named location.
* `object_id` - The object ID of the named location.

## Timeouts

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,24 @@ func (r ConditionalAccessPolicyResource) Exists(ctx context.Context, clients *cl
return pointer.To(true), nil
}

func TestAccConditionalAccessPolicy_namedLocation(t *testing.T) {
data := acceptance.BuildTestData(t, "azuread_conditional_access_policy", "test")
r := ConditionalAccessPolicyResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.namedLocation(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("id").Exists(),
check.That(data.ResourceName).Key("display_name").HasValue(fmt.Sprintf("acctest-CONPOLICY-%d", data.RandomInteger)),
check.That(data.ResourceName).Key("state").HasValue("disabled"),
),
},
data.ImportStep(),
})
}

func (ConditionalAccessPolicyResource) basic(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azuread" {}
Expand Down Expand Up @@ -1222,3 +1240,41 @@ resource "azuread_conditional_access_policy" "test" {
}
`, data.RandomInteger)
}

func (ConditionalAccessPolicyResource) namedLocation(data acceptance.TestData) string {
location := NamedLocationResource{}.basicIP(data)

return fmt.Sprintf(`
provider "azuread" {}

resource "azuread_conditional_access_policy" "test" {
display_name = "acctest-CONPOLICY-%[1]d"
state = "disabled"

conditions {
client_app_types = ["browser"]

applications {
included_applications = ["None"]
}

users {
included_users = ["All"]
excluded_users = ["GuestsOrExternalUsers"]
}

locations {
included_locations = ["All"]
excluded_locations = [azuread_named_location.test.object_id]
}
}

grant_controls {
operator = "OR"
built_in_controls = ["block"]
}
}

%s
`, data.RandomInteger, location)
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ func namedLocationDataSource() *pluginsdk.Resource {
},
},
},

"object_id": {
Description: "The object ID of the named location",
Type: pluginsdk.TypeString,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -123,6 +129,7 @@ func namedLocationDataSourceRead(ctx context.Context, d *pluginsdk.ResourceData,
}

tf.Set(d, "display_name", pointer.From(namedLocation.DisplayName))
tf.Set(d, "object_id", pointer.From(namedLocation.Id))
tf.Set(d, "ip", flattenIPNamedLocation(&namedLocation))

case stable.CountryNamedLocation:
Expand All @@ -131,6 +138,7 @@ func namedLocationDataSourceRead(ctx context.Context, d *pluginsdk.ResourceData,
}

tf.Set(d, "display_name", pointer.From(namedLocation.DisplayName))
tf.Set(d, "object_id", pointer.From(namedLocation.Id))
tf.Set(d, "country", flattenCountryNamedLocation(&namedLocation))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ func namedLocationResource() *pluginsdk.Resource {
},
},
},

"object_id": {
Description: "The object ID of the named location",
Type: pluginsdk.TypeString,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -261,6 +267,7 @@ func namedLocationResourceRead(ctx context.Context, d *pluginsdk.ResourceData, m
}

tf.Set(d, "display_name", pointer.From(namedLocation.DisplayName))
tf.Set(d, "object_id", pointer.From(namedLocation.Id))
tf.Set(d, "ip", flattenIPNamedLocation(&namedLocation))

case stable.CountryNamedLocation:
Expand All @@ -269,6 +276,7 @@ func namedLocationResourceRead(ctx context.Context, d *pluginsdk.ResourceData, m
}

tf.Set(d, "display_name", pointer.From(namedLocation.DisplayName))
tf.Set(d, "object_id", pointer.From(namedLocation.Id))
tf.Set(d, "country", flattenCountryNamedLocation(&namedLocation))
}

Expand Down
Loading