Skip to content

Commit

Permalink
add support for country_lookup_method
Browse files Browse the repository at this point in the history
  • Loading branch information
sdx-jkataja committed Dec 13, 2024
1 parent a204461 commit 3496fd4
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 0 deletions.
10 changes: 10 additions & 0 deletions internal/services/conditionalaccess/conditionalaccess.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,16 @@ func flattenCountryNamedLocation(in *stable.CountryNamedLocation) []interface{}
includeUnknown = *in.IncludeUnknownCountriesAndRegions
}

countryLookupMethod := stable.CountryLookupMethodType_ClientIPAddress
if in.CountryLookupMethod != nil {
countryLookupMethod = *in.CountryLookupMethod
}

return []interface{}{
map[string]interface{}{
"countries_and_regions": tf.FlattenStringSlice(in.CountriesAndRegions),
"include_unknown_countries_and_regions": includeUnknown,
"country_lookup_method": countryLookupMethod,
},
}
}
Expand Down Expand Up @@ -659,6 +665,10 @@ func expandCountryNamedLocation(in []interface{}) *stable.CountryNamedLocation {
result.CountriesAndRegions = tf.ExpandStringSlice(countriesAndRegions)
result.IncludeUnknownCountriesAndRegions = pointer.To(includeUnknown.(bool))

if countryLookupMethodType, ok := config["country_lookup_method"]; ok && countryLookupMethodType.(string) != "" {
result.CountryLookupMethod = pointer.To(stable.CountryLookupMethodType(countryLookupMethodType.(string)))
}

return &result
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ func namedLocationDataSource() *pluginsdk.Resource {
Type: pluginsdk.TypeBool,
Computed: true,
},

"country_lookup_method": {
Type: pluginsdk.TypeString,
Computed: true,
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ func TestAccNamedLocationDataSource_country(t *testing.T) {
check.That(data.ResourceName).Key("country.#").HasValue("1"),
check.That(data.ResourceName).Key("country.0.countries_and_regions.#").HasValue("3"),
check.That(data.ResourceName).Key("country.0.include_unknown_countries_and_regions").HasValue("true"),
check.That(data.ResourceName).Key("country.0.country_lookup_method").HasValue("clientIpAddress"),
),
},
})
}

func TestAccNamedLocationDataSource_countryByGps(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azuread_named_location", "test")

data.DataSourceTest(t, []acceptance.TestStep{
{
Config: NamedLocationDataSource{}.countryByGps(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).Key("country.#").HasValue("1"),
check.That(data.ResourceName).Key("country.0.countries_and_regions.#").HasValue("3"),
check.That(data.ResourceName).Key("country.0.include_unknown_countries_and_regions").HasValue("true"),
check.That(data.ResourceName).Key("country.0.country_lookup_method").HasValue("authenticatorAppGps"),
),
},
})
Expand Down Expand Up @@ -53,6 +70,16 @@ data "azuread_named_location" "test" {
`, NamedLocationResource{}.completeCountry(data))
}

func (NamedLocationDataSource) countryByGps(data acceptance.TestData) string {
return fmt.Sprintf(`
%[1]s
data "azuread_named_location" "test" {
display_name = azuread_named_location.test.display_name
}
`, NamedLocationResource{}.completeCountryByGps(data))
}

func (NamedLocationDataSource) ip(data acceptance.TestData) string {
return fmt.Sprintf(`
%[1]s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ func namedLocationResource() *pluginsdk.Resource {
Type: pluginsdk.TypeBool,
Optional: true,
},

"country_lookup_method": {
Type: pluginsdk.TypeString,
Default: stable.CountryLookupMethodType_ClientIPAddress,
ValidateFunc: validation.StringInSlice(stable.PossibleValuesForCountryLookupMethodType(), false),
Optional: true,
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,50 @@ func TestAccNamedLocation_updateCountry(t *testing.T) {
})
}

func TestAccNamedLocation_completeCountryByGps(t *testing.T) {
data := acceptance.BuildTestData(t, "azuread_named_location", "test")
r := NamedLocationResource{}

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

func TestAccNamedLocation_updateCountryByGps(t *testing.T) {
data := acceptance.BuildTestData(t, "azuread_named_location", "test")
r := NamedLocationResource{}

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

func (r NamedLocationResource) Exists(ctx context.Context, clients *clients.Client, state *terraform.InstanceState) (*bool, error) {
client := clients.ConditionalAccess.NamedLocationClient

Expand Down Expand Up @@ -213,6 +257,24 @@ resource "azuread_named_location" "test" {
"JP",
]
include_unknown_countries_and_regions = true
country_lookup_method = "clientIpAddress"
}
}
`, data.RandomInteger)
}

func (NamedLocationResource) completeCountryByGps(data acceptance.TestData) string {
return fmt.Sprintf(`
resource "azuread_named_location" "test" {
display_name = "acctestNLC-%[1]d"
country {
countries_and_regions = [
"GB",
"US",
"JP",
]
include_unknown_countries_and_regions = true
country_lookup_method = "authenticatorAppGps"
}
}
`, data.RandomInteger)
Expand Down

0 comments on commit 3496fd4

Please sign in to comment.