|
| 1 | +package network |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "time" |
| 6 | + |
| 7 | + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" |
| 8 | + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" |
| 9 | + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network/parse" |
| 10 | + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network/validate" |
| 11 | + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" |
| 12 | + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" |
| 13 | +) |
| 14 | + |
| 15 | +func dataSourceArmFirewallPolicyRuleCollectionGroup() *schema.Resource { |
| 16 | + return &schema.Resource{ |
| 17 | + Read: dataSourceArmFirewallPolicyRuleCollectionGroupRead, |
| 18 | + |
| 19 | + Timeouts: &schema.ResourceTimeout{ |
| 20 | + Read: schema.DefaultTimeout(5 * time.Minute), |
| 21 | + }, |
| 22 | + |
| 23 | + Schema: map[string]*schema.Schema{ |
| 24 | + "name": { |
| 25 | + Type: schema.TypeString, |
| 26 | + Required: true, |
| 27 | + ValidateFunc: validate.FirewallPolicyRuleCollectionGroupName(), |
| 28 | + }, |
| 29 | + |
| 30 | + "firewall_policy_id": { |
| 31 | + Type: schema.TypeString, |
| 32 | + Required: true, |
| 33 | + ForceNew: true, |
| 34 | + ValidateFunc: validate.FirewallPolicyID, |
| 35 | + }, |
| 36 | + }, |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +func dataSourceArmFirewallPolicyRuleCollectionGroupRead(d *schema.ResourceData, meta interface{}) error { |
| 41 | + client := meta.(*clients.Client).Network.FirewallPolicyRuleGroupClient |
| 42 | + ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) |
| 43 | + defer cancel() |
| 44 | + |
| 45 | + name := d.Get("name").(string) |
| 46 | + policyId, err := parse.FirewallPolicyID(d.Get("firewall_policy_id").(string)) |
| 47 | + if err != nil { |
| 48 | + return err |
| 49 | + } |
| 50 | + |
| 51 | + resp, err := client.Get(ctx, policyId.ResourceGroup, policyId.Name, name) |
| 52 | + if err != nil { |
| 53 | + if utils.ResponseWasNotFound(resp.Response) { |
| 54 | + return fmt.Errorf("Firewall Policy Rule Collection Group %q (Resource Group %q / Policy %q) was not found", name, policyId.ResourceGroup, policyId.Name) |
| 55 | + } |
| 56 | + |
| 57 | + return fmt.Errorf("retrieving Firewall Policy Rule Collection Group %q (Resource Group %q / Policy %q): %+v", name, policyId.ResourceGroup, policyId.Name, err) |
| 58 | + } |
| 59 | + |
| 60 | + if resp.ID == nil || *resp.ID == "" { |
| 61 | + return fmt.Errorf("empty or nil ID returned for Firewall Policy Rule Collection Group %q (Resource Group %q / Policy %q) ID", name, policyId.ResourceGroup, policyId.Name) |
| 62 | + } |
| 63 | + |
| 64 | + d.SetId(*resp.ID) |
| 65 | + |
| 66 | + return nil |
| 67 | +} |
0 commit comments