Skip to content

Commit

Permalink
Merge pull request #28600 from jclRatepay/b-aws_appflow_flow-sapo_dat…
Browse files Browse the repository at this point in the history
…a_source-schema-fix

Fixed naming bug for argument of aws_appflow_flow resource
  • Loading branch information
YakDriver authored Feb 10, 2023
2 parents 7147fc9 + 05d1b1e commit 800783e
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 38 deletions.
3 changes: 3 additions & 0 deletions .changelog/28600.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_appflow_flow: Fix misspelled `source_connector_properties.0.sapo_data.0.object`, which never worked, to be `object_path`
```
59 changes: 32 additions & 27 deletions internal/service/appflow/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import (
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
"github.com/hashicorp/terraform-provider-aws/names"
)

const (
AttrObjectPath = "object_path"
)

func ResourceFlow() *schema.Resource {
Expand All @@ -30,17 +35,17 @@ func ResourceFlow() *schema.Resource {
},

Schema: map[string]*schema.Schema{
"arn": {
names.AttrARN: {
Type: schema.TypeString,
Computed: true,
},
"name": {
names.AttrName: {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.All(validation.StringMatch(regexp.MustCompile(`[a-zA-Z0-9][\w!@#.-]+`), "must contain only alphanumeric, exclamation point (!), at sign (@), number sign (#), period (.), and hyphen (-) characters"), validation.StringLenBetween(1, 256)),
},
"description": {
names.AttrDescription: {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringMatch(regexp.MustCompile(`[\w!@#\-.?,\s]*`), "must contain only alphanumeric, underscore (_), exclamation point (!), at sign (@), number sign (#), hyphen (-), period (.), question mark (?), comma (,), and whitespace characters"),
Expand Down Expand Up @@ -471,7 +476,7 @@ func ResourceFlow() *schema.Resource {
ValidateFunc: validation.All(validation.StringMatch(regexp.MustCompile(`\S+`), "must not contain any whitespace characters"), validation.StringLenBetween(0, 128)),
},
},
"object_path": {
AttrObjectPath: {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.All(validation.StringMatch(regexp.MustCompile(`\S+`), "must not contain any whitespace characters"), validation.StringLenBetween(1, 512)),
Expand Down Expand Up @@ -891,7 +896,7 @@ func ResourceFlow() *schema.Resource {
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"object": {
AttrObjectPath: {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.All(validation.StringMatch(regexp.MustCompile(`\S+`), "must not contain any whitespace characters"), validation.StringLenBetween(1, 512)),
Expand Down Expand Up @@ -1196,8 +1201,8 @@ func ResourceFlow() *schema.Resource {
},
},
},
"tags": tftags.TagsSchema(),
"tags_all": tftags.TagsSchemaComputed(),
names.AttrTags: tftags.TagsSchema(),
names.AttrTagsAll: tftags.TagsSchemaComputed(),
},

CustomizeDiff: verify.SetTagsDiff,
Expand All @@ -1208,14 +1213,14 @@ func resourceFlowCreate(ctx context.Context, d *schema.ResourceData, meta interf
conn := meta.(*conns.AWSClient).AppFlowConn()

in := &appflow.CreateFlowInput{
FlowName: aws.String(d.Get("name").(string)),
FlowName: aws.String(d.Get(names.AttrName).(string)),
DestinationFlowConfigList: expandDestinationFlowConfigs(d.Get("destination_flow_config").(*schema.Set).List()),
SourceFlowConfig: expandSourceFlowConfig(d.Get("source_flow_config").([]interface{})[0].(map[string]interface{})),
Tasks: expandTasks(d.Get("task").(*schema.Set).List()),
TriggerConfig: expandTriggerConfig(d.Get("trigger_config").([]interface{})[0].(map[string]interface{})),
}

if v, ok := d.GetOk("description"); ok {
if v, ok := d.GetOk(names.AttrDescription); ok {
in.Description = aws.String(v.(string))
}

Expand All @@ -1224,19 +1229,19 @@ func resourceFlowCreate(ctx context.Context, d *schema.ResourceData, meta interf
}

defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig
tags := defaultTagsConfig.MergeTags(tftags.New(d.Get("tags").(map[string]interface{})))
tags := defaultTagsConfig.MergeTags(tftags.New(d.Get(names.AttrTags).(map[string]interface{})))
if len(tags) > 0 {
in.Tags = Tags(tags.IgnoreAWS())
}

out, err := conn.CreateFlowWithContext(ctx, in)

if err != nil {
return diag.Errorf("creating Appflow Flow (%s): %s", d.Get("name").(string), err)
return diag.Errorf("creating Appflow Flow (%s): %s", d.Get(names.AttrName).(string), err)
}

if out == nil || out.FlowArn == nil {
return diag.Errorf("creating Appflow Flow (%s): empty output", d.Get("name").(string))
return diag.Errorf("creating Appflow Flow (%s): empty output", d.Get(names.AttrName).(string))
}

d.SetId(aws.StringValue(out.FlowArn))
Expand Down Expand Up @@ -1269,9 +1274,9 @@ func resourceFlowRead(ctx context.Context, d *schema.ResourceData, meta interfac
return diag.Errorf("reading AppFlow Flow (%s): %s", d.Id(), err)
}

d.Set("name", out.FlowName)
d.Set("arn", out2.FlowArn)
d.Set("description", out2.Description)
d.Set(names.AttrName, out.FlowName)
d.Set(names.AttrARN, out2.FlowArn)
d.Set(names.AttrDescription, out2.Description)

if err := d.Set("destination_flow_config", flattenDestinationFlowConfigs(out2.DestinationFlowConfigList)); err != nil {
return diag.Errorf("error setting destination_flow_config: %s", err)
Expand Down Expand Up @@ -1310,11 +1315,11 @@ func resourceFlowRead(ctx context.Context, d *schema.ResourceData, meta interfac
tags = tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig)

//lintignore:AWSR002
if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil {
if err := d.Set(names.AttrTags, tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil {
return diag.Errorf("setting tags: %s", err)
}

if err := d.Set("tags_all", tags.Map()); err != nil {
if err := d.Set(names.AttrTagsAll, tags.Map()); err != nil {
return diag.Errorf("setting tags_all: %s", err)
}

Expand All @@ -1325,15 +1330,15 @@ func resourceFlowUpdate(ctx context.Context, d *schema.ResourceData, meta interf
conn := meta.(*conns.AWSClient).AppFlowConn()

in := &appflow.UpdateFlowInput{
FlowName: aws.String(d.Get("name").(string)),
FlowName: aws.String(d.Get(names.AttrName).(string)),
DestinationFlowConfigList: expandDestinationFlowConfigs(d.Get("destination_flow_config").(*schema.Set).List()),
SourceFlowConfig: expandSourceFlowConfig(d.Get("source_flow_config").([]interface{})[0].(map[string]interface{})),
Tasks: expandTasks(d.Get("task").(*schema.Set).List()),
TriggerConfig: expandTriggerConfig(d.Get("trigger_config").([]interface{})[0].(map[string]interface{})),
}

if d.HasChange("description") {
in.Description = aws.String(d.Get("description").(string))
if d.HasChange(names.AttrDescription) {
in.Description = aws.String(d.Get(names.AttrDescription).(string))
}

log.Printf("[DEBUG] Updating AppFlow Flow (%s): %#v", d.Id(), in)
Expand All @@ -1343,10 +1348,10 @@ func resourceFlowUpdate(ctx context.Context, d *schema.ResourceData, meta interf
return diag.Errorf("updating AppFlow Flow (%s): %s", d.Id(), err)
}

arn := d.Get("arn").(string)
arn := d.Get(names.AttrARN).(string)

if d.HasChange("tags_all") {
o, n := d.GetChange("tags_all")
if d.HasChange(names.AttrTagsAll) {
o, n := d.GetChange(names.AttrTagsAll)
if err := UpdateTags(ctx, conn, arn, o, n); err != nil {
return diag.Errorf("error updating tags: %s", err)
}
Expand Down Expand Up @@ -1764,7 +1769,7 @@ func expandSAPODataDestinationProperties(tfMap map[string]interface{}) *appflow.
a.IdFieldNames = flex.ExpandStringList(v)
}

if v, ok := tfMap["object_path"].(string); ok && v != "" {
if v, ok := tfMap[AttrObjectPath].(string); ok && v != "" {
a.ObjectPath = aws.String(v)
}

Expand Down Expand Up @@ -2178,7 +2183,7 @@ func expandSAPODataSourceProperties(tfMap map[string]interface{}) *appflow.SAPOD

a := &appflow.SAPODataSourceProperties{}

if v, ok := tfMap["object_path"].(string); ok && v != "" {
if v, ok := tfMap[AttrObjectPath].(string); ok && v != "" {
a.ObjectPath = aws.String(v)
}

Expand Down Expand Up @@ -2869,7 +2874,7 @@ func flattenSAPODataDestinationProperties(SAPODataDestinationProperties *appflow
}

if v := SAPODataDestinationProperties.ObjectPath; v != nil {
m["object_path"] = aws.StringValue(v)
m[AttrObjectPath] = aws.StringValue(v)
}

if v := SAPODataDestinationProperties.SuccessResponseHandlingConfig; v != nil {
Expand Down Expand Up @@ -3283,7 +3288,7 @@ func flattenSAPODataSourceProperties(sapoDataSourceProperties *appflow.SAPODataS
m := map[string]interface{}{}

if v := sapoDataSourceProperties.ObjectPath; v != nil {
m["object_path"] = aws.StringValue(v)
m[AttrObjectPath] = aws.StringValue(v)
}

return m
Expand Down
7 changes: 4 additions & 3 deletions internal/service/appflow/flow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/hashicorp/terraform-provider-aws/internal/conns"
tfappflow "github.com/hashicorp/terraform-provider-aws/internal/service/appflow"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/names"
)

func TestAccAppFlowFlow_basic(t *testing.T) {
Expand All @@ -36,8 +37,8 @@ func TestAccAppFlowFlow_basic(t *testing.T) {
Config: testAccFlowConfig_basic(rSourceName, rDestinationName, rFlowName, scheduleStartTime),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckFlowExists(ctx, resourceName, &flowOutput),
acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "appflow", regexp.MustCompile(`flow/.+`)),
resource.TestCheckResourceAttr(resourceName, "name", rFlowName),
acctest.MatchResourceAttrRegionalARN(resourceName, names.AttrARN, "appflow", regexp.MustCompile(`flow/.+`)),
resource.TestCheckResourceAttr(resourceName, names.AttrName, rFlowName),
resource.TestCheckResourceAttrSet(resourceName, "destination_flow_config.#"),
resource.TestCheckResourceAttrSet(resourceName, "destination_flow_config.0.connector_type"),
resource.TestCheckResourceAttrSet(resourceName, "destination_flow_config.0.destination_connector_properties.#"),
Expand Down Expand Up @@ -93,7 +94,7 @@ func TestAccAppFlowFlow_update(t *testing.T) {
Config: testAccFlowConfig_update(rSourceName, rDestinationName, rFlowName, description),
Check: resource.ComposeTestCheckFunc(
testAccCheckFlowExists(ctx, resourceName, &flowOutput),
resource.TestCheckResourceAttr(resourceName, "description", description),
resource.TestCheckResourceAttr(resourceName, names.AttrDescription, description),
resource.TestCheckResourceAttr(resourceName, "trigger_config.#", "1"),
resource.TestCheckResourceAttr(resourceName, "trigger_config.0.trigger_type", "Scheduled"),
resource.TestCheckResourceAttr(resourceName, "trigger_config.0.trigger_properties.#", "1"),
Expand Down
15 changes: 8 additions & 7 deletions names/attr_consts.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package names

const (
AttrARN = "arn"
AttrEnabled = "enabled"
AttrKMSKeyARN = "kms_key_arn"
AttrName = "name"
AttrTags = "tags"
AttrTagsAll = "tags_all"
AttrType = "type"
AttrARN = "arn"
AttrDescription = "description"
AttrEnabled = "enabled"
AttrKMSKeyARN = "kms_key_arn"
AttrName = "name"
AttrTags = "tags"
AttrTagsAll = "tags_all"
AttrType = "type"
)
2 changes: 1 addition & 1 deletion website/docs/r/appflow_flow.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ Amplitude, Datadog, Dynatrace, Google Analytics, Infor Nexus, Marketo, ServiceNo

##### SAPOData Source Properties

* `object_path` - (Optional) Object path specified in the SAPOData flow source.
* `object_path` - (Required) Object path specified in the SAPOData flow source.

##### Veeva Source Properties

Expand Down

0 comments on commit 800783e

Please sign in to comment.