diff --git a/builtin/providers/digitalocean/resource_digitalocean_droplet.go b/builtin/providers/digitalocean/resource_digitalocean_droplet.go index 875fd952b..36391f6d3 100644 --- a/builtin/providers/digitalocean/resource_digitalocean_droplet.go +++ b/builtin/providers/digitalocean/resource_digitalocean_droplet.go @@ -194,6 +194,11 @@ func resource_digitalocean_droplet_destroy( // Destroy the droplet err := client.DestroyDroplet(s.ID) + // Handle remotely destroyed droplets + if err != nil && strings.Contains(err.Error(), "404 Not Found") { + return nil + } + if err != nil { return fmt.Errorf("Error deleting Droplet: %s", err) } @@ -208,6 +213,12 @@ func resource_digitalocean_droplet_refresh( client := p.client droplet, err := resource_digitalocean_droplet_retrieve(s.ID, client) + + // Handle remotely destroyed droplets + if err != nil && strings.Contains(err.Error(), "404 Not Found") { + return nil, nil + } + if err != nil { return nil, err } diff --git a/builtin/providers/digitalocean/resource_digitalocean_record.go b/builtin/providers/digitalocean/resource_digitalocean_record.go index 011f5875d..939795a9c 100644 --- a/builtin/providers/digitalocean/resource_digitalocean_record.go +++ b/builtin/providers/digitalocean/resource_digitalocean_record.go @@ -149,11 +149,10 @@ func resource_digitalocean_record_update_state( s.Attributes["priority"] = rec.StringPriority() s.Attributes["port"] = rec.StringPort() - - // We belong to a Domain - s.Dependencies = []terraform.ResourceDependency{ - terraform.ResourceDependency{ID: s.Attributes["domain"]}, - } + // We belong to a Domain + s.Dependencies = []terraform.ResourceDependency{ + terraform.ResourceDependency{ID: s.Attributes["domain"]}, + } return s, nil } diff --git a/terraform/context.go b/terraform/context.go index eed5ecc46..05f1231f5 100644 --- a/terraform/context.go +++ b/terraform/context.go @@ -820,7 +820,11 @@ func (c *Context) refreshWalkFn() depgraph.WalkFunc { rs.Type = r.State.Type c.sl.Lock() - c.state.Resources[r.Id] = rs + if rs.ID == "" { + delete(c.state.Resources, r.Id) + } else { + c.state.Resources[r.Id] = rs + } c.sl.Unlock() for _, h := range c.hooks { diff --git a/terraform/context_test.go b/terraform/context_test.go index 3516bc5cd..7af65afec 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -1639,6 +1639,37 @@ func TestContextRefresh(t *testing.T) { } } +func TestContextRefresh_delete(t *testing.T) { + p := testProvider("aws") + c := testConfig(t, "refresh-basic") + ctx := testContext(t, &ContextOpts{ + Config: c, + Providers: map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + State: &State{ + Resources: map[string]*ResourceState{ + "aws_instance.web": &ResourceState{ + ID: "foo", + Type: "aws_instance", + }, + }, + }, + }) + + p.RefreshFn = nil + p.RefreshReturn = nil + + s, err := ctx.Refresh() + if err != nil { + t.Fatalf("err: %s", err) + } + + if len(s.Resources) > 0 { + t.Fatal("resources should be empty") + } +} + func TestContextRefresh_ignoreUncreated(t *testing.T) { p := testProvider("aws") c := testConfig(t, "refresh-basic") diff --git a/website/source/docs/configuration/index.html.md b/website/source/docs/configuration/index.html.md new file mode 100644 index 000000000..6c015bfbd --- /dev/null +++ b/website/source/docs/configuration/index.html.md @@ -0,0 +1,23 @@ +--- +layout: "docs" +page_title: "Configuration" +sidebar_current: "docs-config" +--- + +# Configuration + +Terraform uses text files to describe infrastructure and to set variables. +These text files are called Terraform _configurations_ and end in +`.tf`. This section talks about the format of these files as well as +how they're loaded. + +The format of the configuration files are able to be in two formats: +Terraform format and JSON. The Terraform format is more human-readable, +supports comments, and is the generally recommended format for most +Terraform files. The JSON format is meant for machines to create, +modify, and update, but can also be done by Terraform operators if +you prefer. Terraform format ends in `.tf` and JSON format ends in +`.tf.json`. + +Click a sub-section in the navigation to the left to learn more about +Terraform configuration. diff --git a/website/source/docs/configuration/load.html.md b/website/source/docs/configuration/load.html.md new file mode 100644 index 000000000..66ed02b9a --- /dev/null +++ b/website/source/docs/configuration/load.html.md @@ -0,0 +1,30 @@ +--- +layout: "docs" +page_title: "Load Order and Semantics" +sidebar_current: "docs-config-load" +--- + +# Load Order and Semantics + +When invoking any command that loads the Terraform configuration, +Terraform loads all configuration files within the directory +specified in alphabetical order. The flies loaded must end in +either `.tf` or `.tf.json` to specify the format that is in use. +Otherwise, the files are ignored. + +[Override](/docs/configuration/override.html) +files are the exception, as they're loaded after all non-override +files, in alphabetical order. + +The configuration within the loaded files are appended to each +other. This is in contrast to being merged. This means that two +resources with the same name are not merged, and will instead +cause a validation error. This is in contrast to +[overrides](/docs/configuration/override.html), +which do merge. + +The order of variables, resources, etc. defined within the +configuration doesn't matter. Terraform configurations are +[declarative](http://en.wikipedia.org/wiki/Declarative_programming), +so references to other resources and variables do not depend +on the order they're defined. diff --git a/website/source/layouts/docs.erb b/website/source/layouts/docs.erb index c32287ca1..c5125efb3 100644 --- a/website/source/layouts/docs.erb +++ b/website/source/layouts/docs.erb @@ -8,87 +8,98 @@ > Configuration - - + + > Commands (CLI) > Providers - + > Provisioners - + > Guides - > Internals -