-
Notifications
You must be signed in to change notification settings - Fork 9.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for provider metadata to modules. (#22583)
Implement a new provider_meta block in the terraform block of modules, allowing provider-keyed metadata to be communicated from HCL to provider binaries. Bundled in this change for minimal protocol version bumping is the addition of markdown support for attribute descriptions and the ability to indicate when an attribute is deprecated, so this information can be shown in the schema dump. Co-authored-by: Paul Tyng <paul@paultyng.net>
- Loading branch information
1 parent
4654b45
commit e6592dc
Showing
56 changed files
with
2,457 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package test | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func testResourceProviderMeta() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: testResourceProviderMetaCreate, | ||
Read: testResourceProviderMetaRead, | ||
Update: testResourceProviderMetaUpdate, | ||
Delete: testResourceProviderMetaDelete, | ||
|
||
Importer: &schema.ResourceImporter{ | ||
State: schema.ImportStatePassthrough, | ||
}, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"optional": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
type providerMeta struct { | ||
Foo string `cty:"foo"` | ||
} | ||
|
||
func testResourceProviderMetaCreate(d *schema.ResourceData, meta interface{}) error { | ||
d.SetId("testId") | ||
var m providerMeta | ||
|
||
err := d.GetProviderMeta(&m) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if m.Foo != "bar" { | ||
return fmt.Errorf("expected provider_meta.foo to be %q, was %q", | ||
"bar", m.Foo) | ||
} | ||
|
||
return testResourceProviderMetaRead(d, meta) | ||
} | ||
|
||
func testResourceProviderMetaRead(d *schema.ResourceData, meta interface{}) error { | ||
var m providerMeta | ||
|
||
err := d.GetProviderMeta(&m) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if m.Foo != "bar" { | ||
return fmt.Errorf("expected provider_meta.foo to be %q, was %q", | ||
"bar", m.Foo) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func testResourceProviderMetaUpdate(d *schema.ResourceData, meta interface{}) error { | ||
var m providerMeta | ||
|
||
err := d.GetProviderMeta(&m) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if m.Foo != "bar" { | ||
return fmt.Errorf("expected provider_meta.foo to be %q, was %q", | ||
"bar", m.Foo) | ||
} | ||
return testResourceProviderMetaRead(d, meta) | ||
} | ||
|
||
func testResourceProviderMetaDelete(d *schema.ResourceData, meta interface{}) error { | ||
d.SetId("") | ||
var m providerMeta | ||
|
||
err := d.GetProviderMeta(&m) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if m.Foo != "bar" { | ||
return fmt.Errorf("expected provider_meta.foo to be %q, was %q", | ||
"bar", m.Foo) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package test | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestResourceProviderMeta_basic(t *testing.T) { | ||
resource.UnitTest(t, resource.TestCase{ | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckResourceDestroy, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: strings.TrimSpace(` | ||
terraform { | ||
provider_meta "test" { | ||
foo = "bar" | ||
} | ||
} | ||
resource "test_resource_provider_meta" "foo" { | ||
} | ||
`), | ||
}, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.