diff --git a/datadog/resource_datadog_integration_aws.go b/datadog/resource_datadog_integration_aws.go index 64db268bcf..f6ca547836 100644 --- a/datadog/resource_datadog_integration_aws.go +++ b/datadog/resource_datadog_integration_aws.go @@ -361,7 +361,8 @@ func resourceDatadogIntegrationAwsImport(ctx context.Context, d *schema.Resource if d.Id() == "" { return nil, fmt.Errorf("error importing aws integration resource. Resource with id `%s` does not exist", originalId) } - - d.Set("external_id", os.Getenv("EXTERNAL_ID")) + if v, ok := os.LookupEnv("EXTERNAL_ID"); ok { + d.Set("external_id", v) + } return []*schema.ResourceData{d}, nil } diff --git a/docs/resources/integration_aws.md b/docs/resources/integration_aws.md index e3ded6bdcf..95a0190fa7 100644 --- a/docs/resources/integration_aws.md +++ b/docs/resources/integration_aws.md @@ -55,6 +55,12 @@ resource "datadog_integration_aws" "sandbox" { Import is supported using the following syntax: ```shell -# Amazon Web Services integrations can be imported using their account ID and role name separated with a colon (:), while the external_id should be passed by setting an environment variable called EXTERNAL_ID +# Amazon Web Services integrations can be imported using their account ID and role name separated with a colon (:), +# The EXTERNAL_ID variable is optional and allows to set external_id + +# Import will be done and the external_id will be set to the value of the EXTERNAL_ID variable EXTERNAL_ID=${external_id} terraform import datadog_integration_aws.test ${account_id}:${role_name} + +# Import will be done and the external_id will not be set +terraform import datadog_integration_aws.test ${account_id}:${role_name} ``` diff --git a/examples/resources/datadog_integration_aws/import.sh b/examples/resources/datadog_integration_aws/import.sh index c71b9779f6..028b2dff2f 100644 --- a/examples/resources/datadog_integration_aws/import.sh +++ b/examples/resources/datadog_integration_aws/import.sh @@ -1,2 +1,8 @@ -# Amazon Web Services integrations can be imported using their account ID and role name separated with a colon (:), while the external_id should be passed by setting an environment variable called EXTERNAL_ID +# Amazon Web Services integrations can be imported using their account ID and role name separated with a colon (:), +# The EXTERNAL_ID variable is optional and allows to set external_id + +# Import will be done and the external_id will be set to the value of the EXTERNAL_ID variable EXTERNAL_ID=${external_id} terraform import datadog_integration_aws.test ${account_id}:${role_name} + +# Import will be done and the external_id will not be set +terraform import datadog_integration_aws.test ${account_id}:${role_name} \ No newline at end of file