Skip to content

Commit 64128d6

Browse files
author
jiangong
committed
do not assign empty values
1 parent 533c8e3 commit 64128d6

File tree

2 files changed

+133
-8
lines changed

2 files changed

+133
-8
lines changed
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
package provider
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/hashicorp/terraform/helper/resource"
8+
"github.com/hashicorp/terraform/terraform"
9+
10+
"github.com/terraform-providers/terraform-provider-oci/httpreplay"
11+
)
12+
13+
var (
14+
steeringPolicyFailOverRepresentation = map[string]interface{}{
15+
"compartment_id": Representation{repType: Required, create: `${var.compartment_id}`},
16+
"display_name": Representation{repType: Required, create: `displayName`, update: `displayName2`},
17+
"template": Representation{repType: Required, create: `FAILOVER`},
18+
"answers": RepresentationGroup{Optional, steeringPolicyFailOverAnswersRepresentation},
19+
"defined_tags": Representation{repType: Optional, create: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "value")}`, update: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "updatedValue")}`},
20+
"freeform_tags": Representation{repType: Optional, create: map[string]string{"freeformTags": "freeformTags"}, update: map[string]string{"freeformTags2": "freeformTags2"}},
21+
"health_check_monitor_id": Representation{repType: Optional, create: `${oci_health_checks_http_monitor.test_http_monitor.id}`},
22+
"rules": []RepresentationGroup{
23+
{Optional, steeringPolicyFailOverRulesFilterRuleTypeRepresentation},
24+
{Optional, steeringPolicyFailOverRulesHealthRuleTypeRepresentation},
25+
{Optional, steeringPolicyFailOverRulesPriorityRuleTypeRepresentation},
26+
{Optional, steeringPolicyFailOverRulesLimitRuleTypeRepresentation},
27+
},
28+
"ttl": Representation{repType: Optional, create: `10`, update: `11`},
29+
}
30+
31+
steeringPolicyFailOverAnswersRepresentation = map[string]interface{}{
32+
"name": Representation{repType: Required, create: `name`},
33+
"rdata": Representation{repType: Required, create: `192.0.2.1`},
34+
"rtype": Representation{repType: Required, create: `A`},
35+
"is_disabled": Representation{repType: Optional, create: `false`},
36+
"pool": Representation{repType: Optional, create: `primary`},
37+
}
38+
39+
steeringPolicyFailOverRulesFilterRuleTypeRepresentation = map[string]interface{}{
40+
"rule_type": Representation{repType: Required, create: `FILTER`},
41+
"default_answer_data": RepresentationGroup{Optional, steeringPolicyFailOverRulesDefaultAnswerDataFilterRuleTypeRepresentation},
42+
"description": Representation{repType: Optional, create: `filter description`},
43+
}
44+
45+
steeringPolicyFailOverRulesDefaultAnswerDataFilterRuleTypeRepresentation = map[string]interface{}{
46+
"answer_condition": Representation{repType: Optional, create: `answer.isDisabled != true`},
47+
"should_keep": Representation{repType: Optional, create: `true`},
48+
}
49+
50+
steeringPolicyFailOverRulesHealthRuleTypeRepresentation = map[string]interface{}{
51+
"rule_type": Representation{repType: Required, create: `HEALTH`},
52+
"description": Representation{repType: Optional, create: `health description`},
53+
}
54+
55+
steeringPolicyFailOverRulesPriorityRuleTypeRepresentation = map[string]interface{}{
56+
"rule_type": Representation{repType: Required, create: `PRIORITY`},
57+
"default_answer_data": RepresentationGroup{Optional, steeringPolicyFailOverRulesDefaultAnswerDataPriorityRuleTypeRepresentation},
58+
"description": Representation{repType: Optional, create: `priority description`},
59+
}
60+
61+
steeringPolicyFailOverRulesDefaultAnswerDataPriorityRuleTypeRepresentation = map[string]interface{}{
62+
"answer_condition": Representation{repType: Optional, create: `answer.pool == 'primary'`},
63+
"value": Representation{repType: Optional, create: `1`},
64+
}
65+
66+
steeringPolicyFailOverRulesLimitRuleTypeRepresentation = map[string]interface{}{
67+
"rule_type": Representation{repType: Required, create: `LIMIT`},
68+
"default_count": Representation{repType: Optional, create: `1`},
69+
"description": Representation{repType: Optional, create: `limit description`},
70+
}
71+
72+
SteeringPolicyFailOverResourceDependencies = HttpMonitorRequiredOnlyResource
73+
)
74+
75+
func TestResourceDnsSteeringPolicyFailOver(t *testing.T) {
76+
httpreplay.SetScenario("TestResourceDnsSteeringPolicyFailOver")
77+
defer httpreplay.SaveScenario()
78+
79+
provider := testAccProvider
80+
config := testProviderConfig()
81+
82+
compartmentId := getEnvSettingWithBlankDefault("compartment_ocid")
83+
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
84+
85+
resourceName := "oci_dns_steering_policy.test_steering_policy"
86+
87+
content := config + compartmentIdVariableStr + SteeringPolicyFailOverResourceDependencies +
88+
generateResourceFromRepresentationMap("oci_dns_steering_policy", "test_steering_policy", Optional, Create, steeringPolicyFailOverRepresentation)
89+
90+
resource.Test(t, resource.TestCase{
91+
PreCheck: func() { testAccPreCheck(t) },
92+
Providers: map[string]terraform.ResourceProvider{
93+
"oci": provider,
94+
},
95+
CheckDestroy: testAccCheckDnsSteeringPolicyDestroy,
96+
Steps: []resource.TestStep{
97+
// verify create
98+
{
99+
Config: content,
100+
Check: resource.ComposeAggregateTestCheckFunc(
101+
resource.TestCheckResourceAttr(resourceName, "answers.#", "1"),
102+
resource.TestCheckResourceAttr(resourceName, "answers.0.is_disabled", "false"),
103+
resource.TestCheckResourceAttr(resourceName, "answers.0.name", "name"),
104+
resource.TestCheckResourceAttr(resourceName, "answers.0.pool", "primary"),
105+
resource.TestCheckResourceAttr(resourceName, "answers.0.rtype", "A"),
106+
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
107+
resource.TestCheckResourceAttr(resourceName, "defined_tags.%", "1"),
108+
resource.TestCheckResourceAttr(resourceName, "display_name", "displayName"),
109+
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
110+
resource.TestCheckResourceAttrSet(resourceName, "health_check_monitor_id"),
111+
resource.TestCheckResourceAttr(resourceName, "rules.#", "4"),
112+
resource.TestCheckResourceAttr(resourceName, "rules.0.default_answer_data.#", "1"),
113+
resource.TestCheckResourceAttr(resourceName, "rules.0.default_answer_data.0.answer_condition", "answer.isDisabled != true"),
114+
resource.TestCheckResourceAttr(resourceName, "rules.0.default_answer_data.0.should_keep", "true"),
115+
resource.TestCheckResourceAttr(resourceName, "rules.0.description", "filter description"),
116+
resource.TestCheckResourceAttr(resourceName, "rules.0.rule_type", "FILTER"),
117+
resource.TestCheckResourceAttr(resourceName, "rules.1.description", "health description"),
118+
resource.TestCheckResourceAttr(resourceName, "rules.1.rule_type", "HEALTH"),
119+
resource.TestCheckResourceAttr(resourceName, "rules.2.default_answer_data.#", "1"),
120+
resource.TestCheckResourceAttr(resourceName, "rules.2.default_answer_data.0.answer_condition", "answer.pool == 'primary'"),
121+
resource.TestCheckResourceAttr(resourceName, "rules.2.default_answer_data.0.value", "1"),
122+
resource.TestCheckResourceAttr(resourceName, "rules.2.description", "priority description"),
123+
resource.TestCheckResourceAttr(resourceName, "rules.2.rule_type", "PRIORITY"),
124+
resource.TestCheckResourceAttr(resourceName, "rules.3.default_count", "1"),
125+
resource.TestCheckResourceAttr(resourceName, "rules.3.description", "limit description"),
126+
resource.TestCheckResourceAttr(resourceName, "rules.3.rule_type", "LIMIT"),
127+
resource.TestCheckResourceAttr(resourceName, "template", "FAILOVER"),
128+
resource.TestCheckResourceAttr(resourceName, "ttl", "10"),
129+
),
130+
},
131+
},
132+
})
133+
}

oci/dns_steering_policy_resource.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,6 @@ func (s *DnsSteeringPolicyResourceCrud) mapToSteeringPolicyRule(fieldKeyFormat s
809809
switch strings.ToLower(ruleType) {
810810
case strings.ToLower("FILTER"):
811811
details := oci_dns.SteeringPolicyFilterRule{}
812-
details.Cases = []oci_dns.SteeringPolicyFilterRuleCase{}
813812
if cases, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "cases")); ok {
814813
interfaces := cases.([]interface{})
815814
tmp := make([]oci_dns.SteeringPolicyFilterRuleCase, len(interfaces))
@@ -824,7 +823,6 @@ func (s *DnsSteeringPolicyResourceCrud) mapToSteeringPolicyRule(fieldKeyFormat s
824823
}
825824
details.Cases = tmp
826825
}
827-
details.DefaultAnswerData = []oci_dns.SteeringPolicyFilterAnswerData{}
828826
if defaultAnswerData, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "default_answer_data")); ok {
829827
interfaces := defaultAnswerData.([]interface{})
830828
tmp := make([]oci_dns.SteeringPolicyFilterAnswerData, len(interfaces))
@@ -846,7 +844,6 @@ func (s *DnsSteeringPolicyResourceCrud) mapToSteeringPolicyRule(fieldKeyFormat s
846844
baseObject = details
847845
case strings.ToLower("HEALTH"):
848846
details := oci_dns.SteeringPolicyHealthRule{}
849-
details.Cases = []oci_dns.SteeringPolicyHealthRuleCase{}
850847
if cases, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "cases")); ok {
851848
interfaces := cases.([]interface{})
852849
tmp := make([]oci_dns.SteeringPolicyHealthRuleCase, len(interfaces))
@@ -868,7 +865,6 @@ func (s *DnsSteeringPolicyResourceCrud) mapToSteeringPolicyRule(fieldKeyFormat s
868865
baseObject = details
869866
case strings.ToLower("LIMIT"):
870867
details := oci_dns.SteeringPolicyLimitRule{}
871-
details.Cases = []oci_dns.SteeringPolicyLimitRuleCase{}
872868
if cases, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "cases")); ok {
873869
interfaces := cases.([]interface{})
874870
tmp := make([]oci_dns.SteeringPolicyLimitRuleCase, len(interfaces))
@@ -894,7 +890,6 @@ func (s *DnsSteeringPolicyResourceCrud) mapToSteeringPolicyRule(fieldKeyFormat s
894890
baseObject = details
895891
case strings.ToLower("PRIORITY"):
896892
details := oci_dns.SteeringPolicyPriorityRule{}
897-
details.Cases = []oci_dns.SteeringPolicyPriorityRuleCase{}
898893
if cases, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "cases")); ok {
899894
interfaces := cases.([]interface{})
900895
tmp := make([]oci_dns.SteeringPolicyPriorityRuleCase, len(interfaces))
@@ -909,7 +904,6 @@ func (s *DnsSteeringPolicyResourceCrud) mapToSteeringPolicyRule(fieldKeyFormat s
909904
}
910905
details.Cases = tmp
911906
}
912-
details.DefaultAnswerData = []oci_dns.SteeringPolicyPriorityAnswerData{}
913907
if defaultAnswerData, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "default_answer_data")); ok {
914908
interfaces := defaultAnswerData.([]interface{})
915909
tmp := make([]oci_dns.SteeringPolicyPriorityAnswerData, len(interfaces))
@@ -931,7 +925,6 @@ func (s *DnsSteeringPolicyResourceCrud) mapToSteeringPolicyRule(fieldKeyFormat s
931925
baseObject = details
932926
case strings.ToLower("WEIGHTED"):
933927
details := oci_dns.SteeringPolicyWeightedRule{}
934-
details.Cases = []oci_dns.SteeringPolicyWeightedRuleCase{}
935928
if cases, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "cases")); ok {
936929
interfaces := cases.([]interface{})
937930
tmp := make([]oci_dns.SteeringPolicyWeightedRuleCase, len(interfaces))
@@ -946,7 +939,6 @@ func (s *DnsSteeringPolicyResourceCrud) mapToSteeringPolicyRule(fieldKeyFormat s
946939
}
947940
details.Cases = tmp
948941
}
949-
details.DefaultAnswerData = []oci_dns.SteeringPolicyWeightedAnswerData{}
950942
if defaultAnswerData, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "default_answer_data")); ok {
951943
interfaces := defaultAnswerData.([]interface{})
952944
tmp := make([]oci_dns.SteeringPolicyWeightedAnswerData, len(interfaces))

0 commit comments

Comments
 (0)