From f0c844105208f252ea9faea073b5e8bb2be5b5e9 Mon Sep 17 00:00:00 2001 From: Prateek Sharma Date: Fri, 16 Jun 2023 11:42:13 -0700 Subject: [PATCH 1/7] Adding support for ChimeSDKVoice Sip Rule --- .../chimesdkvoice/service_package_gen.go | 5 + .../sip_media_application_test.go | 4 +- internal/service/chimesdkvoice/sip_rule.go | 202 ++++++++++++++ .../service/chimesdkvoice/sip_rule_test.go | 263 ++++++++++++++++++ .../r/chimesdkvoice_sip_rule.html.markdown | 62 +++++ 5 files changed, 534 insertions(+), 2 deletions(-) create mode 100644 internal/service/chimesdkvoice/sip_rule.go create mode 100644 internal/service/chimesdkvoice/sip_rule_test.go create mode 100644 website/docs/r/chimesdkvoice_sip_rule.html.markdown diff --git a/internal/service/chimesdkvoice/service_package_gen.go b/internal/service/chimesdkvoice/service_package_gen.go index d25835b58e6..a364a722a13 100644 --- a/internal/service/chimesdkvoice/service_package_gen.go +++ b/internal/service/chimesdkvoice/service_package_gen.go @@ -37,6 +37,11 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka IdentifierAttribute: "arn", }, }, + { + Factory: ResourceSipRule, + TypeName: "aws_chimesdkvoice_sip_rule", + Name: "Sip Rule", + }, { Factory: ResourceVoiceProfileDomain, TypeName: "aws_chimesdkvoice_voice_profile_domain", diff --git a/internal/service/chimesdkvoice/sip_media_application_test.go b/internal/service/chimesdkvoice/sip_media_application_test.go index f4ca462b70b..424db5b785b 100644 --- a/internal/service/chimesdkvoice/sip_media_application_test.go +++ b/internal/service/chimesdkvoice/sip_media_application_test.go @@ -189,7 +189,7 @@ func testAccCheckSipMediaApplicationExists(ctx context.Context, name string, vc } if rs.Primary.ID == "" { - return fmt.Errorf("no Chime voice connector ID is set") + return fmt.Errorf("no ChimeSdkVoice Sip Media Application ID is set") } conn := acctest.Provider.Meta().(*conns.AWSClient).ChimeSDKVoiceConn(ctx) @@ -210,7 +210,7 @@ func testAccCheckSipMediaApplicationExists(ctx context.Context, name string, vc func testAccCheckSipMediaApplicationDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { for _, rs := range s.RootModule().Resources { - if rs.Type != "aws_chimesdkvoice_chime_sip_media_application" { + if rs.Type != "aws_chimesdkvoice_sip_media_application" { continue } conn := acctest.Provider.Meta().(*conns.AWSClient).ChimeSDKVoiceConn(ctx) diff --git a/internal/service/chimesdkvoice/sip_rule.go b/internal/service/chimesdkvoice/sip_rule.go new file mode 100644 index 00000000000..8801305e437 --- /dev/null +++ b/internal/service/chimesdkvoice/sip_rule.go @@ -0,0 +1,202 @@ +package chimesdkvoice + +import ( + "context" + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/chimesdkvoice" + "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" + "log" +) + +// @SDKResource("aws_chimesdkvoice_sip_rule", name="Sip Rule") +func ResourceSipRule() *schema.Resource { + return &schema.Resource{ + CreateWithoutTimeout: resourceSipRuleCreate, + ReadWithoutTimeout: resourceSipRuleRead, + UpdateWithoutTimeout: resourceSipRuleUpdate, + DeleteWithoutTimeout: resourceSipRuleDelete, + + Importer: &schema.ResourceImporter{ + StateContext: schema.ImportStatePassthroughContext, + }, + + Schema: map[string]*schema.Schema{ + "disabled": { + Type: schema.TypeBool, + Optional: true, + }, + "name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringLenBetween(1, 256), + }, + "target_applications": { + Type: schema.TypeSet, + Required: true, + MinItems: 1, + MaxItems: 25, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "aws_region": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "priority": { + Type: schema.TypeInt, + Required: true, + ValidateFunc: validation.IntAtLeast(1), + }, + "sip_media_application_id": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringLenBetween(1, 256), + }, + }, + }, + }, + "trigger_type": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice(chimesdkvoice.SipRuleTriggerType_Values(), false), + }, + "trigger_value": { + Type: schema.TypeString, + Required: true, + }, + }, + } +} + +func resourceSipRuleCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics + conn := meta.(*conns.AWSClient).ChimeSDKVoiceConn(ctx) + + input := &chimesdkvoice.CreateSipRuleInput{ + Name: aws.String(d.Get("name").(string)), + TriggerType: aws.String(d.Get("trigger_type").(string)), + TriggerValue: aws.String(d.Get("trigger_value").(string)), + TargetApplications: expandSipRuleTargetApplications(d.Get("target_applications").(*schema.Set).List()), + } + + if v, ok := d.GetOk("disabled"); ok { + input.Disabled = aws.Bool(v.(bool)) + } + + resp, err := conn.CreateSipRuleWithContext(ctx, input) + + if err != nil || resp.SipRule == nil { + return sdkdiag.AppendErrorf(diags, "creating ChimeSKVoice Sip Rule: %s", err) + } + + d.SetId(aws.StringValue(resp.SipRule.SipRuleId)) + + return append(diags, resourceSipRuleRead(ctx, d, meta)...) +} + +func resourceSipRuleRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics + conn := meta.(*conns.AWSClient).ChimeSDKVoiceConn(ctx) + + getInput := &chimesdkvoice.GetSipRuleInput{ + SipRuleId: aws.String(d.Id()), + } + + resp, err := conn.GetSipRuleWithContext(ctx, getInput) + if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, chimesdkvoice.ErrCodeNotFoundException) { + log.Printf("[WARN] ChimeSDKVoice Sip Rule %s not found", d.Id()) + d.SetId("") + return diags + } + + if err != nil || resp.SipRule == nil { + return sdkdiag.AppendErrorf(diags, "getting Sip Rule (%s): %s", d.Id(), err) + } + + d.Set("name", resp.SipRule.Name) + d.Set("disabled", resp.SipRule.Disabled) + d.Set("trigger_type", resp.SipRule.TriggerType) + d.Set("trigger_value", resp.SipRule.TriggerValue) + d.Set("target_applications", flattenSipRuleTargetApplications(resp.SipRule.TargetApplications)) + return diags +} + +func resourceSipRuleUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics + conn := meta.(*conns.AWSClient).ChimeSDKVoiceConn(ctx) + + updateInput := &chimesdkvoice.UpdateSipRuleInput{ + SipRuleId: aws.String(d.Id()), + Name: aws.String(d.Get("name").(string)), + } + + if d.HasChanges("target_applications") { + updateInput.TargetApplications = expandSipRuleTargetApplications(d.Get("target_applications").(*schema.Set).List()) + } + + if d.HasChanges("disabled") { + updateInput.Disabled = aws.Bool(d.Get("disabled").(bool)) + } + + if _, err := conn.UpdateSipRuleWithContext(ctx, updateInput); err != nil { + return sdkdiag.AppendErrorf(diags, "updating Sip Rule (%s): %s", d.Id(), err) + } + + return append(diags, resourceSipRuleRead(ctx, d, meta)...) +} + +func resourceSipRuleDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics + conn := meta.(*conns.AWSClient).ChimeSDKVoiceConn(ctx) + + input := &chimesdkvoice.DeleteSipRuleInput{ + SipRuleId: aws.String(d.Id()), + } + + if _, err := conn.DeleteSipRuleWithContext(ctx, input); err != nil { + if tfawserr.ErrCodeEquals(err, chimesdkvoice.ErrCodeNotFoundException) { + log.Printf("[WARN] ChimeSDKVoice Sip Rule %s not found", d.Id()) + return diags + } + return sdkdiag.AppendErrorf(diags, "deleting Sip Rule (%s)", d.Id()) + } + + return diags +} + +func expandSipRuleTargetApplications(data []interface{}) []*chimesdkvoice.SipRuleTargetApplication { + var targetApplications []*chimesdkvoice.SipRuleTargetApplication + + for _, rItem := range data { + item := rItem.(map[string]interface{}) + application := &chimesdkvoice.SipRuleTargetApplication{ + SipMediaApplicationId: aws.String(item["sip_media_application_id"].(string)), + Priority: aws.Int64(int64(item["priority"].(int))), + AwsRegion: aws.String(item["aws_region"].(string)), + } + + targetApplications = append(targetApplications, application) + } + + return targetApplications +} + +func flattenSipRuleTargetApplications(apiObject []*chimesdkvoice.SipRuleTargetApplication) []interface{} { + var rawSipRuleTargetApplications []interface{} + + for _, e := range apiObject { + rawTargetApplication := map[string]interface{}{ + "sip_media_application_id": aws.StringValue(e.SipMediaApplicationId), + "priority": aws.Int64Value(e.Priority), + "aws_region": aws.StringValue(e.AwsRegion), + } + + rawSipRuleTargetApplications = append(rawSipRuleTargetApplications, rawTargetApplication) + } + return rawSipRuleTargetApplications +} diff --git a/internal/service/chimesdkvoice/sip_rule_test.go b/internal/service/chimesdkvoice/sip_rule_test.go new file mode 100644 index 00000000000..06376ecef3c --- /dev/null +++ b/internal/service/chimesdkvoice/sip_rule_test.go @@ -0,0 +1,263 @@ +package chimesdkvoice_test + +import ( + "context" + "fmt" + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/endpoints" + "github.com/aws/aws-sdk-go/service/chime" + "github.com/aws/aws-sdk-go/service/chimesdkvoice" + sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" + "github.com/hashicorp/terraform-provider-aws/internal/acctest" + "github.com/hashicorp/terraform-provider-aws/internal/conns" + tfchimesdkvoice "github.com/hashicorp/terraform-provider-aws/internal/service/chimesdkvoice" + "testing" +) + +func TestAccChimeSDKVoiceSipRule_basic(t *testing.T) { + ctx := acctest.Context(t) + var chimeSipRule *chimesdkvoice.SipRule + + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_chimesdkvoice_sip_rule.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) + }, + ErrorCheck: acctest.ErrorCheck(t, chimesdkvoice.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckSipRuleDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccSipRuleConfig_basic(rName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckSipRuleExists(ctx, resourceName, chimeSipRule), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "trigger_type", "RequestUriHostname"), + resource.TestCheckResourceAttrSet(resourceName, "trigger_value"), + resource.TestCheckResourceAttr(resourceName, "target_applications.#", "1"), + resource.TestCheckResourceAttr(resourceName, "target_applications.0.priority", "1"), + resource.TestCheckResourceAttrSet(resourceName, "target_applications.0.sip_media_application_id"), + resource.TestCheckResourceAttrSet(resourceName, "target_applications.0.aws_region"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccChimeSDKVoiceSipRule_disappears(t *testing.T) { + ctx := acctest.Context(t) + var chimeSipRule *chimesdkvoice.SipRule + + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_chimesdkvoice_sip_rule.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) + }, + ErrorCheck: acctest.ErrorCheck(t, chime.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckSipRuleDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccSipRuleConfig_basic(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckSipRuleExists(ctx, resourceName, chimeSipRule), + acctest.CheckResourceDisappears(ctx, acctest.Provider, tfchimesdkvoice.ResourceSipRule(), resourceName), + ), + ExpectNonEmptyPlan: true, + }, + }, + }) +} + +func TestAccChimeSDKVoiceSipRule_update(t *testing.T) { + ctx := acctest.Context(t) + var chimeSipRule *chimesdkvoice.SipRule + + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + rNameUpdated := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_chimesdkvoice_sip_rule.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) + }, + ErrorCheck: acctest.ErrorCheck(t, chimesdkvoice.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckSipRuleDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccSipRuleConfig_update(rName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckSipRuleExists(ctx, resourceName, chimeSipRule), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "trigger_type", "RequestUriHostname"), + resource.TestCheckResourceAttrSet(resourceName, "trigger_value"), + resource.TestCheckResourceAttr(resourceName, "target_applications.#", "1"), + resource.TestCheckResourceAttr(resourceName, "target_applications.0.priority", "1"), + resource.TestCheckResourceAttrSet(resourceName, "target_applications.0.sip_media_application_id"), + resource.TestCheckResourceAttrSet(resourceName, "target_applications.0.aws_region"), + ), + }, + { + Config: testAccSipRuleConfig_update(rNameUpdated), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckSipRuleExists(ctx, resourceName, chimeSipRule), + resource.TestCheckResourceAttr(resourceName, "name", rNameUpdated), + resource.TestCheckResourceAttr(resourceName, "disabled", "true"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccSipRuleConfigBase(rName string) string { + return fmt.Sprintf(` +data "aws_region" "current" {} + +resource "aws_iam_role" "test" { + name = %[1]q + + assume_role_policy = < Date: Fri, 16 Jun 2023 12:03:27 -0700 Subject: [PATCH 2/7] Lint fixes for test files and website --- .../service/chimesdkvoice/sip_rule_test.go | 20 +++++++++---------- .../r/chimesdkvoice_sip_rule.html.markdown | 12 +++++------ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/internal/service/chimesdkvoice/sip_rule_test.go b/internal/service/chimesdkvoice/sip_rule_test.go index 06376ecef3c..1acdf0e9068 100644 --- a/internal/service/chimesdkvoice/sip_rule_test.go +++ b/internal/service/chimesdkvoice/sip_rule_test.go @@ -183,14 +183,14 @@ func testAccSipRuleConfig_basic(rName string) string { testAccSipRuleConfigBase(rName), fmt.Sprintf(` resource "aws_chimesdkvoice_sip_rule" "test" { - name = %[1]q - disabled = "false" - trigger_type = "RequestUriHostname" + name = %[1]q + disabled = "false" + trigger_type = "RequestUriHostname" trigger_value = aws_chime_voice_connector.test.outbound_host_name target_applications { - priority = 1 + priority = 1 sip_media_application_id = aws_chimesdkvoice_sip_media_application.test.id - aws_region = data.aws_region.current.name + aws_region = data.aws_region.current.name } } `, rName)) @@ -201,14 +201,14 @@ func testAccSipRuleConfig_update(rName string) string { testAccSipRuleConfigBase(rName), fmt.Sprintf(` resource "aws_chimesdkvoice_sip_rule" "test" { - name = %[1]q - disabled = "true" - trigger_type = "RequestUriHostname" + name = %[1]q + disabled = "true" + trigger_type = "RequestUriHostname" trigger_value = aws_chime_voice_connector.test.outbound_host_name target_applications { - priority = 1 + priority = 1 sip_media_application_id = aws_chimesdkvoice_sip_media_application.test.id - aws_region = data.aws_region.current.name + aws_region = data.aws_region.current.name } } `, rName)) diff --git a/website/docs/r/chimesdkvoice_sip_rule.html.markdown b/website/docs/r/chimesdkvoice_sip_rule.html.markdown index b4988f62fb5..bece222ee2b 100644 --- a/website/docs/r/chimesdkvoice_sip_rule.html.markdown +++ b/website/docs/r/chimesdkvoice_sip_rule.html.markdown @@ -8,19 +8,20 @@ A SIP rule associates your SIP media application with a phone number or a Reques # Resource: aws_chimesdkvoice_sip_rule A SIP rule associates your SIP media application with a phone number or a Request URI hostname. You can associate a SIP rule with more than one SIP media application. Each application then runs only that rule. + ## Example Usage ### Basic Usage ```terraform resource "aws_chimesdkvoice_sip_rule" "example" { - name = "example-sip-rule" - trigger_type = "RequestUriHostname" + name = "example-sip-rule" + trigger_type = "RequestUriHostname" trigger_value = aws_chime_voice_connector.example-voice-connector.outbound_host_name target_applications { - priority = 1 - sip_media_application_id = aws_chimesdkvoice_sip_media_application.example-sma.id - aws_region = "us-east-1" + priority = 1 + sip_media_application_id = aws_chimesdkvoice_sip_media_application.example-sma.id + aws_region = "us-east-1" } } ``` @@ -46,7 +47,6 @@ List of SIP media applications with priority and AWS Region. Only one SIP applic * `Priority` - (Required) Priority of the SIP media application in the target list. * `SipMediaApplicationId` - (Required) The SIP media application ID. - ## Attributes Reference In addition to all arguments above, the following attributes are exported: From 5603d0095066033aefd05e1dc98fc0e635a0fb11 Mon Sep 17 00:00:00 2001 From: Prateek Sharma Date: Fri, 16 Jun 2023 12:39:02 -0700 Subject: [PATCH 3/7] import, docs fix --- internal/service/chimesdkvoice/sip_rule.go | 3 ++- internal/service/chimesdkvoice/sip_rule_test.go | 3 ++- website/docs/r/chimesdkvoice_sip_rule.html.markdown | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/service/chimesdkvoice/sip_rule.go b/internal/service/chimesdkvoice/sip_rule.go index 8801305e437..3091ac6be8b 100644 --- a/internal/service/chimesdkvoice/sip_rule.go +++ b/internal/service/chimesdkvoice/sip_rule.go @@ -2,6 +2,8 @@ package chimesdkvoice import ( "context" + "log" + "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/chimesdkvoice" "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" @@ -10,7 +12,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" - "log" ) // @SDKResource("aws_chimesdkvoice_sip_rule", name="Sip Rule") diff --git a/internal/service/chimesdkvoice/sip_rule_test.go b/internal/service/chimesdkvoice/sip_rule_test.go index 1acdf0e9068..77d654c1c7d 100644 --- a/internal/service/chimesdkvoice/sip_rule_test.go +++ b/internal/service/chimesdkvoice/sip_rule_test.go @@ -3,6 +3,8 @@ package chimesdkvoice_test import ( "context" "fmt" + "testing" + "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/endpoints" "github.com/aws/aws-sdk-go/service/chime" @@ -13,7 +15,6 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/acctest" "github.com/hashicorp/terraform-provider-aws/internal/conns" tfchimesdkvoice "github.com/hashicorp/terraform-provider-aws/internal/service/chimesdkvoice" - "testing" ) func TestAccChimeSDKVoiceSipRule_basic(t *testing.T) { diff --git a/website/docs/r/chimesdkvoice_sip_rule.html.markdown b/website/docs/r/chimesdkvoice_sip_rule.html.markdown index bece222ee2b..d57cc3ff42f 100644 --- a/website/docs/r/chimesdkvoice_sip_rule.html.markdown +++ b/website/docs/r/chimesdkvoice_sip_rule.html.markdown @@ -3,7 +3,7 @@ subcategory: "Chime SDK Voice" layout: "aws" page_title: "AWS: aws_chimesdkvoice_sip_rule" description: |- -A SIP rule associates your SIP media application with a phone number or a Request URI hostname. You can associate a SIP rule with more than one SIP media application. Each application then runs only that rule. + A SIP rule associates your SIP media application with a phone number or a Request URI hostname. You can associate a SIP rule with more than one SIP media application. Each application then runs only that rule. --- # Resource: aws_chimesdkvoice_sip_rule From 382556d848b4c72a8ac46cc9e978d8a56e2bf5b2 Mon Sep 17 00:00:00 2001 From: Prateek Sharma Date: Fri, 16 Jun 2023 12:47:01 -0700 Subject: [PATCH 4/7] Adding change log --- .changelog/32070.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/32070.txt diff --git a/.changelog/32070.txt b/.changelog/32070.txt new file mode 100644 index 00000000000..6d8891e0be5 --- /dev/null +++ b/.changelog/32070.txt @@ -0,0 +1,3 @@ +```release-note:new-resource +aws_chime_sdk_voice_sip_rule +``` From b1c58112590eb412e5e57bdf83dcaafe559b4f4f Mon Sep 17 00:00:00 2001 From: Prateek Sharma Date: Fri, 16 Jun 2023 12:56:55 -0700 Subject: [PATCH 5/7] Fix changelog --- .changelog/32070.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/32070.txt b/.changelog/32070.txt index 6d8891e0be5..b481c3c829f 100644 --- a/.changelog/32070.txt +++ b/.changelog/32070.txt @@ -1,3 +1,3 @@ ```release-note:new-resource -aws_chime_sdk_voice_sip_rule +aws_chimesdkvoice_sip_rule ``` From 99f6db9e436ff9a5300aaf521d16809d753f4a2e Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Tue, 20 Jun 2023 15:44:41 -0400 Subject: [PATCH 6/7] r/aws_chimesdkvoice_sip_rule(test): re-order test check funcs --- .../service/chimesdkvoice/sip_rule_test.go | 96 +++++++++---------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/internal/service/chimesdkvoice/sip_rule_test.go b/internal/service/chimesdkvoice/sip_rule_test.go index 77d654c1c7d..2d798744096 100644 --- a/internal/service/chimesdkvoice/sip_rule_test.go +++ b/internal/service/chimesdkvoice/sip_rule_test.go @@ -130,6 +130,54 @@ func TestAccChimeSDKVoiceSipRule_update(t *testing.T) { }) } +func testAccCheckSipRuleExists(ctx context.Context, name string, sr *chimesdkvoice.SipRule) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("not found: %s", name) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("no ChimeSdkVoice Sip Rule ID is set") + } + + conn := acctest.Provider.Meta().(*conns.AWSClient).ChimeSDKVoiceConn(ctx) + input := &chimesdkvoice.GetSipRuleInput{ + SipRuleId: aws.String(rs.Primary.ID), + } + resp, err := conn.GetSipRuleWithContext(ctx, input) + if err != nil { + return err + } + + sr = resp.SipRule + + return nil + } +} + +func testAccCheckSipRuleDestroy(ctx context.Context) resource.TestCheckFunc { + return func(s *terraform.State) error { + for _, rs := range s.RootModule().Resources { + if rs.Type != "aws_chimesdkvoice_sip_rule" { + continue + } + conn := acctest.Provider.Meta().(*conns.AWSClient).ChimeSDKVoiceConn(ctx) + input := &chimesdkvoice.GetSipRuleInput{ + SipRuleId: aws.String(rs.Primary.ID), + } + resp, err := conn.GetSipRuleWithContext(ctx, input) + if err == nil { + if resp.SipRule != nil && aws.StringValue(resp.SipRule.Name) != "" { + return fmt.Errorf("error ChimeSdkVoice Sip Rule still exists") + } + } + return nil + } + return nil + } +} + func testAccSipRuleConfigBase(rName string) string { return fmt.Sprintf(` data "aws_region" "current" {} @@ -214,51 +262,3 @@ resource "aws_chimesdkvoice_sip_rule" "test" { } `, rName)) } - -func testAccCheckSipRuleExists(ctx context.Context, name string, sr *chimesdkvoice.SipRule) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[name] - if !ok { - return fmt.Errorf("not found: %s", name) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("no ChimeSdkVoice Sip Rule ID is set") - } - - conn := acctest.Provider.Meta().(*conns.AWSClient).ChimeSDKVoiceConn(ctx) - input := &chimesdkvoice.GetSipRuleInput{ - SipRuleId: aws.String(rs.Primary.ID), - } - resp, err := conn.GetSipRuleWithContext(ctx, input) - if err != nil { - return err - } - - sr = resp.SipRule - - return nil - } -} - -func testAccCheckSipRuleDestroy(ctx context.Context) resource.TestCheckFunc { - return func(s *terraform.State) error { - for _, rs := range s.RootModule().Resources { - if rs.Type != "aws_chimesdkvoice_sip_rule" { - continue - } - conn := acctest.Provider.Meta().(*conns.AWSClient).ChimeSDKVoiceConn(ctx) - input := &chimesdkvoice.GetSipRuleInput{ - SipRuleId: aws.String(rs.Primary.ID), - } - resp, err := conn.GetSipRuleWithContext(ctx, input) - if err == nil { - if resp.SipRule != nil && aws.StringValue(resp.SipRule.Name) != "" { - return fmt.Errorf("error ChimeSdkVoice Sip Rule still exists") - } - } - return nil - } - return nil - } -} From 625867e2102ed87f2c3d54a734044d1b215007c6 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Tue, 20 Jun 2023 16:01:25 -0400 Subject: [PATCH 7/7] r/aws_chimesdkvoice_sip_rule(docs): tidy argument casing --- website/docs/r/chimesdkvoice_sip_rule.html.markdown | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/website/docs/r/chimesdkvoice_sip_rule.html.markdown b/website/docs/r/chimesdkvoice_sip_rule.html.markdown index d57cc3ff42f..c9c8480f46d 100644 --- a/website/docs/r/chimesdkvoice_sip_rule.html.markdown +++ b/website/docs/r/chimesdkvoice_sip_rule.html.markdown @@ -31,9 +31,9 @@ resource "aws_chimesdkvoice_sip_rule" "example" { The following arguments are required: * `name` - (Required) The name of the SIP rule. -* `target_applications` - (Required) List of SIP media applications with priority and AWS Region. Only one SIP application per AWS Region can be used. -* `trigger_type` - (Required) The type of trigger assigned to the SIP rule in TriggerValue, currently RequestUriHostname or ToPhoneNumber. -* `trigger_value` - (Required) If TriggerType is RequestUriHostname, the value can be the outbound host name of an Amazon Chime Voice Connector. If TriggerType is ToPhoneNumber, the value can be a customer-owned phone number in the E164 format. The SipMediaApplication specified in the SipRule is triggered if the request URI in an incoming SIP request matches the RequestUriHostname, or if the To header in the incoming SIP request matches the ToPhoneNumber value. +* `target_applications` - (Required) List of SIP media applications with priority and AWS Region. Only one SIP application per AWS Region can be used. See [`target_applications`](#target_applications). +* `trigger_type` - (Required) The type of trigger assigned to the SIP rule in `trigger_value`. Valid values are `RequestUriHostname` or `ToPhoneNumber`. +* `trigger_value` - (Required) If `trigger_type` is `RequestUriHostname`, the value can be the outbound host name of an Amazon Chime Voice Connector. If `trigger_type` is `ToPhoneNumber`, the value can be a customer-owned phone number in the E164 format. The Sip Media Application specified in the Sip Rule is triggered if the request URI in an incoming SIP request matches the `RequestUriHostname`, or if the "To" header in the incoming SIP request matches the `ToPhoneNumber` value. The following arguments are optional: @@ -43,9 +43,9 @@ The following arguments are optional: List of SIP media applications with priority and AWS Region. Only one SIP application per AWS Region can be used. -* `AwsRegion` - (Required) The AWS Region of the target application. -* `Priority` - (Required) Priority of the SIP media application in the target list. -* `SipMediaApplicationId` - (Required) The SIP media application ID. +* `aws_region` - (Required) The AWS Region of the target application. +* `priority` - (Required) Priority of the SIP media application in the target list. +* `sip_media_application_id` - (Required) The SIP media application ID. ## Attributes Reference