From 2a7f525520f6ad8e8db77543cfcbfb54551eb155 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Thu, 4 Jan 2024 15:23:28 -0500 Subject: [PATCH 1/2] r/aws_datasync_agent: remove ExactlyOneOf activation_key, ip_address This requirement previously prevented successful import of agents initialized with an activation_key. The `activation_key` is not returned by the read operation, so setting this required value in configuration always forced a new resource on the next apply. Practitioners could work around the issue with an `ignore_changes` `lifecycle` argument, but removing the `ExactlyOneOf` condition in favor of a `ConflictsWith` condition allows agents created with an activation key to be imported _without_ requiring the attribute to be set in the corresponding Terraform configuration. --- internal/service/datasync/agent.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/internal/service/datasync/agent.go b/internal/service/datasync/agent.go index 2725d9c6f63a..201f4d73a4c2 100644 --- a/internal/service/datasync/agent.go +++ b/internal/service/datasync/agent.go @@ -52,15 +52,14 @@ func ResourceAgent() *schema.Resource { Optional: true, Computed: true, ForceNew: true, - ExactlyOneOf: []string{"activation_key", "ip_address"}, - ConflictsWith: []string{"private_link_endpoint"}, + ConflictsWith: []string{"private_link_endpoint", "ip_address"}, }, "ip_address": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ForceNew: true, - ExactlyOneOf: []string{"activation_key", "ip_address"}, + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + ConflictsWith: []string{"activation_key"}, }, "private_link_endpoint": { Type: schema.TypeString, @@ -107,6 +106,10 @@ func resourceAgentCreate(ctx context.Context, d *schema.ResourceData, meta inter // Perform one time fetch of activation key from gateway IP address. if activationKey == "" { + if agentIpAddress == "" { + return sdkdiag.AppendErrorf(diags, "one of activation_key or ip_address is required") + } + client := &http.Client{ CheckRedirect: func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse From d502fae2d73ecec51fe43206690070f90131378b Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Thu, 4 Jan 2024 16:45:45 -0500 Subject: [PATCH 2/2] chore: changelog --- .changelog/35150.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/35150.txt diff --git a/.changelog/35150.txt b/.changelog/35150.txt new file mode 100644 index 000000000000..127f0d056502 --- /dev/null +++ b/.changelog/35150.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_datasync_agent: Fix import of agents created with `activation_key` by removing requirement for one of `ip_address` or `activation_key` to be set +```