title: How can I inject a URL of a mock server to terraform's acceptance tests?
body: <p>There's a whole section about acceptance tests for terraform provider on the <a href="https://www.terraform.io/docs/extend/testing/acceptance-tests/index.html" rel="nofollow noreferrer">official</a> website that is assumes I'm going to run it with a test account on a real infrastructure.</p>
  <p>That said, in my case I can't use my real infrastructure and the plan is to use a mock server instead that I want to make tf provider / client talk to and I do have a specific variable for it:</p>
  <pre><code>provider &quot;foo&quot; {
    endpoint = var.endpoint
  }
  
  variable &quot;endpoint&quot; {
    type = string
    description = &quot;Endpoint to talk to&quot;
    default = &quot;https://realinfra.com&quot; % want to use &quot;localhost:9090&quot; (mock server's address) in tests instead
  }
  </code></pre>
  <p>Can I set / pass it somehow in acceptance tests? Here's the minimal working <a href="https://www.terraform.io/docs/extend/testing/acceptance-tests/testcase.html" rel="nofollow noreferrer">example</a> of my test:</p>
  <pre><code>package example
  
  // example.Widget represents a concrete Go type that represents an API resource
  func TestAccExampleWidget_basic(t *testing.T) {
      var widgetBefore, widgetAfter example.Widget
      rName := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)
  
      resource.Test(t, resource.TestCase{
          PreCheck:     func() { testAccPreCheck(t) },
          Providers:    testAccProviders,
          CheckDestroy: testAccCheckExampleResourceDestroy,
          Steps: []resource.TestStep{
              {
                  Config: testAccExampleResource(rName),
                  Check: resource.ComposeTestCheckFunc(
                      testAccCheckExampleResourceExists(&quot;example_widget.foo&quot;, &amp;widgetBefore),
                  ),
              },
              {
                  Config: testAccExampleResource_removedPolicy(rName),
                  Check: resource.ComposeTestCheckFunc(
                      testAccCheckExampleResourceExists(&quot;example_widget.foo&quot;, &amp;widgetAfter),
                  ),
              },
          },
      })
  }
  </code></pre>
  <p>In different words (or like a more general question), how would you set the values for variables in tf provider given that you've got:</p>
  <pre><code>func Provider() *schema.Provider {
      return &amp;schema.Provider{
          Schema: map[string]*schema.Schema{
          ...,
          &quot;endpoint&quot;: {
                  Type:     schema.TypeString,
                  Optional: true,
                  Default:  &quot;https://realinfra.com&quot;,
              },
          &quot;email&quot;: {
                  Type:        schema.TypeString,
                  Optional:    true,
                  DefaultFunc: schema.EnvDefaultFunc(&quot;FOO_USERNAME&quot;, &quot;&quot;),
              }, 
  </code></pre>