|
| 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 | +} |
0 commit comments