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

Fix schema set errors #14167

Merged
merged 5 commits into from
Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions aws/data_source_aws_lb.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ func dataSourceAwsLb() *schema.Resource {
Computed: true,
},

"enable_http2": {
Type: schema.TypeBool,
Computed: true,
},

"idle_timeout": {
Type: schema.TypeInt,
Computed: true,
Expand Down
34 changes: 31 additions & 3 deletions aws/elasticsearch_domain_structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package aws
import (
"github.com/aws/aws-sdk-go/aws"
elasticsearch "github.com/aws/aws-sdk-go/service/elasticsearchservice"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

func expandAdvancedSecurityOptions(m []interface{}) *elasticsearch.AdvancedSecurityOptionsInput {
Expand Down Expand Up @@ -48,10 +49,37 @@ func flattenAdvancedSecurityOptions(advancedSecurityOptions *elasticsearch.Advan
return []map[string]interface{}{}
}

m := map[string]interface{}{
"enabled": aws.BoolValue(advancedSecurityOptions.Enabled),
"internal_user_database_enabled": aws.BoolValue(advancedSecurityOptions.InternalUserDatabaseEnabled),
m := map[string]interface{}{}
m["enabled"] = aws.BoolValue(advancedSecurityOptions.Enabled)
if aws.BoolValue(advancedSecurityOptions.Enabled) {
m["internal_user_database_enabled"] = aws.BoolValue(advancedSecurityOptions.InternalUserDatabaseEnabled)
}

return []map[string]interface{}{m}
}

func getMasterUserOptions(d *schema.ResourceData) []interface{} {
if v, ok := d.GetOk("advanced_security_options"); ok {
options := v.([]interface{})
if len(options) > 0 && options[0] != nil {
m := options[0].(map[string]interface{})
if opts, ok := m["master_user_options"]; ok {
return opts.([]interface{})
}
}
}
return []interface{}{}
}

func getUserDBEnabled(d *schema.ResourceData) bool {
if v, ok := d.GetOk("advanced_security_options"); ok {
options := v.([]interface{})
if len(options) > 0 && options[0] != nil {
m := options[0].(map[string]interface{})
if enabled, ok := m["internal_user_database_enabled"]; ok {
return enabled.(bool)
}
}
}
return false
}
1 change: 0 additions & 1 deletion aws/resource_aws_api_gateway_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ func resourceAwsApiGatewayResource() *schema.Resource {
}
restApiID := idParts[0]
resourceID := idParts[1]
d.Set("request_validator_id", resourceID)
d.Set("rest_api_id", restApiID)
d.SetId(resourceID)
return []*schema.ResourceData{d}, nil
Expand Down
21 changes: 12 additions & 9 deletions aws/resource_aws_elasticsearch_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -709,16 +709,19 @@ func resourceAwsElasticSearchDomainRead(d *schema.ResourceData, meta interface{}
return err
}

// Use AdvancedSecurityOptions from resource if possible
// because DescribeElasticsearchDomainConfig does not return MasterUserOptions
// Populate AdvancedSecurityOptions with values returned from
// DescribeElasticsearchDomainConfig, if enabled, else use
// values from resource; additionally, append MasterUserOptions
// from resource as they are not returned from the API
if ds.AdvancedSecurityOptions != nil {
if _, ok := d.GetOk("advanced_security_options"); ok {
d.Set("advanced_security_options.0.enabled", ds.AdvancedSecurityOptions.Enabled)
d.Set("advanced_security_options.0.internal_user_database_enabled", ds.AdvancedSecurityOptions.InternalUserDatabaseEnabled)
} else {
if err := d.Set("advanced_security_options", flattenAdvancedSecurityOptions(ds.AdvancedSecurityOptions)); err != nil {
return fmt.Errorf("error setting advanced_security_options: %w", err)
}
advSecOpts := flattenAdvancedSecurityOptions(ds.AdvancedSecurityOptions)
if !aws.BoolValue(ds.AdvancedSecurityOptions.Enabled) {
advSecOpts[0]["internal_user_database_enabled"] = getUserDBEnabled(d)
}
advSecOpts[0]["master_user_options"] = getMasterUserOptions(d)

if err := d.Set("advanced_security_options", advSecOpts); err != nil {
return fmt.Errorf("error setting advanced_security_options: %w", err)
}
}

Expand Down
6 changes: 5 additions & 1 deletion aws/resource_aws_lb_cookie_stickiness_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ func resourceAwsLBCookieStickinessPolicyRead(d *schema.ResourceData, meta interf

d.Set("name", policyName)
d.Set("load_balancer", lbName)
d.Set("lb_port", lbPort)
lbPortInt, err := strconv.Atoi(lbPort)
if err != nil {
return err
}
d.Set("lb_port", lbPortInt)

return nil
}
Expand Down
4 changes: 2 additions & 2 deletions aws/resource_aws_spot_instance_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ func readInstance(d *schema.ResourceData, meta interface{}) error {
for _, ni := range instance.NetworkInterfaces {
if *ni.Attachment.DeviceIndex == 0 {
d.Set("subnet_id", ni.SubnetId)
d.Set("network_interface_id", ni.NetworkInterfaceId)
d.Set("primary_network_interface_id", ni.NetworkInterfaceId)
d.Set("associate_public_ip_address", ni.Association != nil)
d.Set("ipv6_address_count", len(ni.Ipv6Addresses))

Expand All @@ -360,7 +360,7 @@ func readInstance(d *schema.ResourceData, meta interface{}) error {
}
} else {
d.Set("subnet_id", instance.SubnetId)
d.Set("network_interface_id", "")
d.Set("primary_network_interface_id", "")
}

if err := d.Set("ipv6_addresses", ipv6Addresses); err != nil {
Expand Down
5 changes: 4 additions & 1 deletion aws/resource_aws_ssm_association.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ func resourceAwsSsmAssociationRead(d *schema.ResourceData, meta interface{}) err
d.Set("association_name", association.AssociationName)
d.Set("instance_id", association.InstanceId)
d.Set("name", association.Name)
d.Set("parameters", association.Parameters)
d.Set("association_id", association.AssociationId)
d.Set("schedule_expression", association.ScheduleExpression)
d.Set("document_version", association.DocumentVersion)
Expand All @@ -227,6 +226,10 @@ func resourceAwsSsmAssociationRead(d *schema.ResourceData, meta interface{}) err
d.Set("max_errors", association.MaxErrors)
d.Set("automation_target_parameter_name", association.AutomationTargetParameterName)

if err := d.Set("parameters", flattenAwsSsmParameters(association.Parameters)); err != nil {
return err
}

if err := d.Set("targets", flattenAwsSsmTargets(association.Targets)); err != nil {
return fmt.Errorf("Error setting targets error: %#v", err)
}
Expand Down
14 changes: 14 additions & 0 deletions aws/structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -3262,6 +3262,20 @@ func expandAwsSsmTargets(in []interface{}) []*ssm.Target {
return targets
}

func flattenAwsSsmParameters(parameters map[string][]*string) map[string]string {
result := make(map[string]string)
for p, values := range parameters {
var vs []string
for _, vPtr := range values {
if v := aws.StringValue(vPtr); v != "" {
vs = append(vs, v)
}
}
result[p] = strings.Join(vs, ",")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bflad unsure if this was the right way to do this.. the data structure from the API is map[string][]string, so in the scenario where it's multiple values for 1 key I string delimited the list??

}
return result
}

func flattenAwsSsmTargets(targets []*ssm.Target) []map[string]interface{} {
if len(targets) == 0 {
return nil
Expand Down