Skip to content

Commit cb4966b

Browse files
committed
case insensitive search in singular AD
1 parent 27d098d commit cb4966b

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

examples/networking/vcn/vcn.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ resource "oci_core_vcn" "vcn1" {
2424

2525
output "vcn_id" {
2626
value = "${oci_core_vcn.vcn1.id}"
27-
}
27+
}

oci/identity_availability_domain_data_source.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ func (s *AvailabilityDomainDataSourceCrud) SetData() error {
127127
}
128128

129129
func adNumberFromName(adName string) int {
130-
regex := regexp.MustCompile(`AD-(\d)`)
130+
// case insensitive matching
131+
regex := regexp.MustCompile(`(?i)AD-(\d)`)
131132
res := regex.FindAllStringSubmatch(adName, -1)
132133

133134
// no matching AD name

oci/identity_availability_domain_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,21 @@ func TestIdentityAvailabilityDomainResource_basic(t *testing.T) {
7171
resource.TestCheckResourceAttrSet(singularDatasourceName, "id"),
7272
resource.TestCheckResourceAttr(singularDatasourceName, "ad_number", "2"),
7373
resource.TestMatchResourceAttr(singularDatasourceName, "name", regexp.MustCompile(`\w+-AD-2`)),
74+
func(s *terraform.State) (err error) {
75+
adName, err := fromInstanceState(s, singularDatasourceName, "name")
76+
if err != nil {
77+
return err
78+
}
79+
80+
regex := regexp.MustCompile(`(?i)AD-(\d)`)
81+
res := regex.FindAllStringSubmatch(adName, -1)
82+
83+
// no matching AD name
84+
if res == nil || len(res) < 1 {
85+
fmt.Errorf("No match found for case insensitive search")
86+
}
87+
return err
88+
},
7489
),
7590
},
7691
},

0 commit comments

Comments
 (0)