Skip to content

Commit d104524

Browse files
committed
DNS Tagging
1 parent eef766e commit d104524

File tree

8 files changed

+189
-30
lines changed

8 files changed

+189
-30
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
### Added
99
- Support for attaching Route Table to Subnet. Issue [#270](https://github.com/terraform-providers/terraform-provider-oci/issues/270)
10+
- Support for tagging in `oci_dns_zone`
11+
- New attribute `nameservers` is added to `oci_dns_zone`
1012

1113

1214
## 3.9.0 (December 04, 2018)

oci/dns_zone_resource.go

Lines changed: 87 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ func ZoneResource() *schema.Resource {
4444
},
4545

4646
// Optional
47+
"defined_tags": {
48+
Type: schema.TypeMap,
49+
Optional: true,
50+
Computed: true,
51+
DiffSuppressFunc: definedTagsDiffSuppressFunction,
52+
Elem: schema.TypeString,
53+
},
4754
"external_masters": {
4855
Type: schema.TypeList,
4956
Optional: true,
@@ -95,8 +102,31 @@ func ZoneResource() *schema.Resource {
95102
},
96103
},
97104
},
105+
"freeform_tags": {
106+
Type: schema.TypeMap,
107+
Optional: true,
108+
Computed: true,
109+
Elem: schema.TypeString,
110+
},
98111

99112
// Computed
113+
"nameservers": {
114+
Type: schema.TypeList,
115+
Computed: true,
116+
Elem: &schema.Resource{
117+
Schema: map[string]*schema.Schema{
118+
// Required
119+
120+
// Optional
121+
122+
// Computed
123+
"hostname": {
124+
Type: schema.TypeString,
125+
Computed: true,
126+
},
127+
},
128+
},
129+
},
100130
"self": {
101131
Type: schema.TypeString,
102132
Computed: true,
@@ -173,6 +203,14 @@ func (s *ZoneResourceCrud) Create() error {
173203
request.CreateZoneDetails.CompartmentId = &tmp
174204
}
175205

206+
if definedTags, ok := s.D.GetOkExists("defined_tags"); ok {
207+
convertedDefinedTags, err := mapToDefinedTags(definedTags.(map[string]interface{}))
208+
if err != nil {
209+
return err
210+
}
211+
request.DefinedTags = convertedDefinedTags
212+
}
213+
176214
request.ExternalMasters = []oci_dns.ExternalMaster{}
177215
if externalMasters, ok := s.D.GetOkExists("external_masters"); ok {
178216
interfaces := externalMasters.([]interface{})
@@ -189,6 +227,10 @@ func (s *ZoneResourceCrud) Create() error {
189227
request.ExternalMasters = tmp
190228
}
191229

230+
if freeformTags, ok := s.D.GetOkExists("freeform_tags"); ok {
231+
request.FreeformTags = objectMapToStringMap(freeformTags.(map[string]interface{}))
232+
}
233+
192234
if name, ok := s.D.GetOkExists("name"); ok {
193235
tmp := name.(string)
194236
request.Name = &tmp
@@ -199,6 +241,7 @@ func (s *ZoneResourceCrud) Create() error {
199241
}
200242

201243
request.RequestMetadata.RetryPolicy = getRetryPolicy(s.DisableNotFoundRetries, "dns")
244+
202245
response, err := s.Client.CreateZone(context.Background(), request)
203246
if err != nil {
204247
return err
@@ -220,6 +263,7 @@ func (s *ZoneResourceCrud) Get() error {
220263
request.ZoneNameOrId = &tmp
221264

222265
request.RequestMetadata.RetryPolicy = getRetryPolicy(s.DisableNotFoundRetries, "dns")
266+
223267
response, err := s.Client.GetZone(context.Background(), request)
224268
if err != nil {
225269
return err
@@ -232,14 +276,19 @@ func (s *ZoneResourceCrud) Get() error {
232276
func (s *ZoneResourceCrud) Update() error {
233277
request := oci_dns.UpdateZoneRequest{}
234278

235-
tmp := s.D.Id()
236-
request.ZoneNameOrId = &tmp
237-
238279
if compartmentId, ok := s.D.GetOkExists("compartment_id"); ok {
239280
tmp := compartmentId.(string)
240281
request.CompartmentId = &tmp
241282
}
242283

284+
if definedTags, ok := s.D.GetOkExists("defined_tags"); ok {
285+
convertedDefinedTags, err := mapToDefinedTags(definedTags.(map[string]interface{}))
286+
if err != nil {
287+
return err
288+
}
289+
request.DefinedTags = convertedDefinedTags
290+
}
291+
243292
request.ExternalMasters = []oci_dns.ExternalMaster{}
244293
if externalMasters, ok := s.D.GetOkExists("external_masters"); ok {
245294
interfaces := externalMasters.([]interface{})
@@ -256,7 +305,15 @@ func (s *ZoneResourceCrud) Update() error {
256305
request.ExternalMasters = tmp
257306
}
258307

308+
if freeformTags, ok := s.D.GetOkExists("freeform_tags"); ok {
309+
request.FreeformTags = objectMapToStringMap(freeformTags.(map[string]interface{}))
310+
}
311+
312+
tmp := s.D.Id()
313+
request.ZoneNameOrId = &tmp
314+
259315
request.RequestMetadata.RetryPolicy = getRetryPolicy(s.DisableNotFoundRetries, "dns")
316+
260317
response, err := s.Client.UpdateZone(context.Background(), request)
261318
if err != nil {
262319
return err
@@ -289,11 +346,27 @@ func (s *ZoneResourceCrud) SetData() error {
289346
s.D.Set("compartment_id", *s.Res.CompartmentId)
290347
}
291348

349+
if s.Res.DefinedTags != nil {
350+
s.D.Set("defined_tags", definedTagsToMap(s.Res.DefinedTags))
351+
}
352+
353+
externalMasters := []interface{}{}
354+
for _, item := range s.Res.ExternalMasters {
355+
externalMasters = append(externalMasters, ExternalMasterToMap(item))
356+
}
357+
s.D.Set("external_masters", externalMasters)
358+
359+
s.D.Set("freeform_tags", s.Res.FreeformTags)
360+
292361
if s.Res.Name != nil {
293362
s.D.Set("name", *s.Res.Name)
294363
}
295364

296-
// todo: zone entities have a "nameservers" list which is missing from the spec and should be added here when sdk is regenerated
365+
nameservers := []interface{}{}
366+
for _, item := range s.Res.Nameservers {
367+
nameservers = append(nameservers, NameserverToMap(item))
368+
}
369+
s.D.Set("nameservers", nameservers)
297370

298371
if s.Res.Self != nil {
299372
s.D.Set("self", *s.Res.Self)
@@ -309,12 +382,6 @@ func (s *ZoneResourceCrud) SetData() error {
309382

310383
s.D.Set("zone_type", s.Res.ZoneType)
311384

312-
externalMasters := []interface{}{}
313-
for _, item := range s.Res.ExternalMasters {
314-
externalMasters = append(externalMasters, ExternalMasterToMap(item))
315-
}
316-
s.D.Set("external_masters", externalMasters)
317-
318385
s.D.Set("state", s.Res.LifecycleState)
319386

320387
s.D.Set("time_created", s.Res.TimeCreated.String())
@@ -367,6 +434,16 @@ func ExternalMasterToMap(obj oci_dns.ExternalMaster) map[string]interface{} {
367434
return result
368435
}
369436

437+
func NameserverToMap(obj oci_dns.Nameserver) map[string]interface{} {
438+
result := map[string]interface{}{}
439+
440+
if obj.Hostname != nil {
441+
result["hostname"] = string(*obj.Hostname)
442+
}
443+
444+
return result
445+
}
446+
370447
func (s *ZoneResourceCrud) mapToTSIG(fieldKeyFormat string) (oci_dns.Tsig, error) {
371448
result := oci_dns.Tsig{}
372449

oci/dns_zone_test.go

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ var (
5252
"compartment_id": Representation{repType: Required, create: `${var.compartment_id}`},
5353
"name": Representation{repType: Required, create: `${data.oci_identity_tenancy.test_tenancy.name}.{{.token}}.oci-zone-test`},
5454
"zone_type": Representation{repType: Required, create: `PRIMARY`},
55+
"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")}`},
5556
"external_masters": RepresentationGroup{Optional, zoneExternalMastersRepresentation},
57+
"freeform_tags": Representation{repType: Optional, create: map[string]string{"bar-key": "value"}, update: map[string]string{"Department": "Accounting"}},
5658
}
5759
zoneRepresentation = getUpdatedRepresentationCopy("zone_type", "SECONDARY", zoneRepresentationPrimary)
5860

@@ -67,7 +69,7 @@ var (
6769
"secret": Representation{repType: Required, create: `c2VjcmV0`, update: `secret2`},
6870
}
6971

70-
ZoneResourceDependencies = `
72+
ZoneResourceDependencies = DefinedTagsDependencies + `
7173
data "oci_identity_tenancy" "test_tenancy" {
7274
tenancy_id = "${var.tenancy_ocid}"
7375
}
@@ -85,7 +87,7 @@ func TestDnsZoneResource_basic(t *testing.T) {
8587
datasourceName := "data.oci_dns_zones.test_zones"
8688

8789
_, tokenFn := tokenize()
88-
var resId string
90+
var resId, resId2 string
8991

9092
resource.Test(t, resource.TestCase{
9193
PreCheck: func() { testAccPreCheck(t) },
@@ -104,7 +106,7 @@ func TestDnsZoneResource_basic(t *testing.T) {
104106
resource.TestCheckResourceAttr(resourceName, "zone_type", "PRIMARY"),
105107

106108
func(s *terraform.State) (err error) {
107-
resId, err = fromInstanceState(s, resourceName, "id")
109+
_, err = fromInstanceState(s, resourceName, "id")
108110
return err
109111
},
110112
),
@@ -139,6 +141,50 @@ func TestDnsZoneResource_basic(t *testing.T) {
139141
),
140142
},
141143
*/
144+
// delete before next create
145+
{
146+
Config: tokenFn(config+compartmentIdVariableStr+ZoneResourceDependencies, nil),
147+
},
148+
// verify create with optionals
149+
{
150+
Config: tokenFn(config+compartmentIdVariableStr+ZoneResourceDependencies+
151+
generateResourceFromRepresentationMap("oci_dns_zone", "test_zone", Optional, Create,
152+
representationCopyWithRemovedProperties(zoneRepresentationPrimary, []string{"external_masters"})), nil),
153+
Check: resource.ComposeAggregateTestCheckFunc(
154+
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
155+
resource.TestMatchResourceAttr(resourceName, "name", regexp.MustCompile("\\.oci-zone-test")),
156+
resource.TestCheckResourceAttr(resourceName, "zone_type", "PRIMARY"),
157+
resource.TestCheckResourceAttr(resourceName, "defined_tags.%", "1"),
158+
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
159+
resource.TestCheckResourceAttrSet(resourceName, "nameservers.#"),
160+
161+
func(s *terraform.State) (err error) {
162+
resId, err = fromInstanceState(s, resourceName, "id")
163+
return err
164+
},
165+
),
166+
},
167+
// verify updates to updatable parameters
168+
{
169+
Config: tokenFn(config+compartmentIdVariableStr+ZoneResourceDependencies+
170+
generateResourceFromRepresentationMap("oci_dns_zone", "test_zone", Optional, Update,
171+
representationCopyWithRemovedProperties(zoneRepresentationPrimary, []string{"external_masters"})), nil),
172+
Check: resource.ComposeAggregateTestCheckFunc(
173+
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
174+
resource.TestCheckResourceAttr(resourceName, "defined_tags.%", "1"),
175+
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
176+
resource.TestMatchResourceAttr(resourceName, "name", regexp.MustCompile("\\.oci-zone-test")),
177+
resource.TestCheckResourceAttr(resourceName, "zone_type", "PRIMARY"),
178+
179+
func(s *terraform.State) (err error) {
180+
resId2, err = fromInstanceState(s, resourceName, "id")
181+
if resId != resId2 {
182+
return fmt.Errorf("Resource recreated when it was supposed to be updated.")
183+
}
184+
return err
185+
},
186+
),
187+
},
142188
// verify datasource
143189
{
144190
Config: tokenFn(config+generateDataSourceFromRepresentationMap("oci_dns_zones", "test_zones", Optional, Create, zoneDataSourceRepresentationRequiredOnlyWithFilter)+
@@ -147,6 +193,9 @@ func TestDnsZoneResource_basic(t *testing.T) {
147193
Check: resource.ComposeAggregateTestCheckFunc(
148194
resource.TestCheckResourceAttr(datasourceName, "compartment_id", compartmentId),
149195
resource.TestCheckResourceAttr(datasourceName, "zones.#", "1"),
196+
resource.TestCheckResourceAttr(datasourceName, "zones.0.defined_tags.%", "1"),
197+
resource.TestCheckResourceAttr(datasourceName, "zones.0.freeform_tags.%", "1"),
198+
resource.TestCheckResourceAttrSet(datasourceName, "zones.0.nameservers.#"),
150199
),
151200
},
152201
{
@@ -156,6 +205,8 @@ func TestDnsZoneResource_basic(t *testing.T) {
156205
Check: resource.ComposeAggregateTestCheckFunc(
157206
resource.TestMatchResourceAttr(datasourceName, "name", regexp.MustCompile("\\.oci-zone-test")),
158207
resource.TestCheckResourceAttr(datasourceName, "zones.#", "1"),
208+
resource.TestCheckResourceAttr(datasourceName, "zones.0.defined_tags.%", "1"),
209+
resource.TestCheckResourceAttr(datasourceName, "zones.0.freeform_tags.%", "1"),
159210
),
160211
},
161212
{
@@ -165,6 +216,8 @@ func TestDnsZoneResource_basic(t *testing.T) {
165216
Check: resource.ComposeAggregateTestCheckFunc(
166217
resource.TestCheckResourceAttr(datasourceName, "name_contains", "oci-zone-test"),
167218
resource.TestCheckResourceAttrSet(datasourceName, "zones.#"),
219+
resource.TestCheckResourceAttr(datasourceName, "zones.0.defined_tags.%", "1"),
220+
resource.TestCheckResourceAttr(datasourceName, "zones.0.freeform_tags.%", "1"),
168221
),
169222
},
170223
{
@@ -174,6 +227,8 @@ func TestDnsZoneResource_basic(t *testing.T) {
174227
Check: resource.ComposeAggregateTestCheckFunc(
175228
resource.TestCheckResourceAttr(datasourceName, "state", "ACTIVE"),
176229
resource.TestCheckResourceAttrSet(datasourceName, "zones.#"),
230+
resource.TestCheckResourceAttr(datasourceName, "zones.0.defined_tags.%", "1"),
231+
resource.TestCheckResourceAttr(datasourceName, "zones.0.freeform_tags.%", "1"),
177232
),
178233
},
179234
{
@@ -183,6 +238,8 @@ func TestDnsZoneResource_basic(t *testing.T) {
183238
Check: resource.ComposeAggregateTestCheckFunc(
184239
resource.TestCheckResourceAttr(datasourceName, "zone_type", "PRIMARY"),
185240
resource.TestCheckResourceAttrSet(datasourceName, "zones.#"),
241+
resource.TestCheckResourceAttr(datasourceName, "zones.0.defined_tags.%", "1"),
242+
resource.TestCheckResourceAttr(datasourceName, "zones.0.freeform_tags.%", "1"),
186243
),
187244
},
188245
{
@@ -193,6 +250,8 @@ func TestDnsZoneResource_basic(t *testing.T) {
193250
resource.TestCheckResourceAttr(datasourceName, "compartment_id", compartmentId),
194251
resource.TestCheckResourceAttr(datasourceName, "time_created_greater_than_or_equal_to", "2018-01-01T00:00:00.000Z"),
195252
resource.TestCheckResourceAttrSet(datasourceName, "zones.#"),
253+
resource.TestCheckResourceAttr(datasourceName, "zones.0.defined_tags.%", "1"),
254+
resource.TestCheckResourceAttr(datasourceName, "zones.0.freeform_tags.%", "1"),
196255
),
197256
},
198257
{
@@ -203,6 +262,8 @@ func TestDnsZoneResource_basic(t *testing.T) {
203262
resource.TestCheckResourceAttr(datasourceName, "compartment_id", compartmentId),
204263
resource.TestCheckResourceAttr(datasourceName, "time_created_less_than", "2022-04-10T19:01:09.000-00:00"),
205264
resource.TestCheckResourceAttrSet(datasourceName, "zones.#"),
265+
resource.TestCheckResourceAttr(datasourceName, "zones.0.defined_tags.%", "1"),
266+
resource.TestCheckResourceAttr(datasourceName, "zones.0.freeform_tags.%", "1"),
206267
),
207268
},
208269
// verify resource import

oci/dns_zones_data_source.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ func (s *ZonesDataSourceCrud) Get() error {
157157
s.Res.Items = append(s.Res.Items, listResponse.Items...)
158158
request.Page = listResponse.OpcNextPage
159159
}
160+
160161
return nil
161162
}
162163

@@ -173,6 +174,12 @@ func (s *ZonesDataSourceCrud) SetData() error {
173174
"compartment_id": *r.CompartmentId,
174175
}
175176

177+
if r.DefinedTags != nil {
178+
zone["defined_tags"] = definedTagsToMap(r.DefinedTags)
179+
}
180+
181+
zone["freeform_tags"] = r.FreeformTags
182+
176183
if r.Id != nil {
177184
zone["id"] = *r.Id
178185
}

website/docs/d/dns_records.html.markdown

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This data source provides the list of Records in Oracle Cloud Infrastructure Dns
1111

1212
Gets all records in the specified zone. The results are
1313
sorted by `domain` in alphabetical order by default. For more
14-
information about records, please see [Resource Record (RR) TYPEs](https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-4).
14+
information about records, see [Resource Record (RR) TYPEs](https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-4).
1515

1616

1717
## Example Usage
@@ -37,7 +37,7 @@ The following arguments are supported:
3737
* `compartment_id` - (Optional) The OCID of the compartment the resource belongs to.
3838
* `domain` - (Optional) Search by domain. Will match any record whose domain (case-insensitive) equals the provided value.
3939
* `domain_contains` - (Optional) Search by domain. Will match any record whose domain (case-insensitive) contains the provided value.
40-
* `rtype` - (Optional) Search by record type. Will match any record whose [type](https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-4) (case-insensitive) equals the provided value.
40+
* `rtype` - (Optional) Search by record type. Will match any record whose [type](https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-4) (case-insensitive) equals the provided value.
4141
* `sort_by` - (Optional) The field by which to sort records. Allowed values are: domain|rtype|ttl
4242
* `sort_order` - The order to sort the resources. Allowed values are: ASC|DESC
4343
* `zone_name_or_id` - (Required) The name or OCID of the target zone.
@@ -57,7 +57,7 @@ The following attributes are exported:
5757
* `compartment_id` - The OCID of the compartment the resource belongs to.
5858
* `domain` - The fully qualified domain name where the record can be located.
5959
* `is_protected` - A Boolean flag indicating whether or not parts of the record are unable to be explicitly managed.
60-
* `rdata` - The record's data, as whitespace-delimited tokens in type-specific presentation format.
60+
* `rdata` - The record's data, as whitespace-delimited tokens in type-specific presentation format. All RDATA is normalized and the returned presentation of your RDATA may differ from its initial input. For more information about RDATA, see [Supported DNS Resource Record Types](/iaas/Content/DNS/Reference/supporteddnsresource.htm)
6161
* `record_hash` - A unique identifier for the record within its zone.
6262
* `rrset_version` - The latest version of the record's zone in which its RRSet differs from the preceding version.
6363
* `rtype` - The canonical name for the record's type, such as A or CNAME. For more information, see [Resource Record (RR) TYPEs](https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-4).

0 commit comments

Comments
 (0)