-
Notifications
You must be signed in to change notification settings - Fork 626
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
cloudflare_ip_list import set correct account_id #916
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is the solution to this issue as will not populate the client.AccountID
value for the Create
or Update
methods. Instead, I think you need to first check if the client.AccountID
is empty and then fetch the value if it is not.
func resourceCloudflareIPListRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*cloudflare.API)
if client.AccountID == "" {
client.AccountID = d.Get("account_id").(string)
}
// .. snip
how about this? func resourceCloudflareIPListImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
// ... snip
accountID, listID := attributes[0], attributes[1]
d.SetId(listID)
d.Set("account_id", accountID) // replace client.AccountID = accountID
// ... snip
}
|
ef79835
to
fc0f4f2
Compare
The change seems like a better outcome. Would you mind adding a test to verify the |
I looked, but didn't really understand how the test setup was supposed to work even after looking at the other import tests |
Sure, let me explain. For package cloudflare
import (
"fmt"
"os"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)
func TestAccCloudflareIPList_Import(t *testing.T) {
rnd := generateRandomResourceName()
accountID := os.Getenv("CLOUDFLARE_ACCOUNT_ID")
name := "cloudflare_ip_list." + rnd
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckCloudflareIPList(rnd, rnd, rnd, accountID),
},
{
ResourceName: name,
ImportStateIdPrefix: fmt.Sprintf("%s/", accountID),
ImportState: true,
ImportStateVerify: true,
},
},
})
} Running this on the
However, with your fix:
And because of the Full details on the I'll push up the changes to include this in your branch and we'll get this landed. |
this has been released in v2.18.0 |
The account id is set on L100 but overriden with the empty string (because it's an import action) on L109
terraform-provider-cloudflare/cloudflare/resource_cloudflare_ip_list.go
Lines 100 to 109 in 4b7fbd9
Fixes #915