-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Resource:
azurerm_spring_cloud_connection
and `azurerm_app_serv…
…ice_connection` (#16907) New Resource: `azurerm_spring_cloud_connection` and `azurerm_app_service_connection`
- Loading branch information
1 parent
04e8fae
commit 61db9d4
Showing
77 changed files
with
5,053 additions
and
0 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
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,25 @@ | ||
package client | ||
|
||
import ( | ||
"github.com/hashicorp/go-azure-sdk/resource-manager/servicelinker/2022-05-01/links" | ||
"github.com/hashicorp/go-azure-sdk/resource-manager/servicelinker/2022-05-01/servicelinker" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/common" | ||
) | ||
|
||
type Client struct { | ||
ServiceLinkerClient *servicelinker.ServicelinkerClient | ||
LinksClient *links.LinksClient | ||
} | ||
|
||
func NewClient(o *common.ClientOptions) *Client { | ||
serviceLinkerClient := servicelinker.NewServicelinkerClientWithBaseURI(o.ResourceManagerEndpoint) | ||
o.ConfigureClient(&serviceLinkerClient.Client, o.ResourceManagerAuthorizer) | ||
|
||
linksClient := links.NewLinksClientWithBaseURI(o.ResourceManagerEndpoint) | ||
o.ConfigureClient(&linksClient.Client, o.ResourceManagerAuthorizer) | ||
|
||
return &Client{ | ||
ServiceLinkerClient: &serviceLinkerClient, | ||
LinksClient: &linksClient, | ||
} | ||
} |
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,277 @@ | ||
package serviceconnector | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/go-azure-sdk/resource-manager/servicelinker/2022-05-01/servicelinker" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" | ||
"github.com/hashicorp/terraform-provider-azurerm/utils" | ||
) | ||
|
||
type AuthInfoModel struct { | ||
Type string `tfschema:"type"` | ||
Name string `tfschema:"name"` | ||
Secret string `tfschema:"secret"` | ||
ClientId string `tfschema:"client_id"` | ||
PrincipalId string `tfschema:"principal_id"` | ||
SubscriptionId string `tfschema:"subscription_id"` | ||
Certificate string `tfschema:"certificate"` | ||
} | ||
|
||
func authInfoSchema() *pluginsdk.Schema { | ||
return &pluginsdk.Schema{ | ||
Type: pluginsdk.TypeList, | ||
Required: true, | ||
MaxItems: 1, | ||
Elem: &pluginsdk.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"type": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
ValidateFunc: validation.StringInSlice([]string{ | ||
string(servicelinker.AuthTypeSecret), | ||
string(servicelinker.AuthTypeServicePrincipalSecret), | ||
string(servicelinker.AuthTypeServicePrincipalCertificate), | ||
string(servicelinker.AuthTypeSystemAssignedIdentity), | ||
string(servicelinker.AuthTypeUserAssignedIdentity), | ||
}, false), | ||
}, | ||
|
||
"name": { | ||
Type: pluginsdk.TypeString, | ||
Optional: true, | ||
ValidateFunc: validation.StringIsNotEmpty, | ||
}, | ||
|
||
"secret": { | ||
Type: pluginsdk.TypeString, | ||
Optional: true, | ||
Sensitive: true, | ||
ValidateFunc: validation.StringIsNotEmpty, | ||
}, | ||
|
||
"client_id": { | ||
Type: pluginsdk.TypeString, | ||
Optional: true, | ||
ValidateFunc: validation.StringIsNotEmpty, | ||
}, | ||
|
||
"subscription_id": { | ||
Type: pluginsdk.TypeString, | ||
Optional: true, | ||
ValidateFunc: validation.StringIsNotEmpty, | ||
}, | ||
|
||
"principal_id": { | ||
Type: pluginsdk.TypeString, | ||
Optional: true, | ||
ValidateFunc: validation.StringIsNotEmpty, | ||
}, | ||
|
||
"certificate": { | ||
Type: pluginsdk.TypeString, | ||
Optional: true, | ||
Sensitive: true, | ||
ValidateFunc: validation.StringIsNotEmpty, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func expandServiceConnectorAuthInfo(input []AuthInfoModel) (servicelinker.AuthInfoBase, error) { | ||
if len(input) == 0 { | ||
return nil, fmt.Errorf("authentication should be defined") | ||
} | ||
v := input[0] | ||
|
||
authType := servicelinker.AuthType(v.Type) | ||
name := v.Name | ||
secret := v.Secret | ||
clientId := v.ClientId | ||
subscriptionId := v.SubscriptionId | ||
principalId := v.PrincipalId | ||
certificate := v.Certificate | ||
|
||
switch authType { | ||
case servicelinker.AuthTypeSecret: | ||
if clientId != "" { | ||
return nil, fmt.Errorf("`client_id` cannot be set when `type` is set to `Secret`") | ||
} | ||
if subscriptionId != "" { | ||
return nil, fmt.Errorf("`subscription_id` cannot be set when `type` is set to `Secret`") | ||
} | ||
if principalId != "" { | ||
return nil, fmt.Errorf("`principal_id` cannot be set when `type` is set to `Secret`") | ||
} | ||
if certificate != "" { | ||
return nil, fmt.Errorf("`certificate` cannot be set when `type` is set to `Secret`") | ||
} | ||
if name != "" && secret == "" { | ||
return nil, fmt.Errorf("`name` cannot be set when `secret` is empty") | ||
} | ||
if name == "" && secret != "" { | ||
return nil, fmt.Errorf("`secret` cannot be set when `name` is empty") | ||
} | ||
return servicelinker.SecretAuthInfo{ | ||
Name: utils.String(name), | ||
SecretInfo: secret, | ||
}, nil | ||
|
||
case servicelinker.AuthTypeSystemAssignedIdentity: | ||
if name != "" || secret != "" || clientId != "" || subscriptionId != "" || principalId != "" || certificate != "" { | ||
return nil, fmt.Errorf("no other parameters should be set when `type` is set to `SystemIdentity`") | ||
} | ||
return servicelinker.SystemAssignedIdentityAuthInfo{}, nil | ||
|
||
case servicelinker.AuthTypeServicePrincipalSecret: | ||
if clientId == "" { | ||
return nil, fmt.Errorf("`client_id` must be specified when `type` is set to `ServicePrincipal`") | ||
} | ||
if principalId == "" { | ||
return nil, fmt.Errorf("`principal_id` must be specified when `type` is set to `ServicePrincipal`") | ||
} | ||
if secret == "" { | ||
return nil, fmt.Errorf("`secret` must be specified when `type` is set to `ServicePrincipal`") | ||
} | ||
if subscriptionId != "" { | ||
return nil, fmt.Errorf("`subscription_id` cannot be set when `type` is set to `ServicePrincipal`") | ||
} | ||
if name != "" { | ||
return nil, fmt.Errorf("`name` cannot be set when `type` is set to `ServicePrincipal`") | ||
} | ||
if certificate != "" { | ||
return nil, fmt.Errorf("`certificate` cannot be set when `type` is set to `ServicePrincipal`") | ||
} | ||
return servicelinker.ServicePrincipalSecretAuthInfo{ | ||
ClientId: clientId, | ||
PrincipalId: principalId, | ||
Secret: secret, | ||
}, nil | ||
|
||
case servicelinker.AuthTypeServicePrincipalCertificate: | ||
if clientId == "" { | ||
return nil, fmt.Errorf("`client_id` must be specified when `type` is set to `ServicePrincipalCertificate`") | ||
} | ||
if principalId == "" { | ||
return nil, fmt.Errorf("`principal_id` must be specified when `type` is set to `ServicePrincipalCertificate`") | ||
} | ||
if certificate == "" { | ||
return nil, fmt.Errorf("`certificate` must be specified when `type` is set to `ServicePrincipalCertificate`") | ||
} | ||
if subscriptionId != "" { | ||
return nil, fmt.Errorf("`subscription_id` cannot be set when `type` is set to `ServicePrincipalCertificate`") | ||
} | ||
if name != "" { | ||
return nil, fmt.Errorf("`name` cannot be set when `type` is set to `ServicePrincipalCertificate`") | ||
} | ||
if secret != "" { | ||
return nil, fmt.Errorf("`secret` cannot be set when `type` is set to `ServicePrincipalCertificate`") | ||
} | ||
return servicelinker.ServicePrincipalCertificateAuthInfo{ | ||
Certificate: certificate, | ||
ClientId: clientId, | ||
PrincipalId: principalId, | ||
}, nil | ||
|
||
case servicelinker.AuthTypeUserAssignedIdentity: | ||
if principalId != "" { | ||
return nil, fmt.Errorf("`principal_id` cannot be set when `type` is set to `UserIdentity`") | ||
} | ||
if certificate != "" { | ||
return nil, fmt.Errorf("`certificate` cannot be set when `type` is set to `UserIdentity`") | ||
} | ||
if name != "" { | ||
return nil, fmt.Errorf("`name` cannot be set when `type` is set to `UserIdentity`") | ||
} | ||
if secret != "" { | ||
return nil, fmt.Errorf("`secret` cannot be set when `type` is set to `UserIdentity`") | ||
} | ||
if clientId == "" && subscriptionId != "" { | ||
return nil, fmt.Errorf("`subscription_id` cannot be set when `client_id` is empty") | ||
} | ||
if clientId != "" && subscriptionId == "" { | ||
return nil, fmt.Errorf("`client_id` cannot be set when `subscription_id` is empty") | ||
} | ||
return servicelinker.UserAssignedIdentityAuthInfo{ | ||
ClientId: utils.String(clientId), | ||
SubscriptionId: utils.String(subscriptionId), | ||
}, nil | ||
} | ||
|
||
return nil, fmt.Errorf("unsupported authentication type %q", authType) | ||
} | ||
|
||
func flattenServiceConnectorAuthInfo(input servicelinker.AuthInfoBase) []AuthInfoModel { | ||
var authType string | ||
var name string | ||
var secret string | ||
var clientId string | ||
var principalId string | ||
var subscriptionId string | ||
var certificate string | ||
|
||
if value, ok := input.(servicelinker.SecretAuthInfo); ok { | ||
authType = string(servicelinker.AuthTypeSecret) | ||
if value.Name != nil { | ||
name = *value.Name | ||
} | ||
secret = value.SecretInfo.(string) | ||
} | ||
|
||
if _, ok := input.(servicelinker.SystemAssignedIdentityAuthInfo); ok { | ||
authType = string(servicelinker.AuthTypeSystemAssignedIdentity) | ||
} | ||
|
||
if value, ok := input.(servicelinker.UserAssignedIdentityAuthInfo); ok { | ||
authType = string(servicelinker.AuthTypeUserAssignedIdentity) | ||
if value.ClientId != nil { | ||
clientId = *value.ClientId | ||
} | ||
if value.SubscriptionId != nil { | ||
subscriptionId = *value.SubscriptionId | ||
} | ||
} | ||
|
||
if value, ok := input.(servicelinker.ServicePrincipalSecretAuthInfo); ok { | ||
authType = string(servicelinker.AuthTypeServicePrincipalSecret) | ||
clientId = value.ClientId | ||
principalId = value.PrincipalId | ||
secret = value.Secret | ||
} | ||
|
||
if value, ok := input.(servicelinker.ServicePrincipalCertificateAuthInfo); ok { | ||
authType = string(servicelinker.AuthTypeServicePrincipalCertificate) | ||
certificate = value.Certificate | ||
clientId = value.ClientId | ||
principalId = value.PrincipalId | ||
} | ||
|
||
return []AuthInfoModel{ | ||
{ | ||
Type: authType, | ||
Name: name, | ||
Secret: secret, | ||
ClientId: clientId, | ||
PrincipalId: principalId, | ||
SubscriptionId: subscriptionId, | ||
Certificate: certificate, | ||
}, | ||
} | ||
} | ||
|
||
//TODO: Only support Azure resource for now. Will include ConfluentBootstrapServer and ConfluentSchemaRegistry in the future. | ||
func flattenTargetService(input servicelinker.TargetServiceBase) string { | ||
var targetServiceId string | ||
|
||
if value, ok := input.(servicelinker.AzureResource); ok { | ||
if value.Id != nil { | ||
targetServiceId = *value.Id | ||
} | ||
} | ||
|
||
return targetServiceId | ||
} |
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,28 @@ | ||
package serviceconnector | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk" | ||
) | ||
|
||
type Registration struct{} | ||
|
||
var _ sdk.TypedServiceRegistration = Registration{} | ||
|
||
func (r Registration) WebsiteCategories() []string { | ||
return []string{} | ||
} | ||
|
||
func (r Registration) DataSources() []sdk.DataSource { | ||
return []sdk.DataSource{} | ||
} | ||
|
||
func (r Registration) Resources() []sdk.Resource { | ||
return []sdk.Resource{ | ||
AppServiceConnectorResource{}, | ||
SpringCloudConnectorResource{}, | ||
} | ||
} | ||
|
||
func (r Registration) Name() string { | ||
return "ServiceConnector" | ||
} |
Oops, something went wrong.