Skip to content

Commit

Permalink
Merge pull request #36592 from hashicorp/b-elasticsearch_domain_polic…
Browse files Browse the repository at this point in the history
…y-retry

r/aws_opensearch_domain_policy: handle domain update propagation delays
  • Loading branch information
jar-b authored Mar 26, 2024
2 parents 50a4be7 + 830a524 commit 78c1710
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .changelog/36592.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
```release-note:bug
resource/aws_elasticsearch_domain_policy: Handle delayed domain status propagation, preventing a `ValidationException`.
```
```release-note:bug
resource/aws_opensearch_domain_policy: Handle delayed domain status propagation, preventing a `ValidationException`.
```
14 changes: 10 additions & 4 deletions internal/service/elasticsearch/domain_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,16 @@ func resourceDomainPolicyUpsert(ctx context.Context, d *schema.ResourceData, met
return sdkdiag.AppendErrorf(diags, "policy (%s) is invalid JSON: %s", policy, err)
}

_, err = conn.UpdateElasticsearchDomainConfigWithContext(ctx, &elasticsearch.UpdateElasticsearchDomainConfigInput{
DomainName: aws.String(domainName),
AccessPolicies: aws.String(policy),
})
_, err = tfresource.RetryWhenAWSErrMessageContains(ctx, propagationTimeout,
func() (interface{}, error) {
return conn.UpdateElasticsearchDomainConfigWithContext(ctx, &elasticsearch.UpdateElasticsearchDomainConfigInput{
DomainName: aws.String(domainName),
AccessPolicies: aws.String(policy),
})
},
elasticsearch.ErrCodeValidationException,
"A change/update is in progress",
)
if err != nil {
return sdkdiag.AppendErrorf(diags, "setting Elasticsearch Domain Policy (%s): %s", d.Id(), err)
}
Expand Down
14 changes: 10 additions & 4 deletions internal/service/opensearch/domain_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,16 @@ func resourceDomainPolicyUpsert(ctx context.Context, d *schema.ResourceData, met
return sdkdiag.AppendErrorf(diags, "policy (%s) is invalid JSON: %s", policy, err)
}

_, err = conn.UpdateDomainConfigWithContext(ctx, &opensearchservice.UpdateDomainConfigInput{
DomainName: aws.String(domainName),
AccessPolicies: aws.String(policy),
})
_, err = tfresource.RetryWhenAWSErrMessageContains(ctx, propagationTimeout,
func() (interface{}, error) {
return conn.UpdateDomainConfigWithContext(ctx, &opensearchservice.UpdateDomainConfigInput{
DomainName: aws.String(domainName),
AccessPolicies: aws.String(policy),
})
},
opensearchservice.ErrCodeValidationException,
"A change/update is in progress",
)
if err != nil {
return sdkdiag.AppendErrorf(diags, "updating OpenSearch Domain Policy (%s): %s", d.Id(), err)
}
Expand Down

0 comments on commit 78c1710

Please sign in to comment.