Skip to content
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

Add appconfig key resource #13118

Merged
merged 20 commits into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions internal/clients/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ func Build(ctx context.Context, builder ClientBuilder) (*Client, error) {
Environment: *env,
Features: builder.Features,
StorageUseAzureAD: builder.StorageUseAzureAD,
TokenFunc: func(endpoint string) (autorest.Authorizer, error) {
authorizer, err := builder.AuthConfig.GetAuthorizationToken(sender, oauthConfig, endpoint)
if err != nil {
return nil, fmt.Errorf("getting authorization token for endpoint %s: %+v", endpoint, err)
}
return authorizer, nil
},
}

if err := client.Build(ctx, o); err != nil {
Expand Down
3 changes: 3 additions & 0 deletions internal/common/client_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ type ClientOptions struct {
Environment azure.Environment
Features features.UserFeatures
StorageUseAzureAD bool

// Some Dataplane APIs require a token scoped for a specific endpoint
TokenFunc func(endpoint string) (autorest.Authorizer, error)
}

func (o ClientOptions) ConfigureClient(c *autorest.Client, authorizer autorest.Authorizer) {
Expand Down
1 change: 1 addition & 0 deletions internal/provider/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ import (
func SupportedTypedServices() []sdk.TypedServiceRegistration {
return []sdk.TypedServiceRegistration{
apimanagement.Registration{},
appconfiguration.Registration{},
batch.Registration{},
eventhub.Registration{},
loadbalancer.Registration{},
Expand Down
14 changes: 13 additions & 1 deletion internal/sdk/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ type Resource interface {
IDValidationFunc() pluginsdk.SchemaValidateFunc
}

// TODO: ResourceWithCustomizeDiff
// TODO: ResourceWithStateMigration
// TODO: a generic state migration for updating ID's

Expand Down Expand Up @@ -100,6 +99,14 @@ type ResourceWithDeprecation interface {
DeprecationMessage() string
}

// ResourceWithCustomizeDiff is an optional interface
type ResourceWithCustomizeDiff interface {
Resource

// CustomizeDiff returns a ResourceFunc that runs the Custom Diff logic
CustomizeDiff() ResourceFunc
}

// ResourceRunFunc is the function which can be run
// ctx provides a Context instance with the user-provided timeout
// metadata is a reference to an object containing the Client, ResourceData and a Logger
Expand All @@ -110,6 +117,8 @@ type ResourceFunc struct {
// for example, during Read this is the Read function, during Update this is the Update function
Func ResourceRunFunc

DiffFunc ResourceRunFunc

// Timeout is the default timeout, which can be overridden by users
// for this method - in-turn used for the Azure API
Timeout time.Duration
Expand All @@ -127,6 +136,9 @@ type ResourceMetaData struct {
// for example, to determine if a field has changes
ResourceData *schema.ResourceData

// ResourceDiff is a reference to the ResourceDiff object from Terraform's Plugin SDK
ResourceDiff *schema.ResourceDiff

// serializationDebugLogger is used for testing purposes
serializationDebugLogger Logger
}
Expand Down
17 changes: 15 additions & 2 deletions internal/sdk/wrapper_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
)

Expand Down Expand Up @@ -124,6 +125,20 @@ func (rw *ResourceWrapper) Resource() (*schema.Resource, error) {
resource.Timeouts.Update = d(v.Update().Timeout)
}

if v, ok := rw.resource.(ResourceWithCustomizeDiff); ok {
resource.CustomizeDiff = func(ctx context.Context, d *schema.ResourceDiff, meta interface{}) error {
client := meta.(*clients.Client)
metaData := ResourceMetaData{
Client: client,
Logger: rw.logger,
ResourceDiff: d,
serializationDebugLogger: NullLogger{},
}

return v.CustomizeDiff().Func(ctx, metaData)
}
}

if v, ok := rw.resource.(ResourceWithDeprecation); ok {
message := v.DeprecationMessage()
if message == "" {
Expand All @@ -132,8 +147,6 @@ func (rw *ResourceWrapper) Resource() (*schema.Resource, error) {

resource.DeprecationMessage = message
}

// TODO: CustomizeDiff
// TODO: State Migrations

return &resource, nil
Expand Down
Loading