Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(PDNS): update custom resolver profile and views. #5625

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4121186
feat(PDNS): update custom resolver profile and views
arjunchauhanibm Sep 6, 2024
8df588a
fix minor warnigns
arjunchauhanibm Sep 6, 2024
c379260
add example
arjunchauhanibm Sep 6, 2024
d20fbf8
add documentation
arjunchauhanibm Sep 6, 2024
afb56ac
change variable names
arjunchauhanibm Sep 6, 2024
dc780d6
fix styling
arjunchauhanibm Sep 6, 2024
a04bd55
add validator for profile
arjunchauhanibm Sep 6, 2024
3ba5012
modify example
arjunchauhanibm Sep 7, 2024
1097e5b
improve error message
arjunchauhanibm Sep 22, 2024
8d124a4
modified docs
arjunchauhanibm Sep 23, 2024
31780ce
fix error message
arjunchauhanibm Sep 23, 2024
b7ed734
incorporate review comments for documentation
arjunchauhanibm Oct 13, 2024
57c87c0
add order in views and fix minor bugs
arjunchauhanibm Oct 16, 2024
50bbf8e
change the variable instance
arjunchauhanibm Oct 16, 2024
f6ddd4e
changing update logic for views
arjunchauhanibm Oct 19, 2024
0335f54
modified test for linked zone
arjunchauhanibm Oct 22, 2024
95ecf4d
add test for custom resolver profile
arjunchauhanibm Oct 22, 2024
4c72d23
add test for forwarding rule views
arjunchauhanibm Oct 22, 2024
5c37702
fix acceptance test FR
arjunchauhanibm Oct 27, 2024
47963f4
Merge branch 'master' into add_views
arjunchauhanibm Oct 27, 2024
004b648
change message format
arjunchauhanibm Nov 4, 2024
3c9d284
change fields to computed in data source file
arjunchauhanibm Nov 12, 2024
4328e8e
incorporated doc review changes
arjunchauhanibm Jan 6, 2025
2df0ad2
Merge branch 'master' into add_views
arjunchauhanibm Jan 11, 2025
3565838
fix go mod issues
arjunchauhanibm Jan 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions examples/ibm-private-dns/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ resource "ibm_dns_custom_resolver" "test" {
name = "testCR-TF"
instance_id = ibm_resource_instance.test-pdns-instance.guid
description = "testdescription-CR"
profile = "essential"
allow_disruptive_updates = false
locations {
subnet_crn = "crn:v1:staging:public:is:us-south-1:a/01652b251c3ae2787110a995d8db0135::subnet:0716-6c3a997d-72b2-47f6-8788-6bd95e1bdb03"
enabled = false
Expand All @@ -203,6 +205,8 @@ resource "ibm_dns_custom_resolver" "test" {
description = "new test CR TF-1"
high_availability = true
enabled = true
profile = "essential"
allow_disruptive_updates = false
locations {
subnet_crn = "crn:v1:staging:public:is:us-south-1:a/01652b251c3ae2787110a995d8db0135::subnet:0716-a094c4e8-02cd-4b04-858d-3432"
enabled = false
Expand Down Expand Up @@ -236,6 +240,12 @@ resource "ibm_dns_custom_resolver_forwarding_rule" "test" {
type = "zone"
match = "test.example.com"
forward_to = ["168.20.22.122"]
views {
name = "view-example-name"
description = "view description"
expression = "ipInRange(source.ip, '10.240.0.0/24') || ipInRange(source.ip, '10.240.1.0/24')"
forward_to = ["10.240.2.6","10.240.2.7"]
}
}

data "ibm_dns_custom_resolver_forwarding_rules" "test-fr" {
Expand Down
1 change: 1 addition & 0 deletions ibm/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1863,6 +1863,7 @@ func Validator() validate.ValidatorDict {
"ibm_is_reservation": vpc.ResourceIBMISReservationValidator(),
"ibm_kms_key_rings": kms.ResourceIBMKeyRingValidator(),
"ibm_dns_glb_monitor": dnsservices.ResourceIBMPrivateDNSGLBMonitorValidator(),
"ibm_dns_custom_resolver": dnsservices.ResourceIBMPrivateDNSCustomResolverValidator(),
"ibm_dns_custom_resolver_forwarding_rule": dnsservices.ResourceIBMPrivateDNSForwardingRuleValidator(),
"ibm_schematics_action": schematics.ResourceIBMSchematicsActionValidator(),
"ibm_schematics_job": schematics.ResourceIBMSchematicsJobValidator(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@
Type: schema.TypeString,
Computed: true,
},
pdnsCRProfile: {
Type: schema.TypeString,
arjunchauhanibm marked this conversation as resolved.
Show resolved Hide resolved
Optional: true,
Default: "essential",
Description: "The profile name of the custom resolver.",
},
pdnsCRAllowDisruptiveUpdates: {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Whether disruptive update is allowed for the custom resolver",
},
pdnsCustomResolverLocations: {
Type: schema.TypeList,
Description: "Locations on which the custom resolver will be running",
Expand Down Expand Up @@ -109,17 +121,19 @@
customResolver[pdnsCRDescription] = *instance.Description
customResolver[pdnsCRHealth] = *instance.Health
customResolver[pdnsCREnabled] = *instance.Enabled
customResolver[pdnsCRProfile] = *instance.Profile

Check failure on line 124 in ibm/service/dnsservices/data_source_ibm_private_dns_custom_resolver.go

View workflow job for this annotation

GitHub Actions / Build

instance.Profile undefined (type dnssvcsv1.CustomResolver has no field or method Profile)
customResolver[pdnsCRAllowDisruptiveUpdates] = *instance.AllowDisruptiveUpdates

Check failure on line 125 in ibm/service/dnsservices/data_source_ibm_private_dns_custom_resolver.go

View workflow job for this annotation

GitHub Actions / Build

instance.AllowDisruptiveUpdates undefined (type dnssvcsv1.CustomResolver has no field or method AllowDisruptiveUpdates)
customResolver[pdnsCustomResolverLocations] = flattenPdnsCRLocations(instance.Locations)

customResolvers = append(customResolvers, customResolver)
}
d.SetId(dataSourceIBMPrivateDNSCustomResolverID(d))
d.SetId(dataSourceIBMPrivateDNSCustomResolverID())
d.Set(pdnsInstanceID, instanceID)
d.Set(pdnsCustomResolvers, customResolvers)
return nil
}

// dataSourceIBMPrivateDNSCustomResolverID returns a reasonable ID for dns custom resolver list.
func dataSourceIBMPrivateDNSCustomResolverID(d *schema.ResourceData) string {
func dataSourceIBMPrivateDNSCustomResolverID() string {
return time.Now().UTC().String()
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,36 @@
Type: schema.TypeString,
},
},
pdnsCRFRViews: {
arjunchauhanibm marked this conversation as resolved.
Show resolved Hide resolved
Type: schema.TypeSet,
Description: "An array of views used by forwarding rules",
arjunchauhanibm marked this conversation as resolved.
Show resolved Hide resolved
arjunchauhanibm marked this conversation as resolved.
Show resolved Hide resolved
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
pdnsCRFRVName: {
Type: schema.TypeString,
Required: true,
Description: "Unique name of the view.",
},
pdnsCRFRVDescription: {
Type: schema.TypeString,
Optional: true,
Description: "Description of the view.",
},
pdnsCRFRVExpression: {
Type: schema.TypeString,
Required: true,
Description: "Expression of the view.",
},
pdnsCRFRVForwardTo: {
Type: schema.TypeList,
Required: true,
Description: "The upstream DNS servers will be forwarded to.",
arjunchauhanibm marked this conversation as resolved.
Show resolved Hide resolved
Elem: &schema.Schema{Type: schema.TypeString},
},
},
},
},
},
},
},
Expand Down Expand Up @@ -91,16 +121,17 @@
forwardRule[pdnsCRFRType] = *instance.Type
forwardRule[pdnsCRFRMatch] = *instance.Match
forwardRule[pdnsCRFRForwardTo] = instance.ForwardTo
forwardRule[pdnsCRFRViews] = flattenPDNSFRViews(instance.Views)

Check failure on line 124 in ibm/service/dnsservices/data_source_ibm_private_dns_custom_resolver_forwarding_rules.go

View workflow job for this annotation

GitHub Actions / Build

instance.Views undefined (type dnssvcsv1.ForwardingRule has no field or method Views)
arjunchauhanibm marked this conversation as resolved.
Show resolved Hide resolved

forwardRules = append(forwardRules, forwardRule)
}
d.SetId(dataSourceIBMPrivateDNSForwardrulesID(d))
d.SetId(dataSourceIBMPrivateDNSForwardrulesID())
d.Set(pdnsInstanceID, instanceID)
d.Set(pdnsCRFRResolverID, resolverID)
d.Set(pdnsCRForwardRules, forwardRules)
return nil
}

func dataSourceIBMPrivateDNSForwardrulesID(d *schema.ResourceData) string {
func dataSourceIBMPrivateDNSForwardrulesID() string {
return time.Now().UTC().String()
}
4 changes: 1 addition & 3 deletions ibm/service/dnsservices/resource_ibm_dns_linked_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,10 @@
}
ownerInstanceID := d.Get(DnsLinkedZoneOwnerInstanceID).(string)
ownerZoneID := d.Get(DnsLinkedZoneOwnerZoneID).(string)
createLinkedZoneOptions := sess.NewCreateLinkedZoneOptions(instanceID)
createLinkedZoneOptions := sess.NewCreateLinkedZoneOptions(instanceID, ownerInstanceID, ownerZoneID)

Check failure on line 123 in ibm/service/dnsservices/resource_ibm_dns_linked_zone.go

View workflow job for this annotation

GitHub Actions / Build

too many arguments in call to sess.NewCreateLinkedZoneOptions
arjunchauhanibm marked this conversation as resolved.
Show resolved Hide resolved

createLinkedZoneOptions.SetDescription(description)
createLinkedZoneOptions.SetLabel(label)
createLinkedZoneOptions.SetOwnerInstanceID(ownerInstanceID)
createLinkedZoneOptions.SetOwnerZoneID(ownerZoneID)
mk := "dns_linked_zone_" + instanceID
conns.IbmMutexKV.Lock(mk)
defer conns.IbmMutexKV.Unlock(mk)
Expand Down
124 changes: 99 additions & 25 deletions ibm/service/dnsservices/resource_ibm_private_dns_custom_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/validate"
"github.com/IBM/networking-go-sdk/dnssvcsv1"

"github.com/IBM/go-sdk-core/v5/core"
Expand All @@ -21,25 +22,27 @@
)

const (
ibmDNSCustomResolver = "ibm_dns_custom_resolver"
pdnsCustomResolvers = "custom_resolvers"
pdnsCustomResolverLocations = "locations"
pdnsCRId = "custom_resolver_id"
pdnsCRName = "name"
pdnsCRDescription = "description"
pdnsCRHealth = "health"
pdnsCREnabled = "enabled"
pdnsCRCreatedOn = "created_on"
pdnsCRModifiedOn = "modified_on"
pdnsCRLocationId = "location_id"
pdnsCRLocationSubnetCrn = "subnet_crn"
pdnsCRLocationEnabled = "enabled"
pdnsCRLocationHealthy = "healthy"
pdnsCRLocationDnsServerIp = "dns_server_ip"
pdnsCustomResolverCritical = "CRITICAL"
pdnsCustomResolverDegraded = "DEGRADED"
pdnsCustomResolverHealthy = "HEALTHY"
pdnsCRHighAvailability = "high_availability"
ibmDNSCustomResolver = "ibm_dns_custom_resolver"
pdnsCustomResolvers = "custom_resolvers"
pdnsCustomResolverLocations = "locations"
pdnsCRId = "custom_resolver_id"
pdnsCRName = "name"
pdnsCRDescription = "description"
pdnsCRHealth = "health"
pdnsCREnabled = "enabled"
pdnsCRCreatedOn = "created_on"
pdnsCRModifiedOn = "modified_on"
pdnsCRLocationId = "location_id"
pdnsCRLocationSubnetCrn = "subnet_crn"
pdnsCRLocationEnabled = "enabled"
pdnsCRLocationHealthy = "healthy"
pdnsCRLocationDnsServerIp = "dns_server_ip"
pdnsCustomResolverCritical = "CRITICAL"
pdnsCustomResolverDegraded = "DEGRADED"
pdnsCustomResolverHealthy = "HEALTHY"
pdnsCRHighAvailability = "high_availability"
pdnsCRProfile = "profile"
pdnsCRAllowDisruptiveUpdates = "allow_disruptive_updates"
)

func ResourceIBMPrivateDNSCustomResolver() *schema.Resource {
Expand Down Expand Up @@ -132,6 +135,19 @@
},
},
},
pdnsCRProfile: {
Type: schema.TypeString,
Optional: true,
Default: "essential",
Description: "The profile name of the custom resolver.",
ValidateFunc: validate.InvokeValidator(ibmDNSCustomResolver, pdnsCRProfile),
},
pdnsCRAllowDisruptiveUpdates: {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Whether disruptive update is allowed for the custom resolver",
},
pdnsCRForwardRules: {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -165,6 +181,36 @@
Type: schema.TypeString,
},
},
pdnsCRFRViews: {
Type: schema.TypeSet,
Description: "An array of views used by forwarding rules",
arjunchauhanibm marked this conversation as resolved.
Show resolved Hide resolved
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
pdnsCRFRVName: {
Type: schema.TypeString,
Required: true,
Description: "Unique name of the view.",
},
pdnsCRFRVDescription: {
Type: schema.TypeString,
Optional: true,
Description: "Description of the view.",
},
pdnsCRFRVExpression: {
Type: schema.TypeString,
Required: true,
Description: "Expression of the view.",
},
pdnsCRFRVForwardTo: {
Type: schema.TypeList,
Required: true,
Description: "The upstream DNS servers will be forwarded to.",
arjunchauhanibm marked this conversation as resolved.
Show resolved Hide resolved
Elem: &schema.Schema{Type: schema.TypeString},
},
},
},
},
},
},
},
Expand All @@ -183,6 +229,21 @@
}
}

func ResourceIBMPrivateDNSCustomResolverValidator() *validate.ResourceValidator {
validateSchema := make([]validate.ValidateSchema, 0)
validateSchema = append(validateSchema,
validate.ValidateSchema{
Identifier: pdnsCRProfile,
ValidateFunctionIdentifier: validate.ValidateAllowedStringValue,
Type: validate.TypeString,
Optional: true,
AllowedValues: "essential, advanced, premier",
},
)
resourceValidator := validate.ResourceValidator{ResourceName: ibmDNSCustomResolver, Schema: validateSchema}
return &resourceValidator
}

type location struct {
locationId string
subnet string
Expand All @@ -205,10 +266,11 @@
if des, ok := d.GetOk(pdnsCRDescription); ok {
crDescription = des.(string)
}
crProfile := d.Get(pdnsCRProfile).(string)

customResolverOption := sess.NewCreateCustomResolverOptions(crn)
customResolverOption.SetName(crName)
customResolverOption := sess.NewCreateCustomResolverOptions(crn, crName)

Check failure on line 271 in ibm/service/dnsservices/resource_ibm_private_dns_custom_resolver.go

View workflow job for this annotation

GitHub Actions / Build

too many arguments in call to sess.NewCreateCustomResolverOptions
customResolverOption.SetDescription(crDescription)
customResolverOption.SetProfile(crProfile)

Check failure on line 273 in ibm/service/dnsservices/resource_ibm_private_dns_custom_resolver.go

View workflow job for this annotation

GitHub Actions / Build

customResolverOption.SetProfile undefined (type *dnssvcsv1.CreateCustomResolverOptions has no field or method SetProfile)

cr_highaval := d.Get(pdnsCRHighAvailability).(bool)

Expand Down Expand Up @@ -294,6 +356,7 @@
forwardRule[pdnsCRFRType] = *instance.Type
forwardRule[pdnsCRFRMatch] = *instance.Match
forwardRule[pdnsCRFRForwardTo] = instance.ForwardTo
forwardRule[pdnsCRFRViews] = flattenPDNSFRViews(instance.Views)
forwardRules = append(forwardRules, forwardRule)
}
d.Set(pdnsInstanceID, crn)
Expand All @@ -304,6 +367,8 @@
d.Set(pdnsCREnabled, *result.Enabled)
d.Set(pdnsCustomResolverLocations, flattenPdnsCRLocations(result.Locations))
d.Set(pdnsCRForwardRules, forwardRules)
d.Set(pdnsCRProfile, *result.Profile)
d.Set(pdnsCRAllowDisruptiveUpdates, *result.AllowDisruptiveUpdates)
return nil
}

Expand Down Expand Up @@ -331,7 +396,9 @@
if d.HasChange(pdnsCRName) ||
d.HasChange(pdnsCRDescription) ||
d.HasChange(pdnsCREnabled) ||
d.HasChange(pdnsCRHighAvailability) {
d.HasChange(pdnsCRHighAvailability) ||
d.HasChange(pdnsCRProfile) ||
d.HasChange(pdnsCRAllowDisruptiveUpdates) {

// Validation
if _, ok := d.GetOk(pdnsCustomResolverLocations); ok {
Expand Down Expand Up @@ -368,6 +435,14 @@
if !cr_enable {
opt.SetEnabled(false)
}
if des, ok := d.GetOk(pdnsCRProfile); ok {
crProfile := des.(string)
opt.SetProfile(crProfile)
}
if des, ok := d.GetOk(pdnsCRAllowDisruptiveUpdates); ok {
crDisruptiveUpdates := des.(bool)
opt.SetAllowDisruptiveUpdates(crDisruptiveUpdates)
}
result, resp, err := sess.UpdateCustomResolverWithContext(context, opt)
if err != nil || result == nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error updating the custom resolver %s:%s", err, resp))
Expand Down Expand Up @@ -491,7 +566,7 @@
optEnabled := sess.NewUpdateCustomResolverOptions(crn, customResolverID)
optEnabled.SetEnabled(false)
result, resp, errEnabled := sess.UpdateCustomResolverWithContext(context, optEnabled)
if err != nil || result == nil {
if errEnabled != nil || result == nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error updating the custom resolver to disable before deleting %s:%s", errEnabled, resp))
}

Expand Down Expand Up @@ -644,8 +719,7 @@
if err != nil {
return "", diag.FromErr(err)
}
opt := sess.NewAddCustomResolverLocationOptions(instanceID, customResolverID)
opt.SetSubnetCrn(subnet)
opt := sess.NewAddCustomResolverLocationOptions(instanceID, customResolverID, subnet)
opt.SetEnabled(false)
result, resp, err := sess.AddCustomResolverLocation(opt)
locationID := *result.ID
Expand Down
Loading
Loading