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 Azure Event Hubs ingestion fields to google_pubsub_topic #9065

Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions .changelog/12744.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
pubsub: added `ingestion_data_source_settings.azure_event_hubs` field to `google_pubsub_topic` resource
```
199 changes: 199 additions & 0 deletions google-beta/services/pubsub/resource_pubsub_topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,54 @@ equals to this service account number.`,
},
ConflictsWith: []string{},
},
"azure_event_hubs": {
Type: schema.TypeList,
Optional: true,
Description: `Settings for ingestion from Azure Event Hubs.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"client_id": {
Type: schema.TypeString,
Optional: true,
Description: `The Azure event hub client ID to use for ingestion.`,
},
"event_hub": {
Type: schema.TypeString,
Optional: true,
Description: `The Azure event hub to ingest data from.`,
},
"gcp_service_account": {
Type: schema.TypeString,
Optional: true,
Description: `The GCP service account to be used for Federated Identity authentication
with Azure (via a 'AssumeRoleWithWebIdentity' call for the provided
role).`,
},
"namespace": {
Type: schema.TypeString,
Optional: true,
Description: `The Azure event hub namespace to ingest data from.`,
},
"resource_group": {
Type: schema.TypeString,
Optional: true,
Description: `The name of the resource group within an Azure subscription.`,
},
"subscription_id": {
Type: schema.TypeString,
Optional: true,
Description: `The Azure event hub subscription ID to use for ingestion.`,
},
"tenant_id": {
Type: schema.TypeString,
Optional: true,
Description: `The Azure event hub tenant ID to use for ingestion.`,
},
},
},
ConflictsWith: []string{},
},
"cloud_storage": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -819,6 +867,8 @@ func flattenPubsubTopicIngestionDataSourceSettings(v interface{}, d *schema.Reso
flattenPubsubTopicIngestionDataSourceSettingsCloudStorage(original["cloudStorage"], d, config)
transformed["platform_logs_settings"] =
flattenPubsubTopicIngestionDataSourceSettingsPlatformLogsSettings(original["platformLogsSettings"], d, config)
transformed["azure_event_hubs"] =
flattenPubsubTopicIngestionDataSourceSettingsAzureEventHubs(original["azureEventHubs"], d, config)
return []interface{}{transformed}
}
func flattenPubsubTopicIngestionDataSourceSettingsAwsKinesis(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
Expand Down Expand Up @@ -941,6 +991,59 @@ func flattenPubsubTopicIngestionDataSourceSettingsPlatformLogsSettingsSeverity(v
return v
}

func flattenPubsubTopicIngestionDataSourceSettingsAzureEventHubs(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
}
original := v.(map[string]interface{})
if len(original) == 0 {
return nil
}
transformed := make(map[string]interface{})
transformed["resource_group"] =
flattenPubsubTopicIngestionDataSourceSettingsAzureEventHubsResourceGroup(original["resourceGroup"], d, config)
transformed["namespace"] =
flattenPubsubTopicIngestionDataSourceSettingsAzureEventHubsNamespace(original["namespace"], d, config)
transformed["event_hub"] =
flattenPubsubTopicIngestionDataSourceSettingsAzureEventHubsEventHub(original["eventHub"], d, config)
transformed["client_id"] =
flattenPubsubTopicIngestionDataSourceSettingsAzureEventHubsClientId(original["clientId"], d, config)
transformed["tenant_id"] =
flattenPubsubTopicIngestionDataSourceSettingsAzureEventHubsTenantId(original["tenantId"], d, config)
transformed["subscription_id"] =
flattenPubsubTopicIngestionDataSourceSettingsAzureEventHubsSubscriptionId(original["subscriptionId"], d, config)
transformed["gcp_service_account"] =
flattenPubsubTopicIngestionDataSourceSettingsAzureEventHubsGcpServiceAccount(original["gcpServiceAccount"], d, config)
return []interface{}{transformed}
}
func flattenPubsubTopicIngestionDataSourceSettingsAzureEventHubsResourceGroup(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenPubsubTopicIngestionDataSourceSettingsAzureEventHubsNamespace(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenPubsubTopicIngestionDataSourceSettingsAzureEventHubsEventHub(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenPubsubTopicIngestionDataSourceSettingsAzureEventHubsClientId(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenPubsubTopicIngestionDataSourceSettingsAzureEventHubsTenantId(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenPubsubTopicIngestionDataSourceSettingsAzureEventHubsSubscriptionId(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenPubsubTopicIngestionDataSourceSettingsAzureEventHubsGcpServiceAccount(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenPubsubTopicTerraformLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return v
Expand Down Expand Up @@ -1059,6 +1162,13 @@ func expandPubsubTopicIngestionDataSourceSettings(v interface{}, d tpgresource.T
transformed["platformLogsSettings"] = transformedPlatformLogsSettings
}

transformedAzureEventHubs, err := expandPubsubTopicIngestionDataSourceSettingsAzureEventHubs(original["azure_event_hubs"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedAzureEventHubs); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["azureEventHubs"] = transformedAzureEventHubs
}

return transformed, nil
}

Expand Down Expand Up @@ -1260,6 +1370,95 @@ func expandPubsubTopicIngestionDataSourceSettingsPlatformLogsSettingsSeverity(v
return v, nil
}

func expandPubsubTopicIngestionDataSourceSettingsAzureEventHubs(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
return nil, nil
}
raw := l[0]
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})

transformedResourceGroup, err := expandPubsubTopicIngestionDataSourceSettingsAzureEventHubsResourceGroup(original["resource_group"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedResourceGroup); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["resourceGroup"] = transformedResourceGroup
}

transformedNamespace, err := expandPubsubTopicIngestionDataSourceSettingsAzureEventHubsNamespace(original["namespace"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedNamespace); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["namespace"] = transformedNamespace
}

transformedEventHub, err := expandPubsubTopicIngestionDataSourceSettingsAzureEventHubsEventHub(original["event_hub"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedEventHub); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["eventHub"] = transformedEventHub
}

transformedClientId, err := expandPubsubTopicIngestionDataSourceSettingsAzureEventHubsClientId(original["client_id"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedClientId); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["clientId"] = transformedClientId
}

transformedTenantId, err := expandPubsubTopicIngestionDataSourceSettingsAzureEventHubsTenantId(original["tenant_id"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedTenantId); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["tenantId"] = transformedTenantId
}

transformedSubscriptionId, err := expandPubsubTopicIngestionDataSourceSettingsAzureEventHubsSubscriptionId(original["subscription_id"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedSubscriptionId); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["subscriptionId"] = transformedSubscriptionId
}

transformedGcpServiceAccount, err := expandPubsubTopicIngestionDataSourceSettingsAzureEventHubsGcpServiceAccount(original["gcp_service_account"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedGcpServiceAccount); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["gcpServiceAccount"] = transformedGcpServiceAccount
}

return transformed, nil
}

func expandPubsubTopicIngestionDataSourceSettingsAzureEventHubsResourceGroup(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandPubsubTopicIngestionDataSourceSettingsAzureEventHubsNamespace(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandPubsubTopicIngestionDataSourceSettingsAzureEventHubsEventHub(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandPubsubTopicIngestionDataSourceSettingsAzureEventHubsClientId(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandPubsubTopicIngestionDataSourceSettingsAzureEventHubsTenantId(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandPubsubTopicIngestionDataSourceSettingsAzureEventHubsSubscriptionId(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandPubsubTopicIngestionDataSourceSettingsAzureEventHubsGcpServiceAccount(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandPubsubTopicEffectiveLabels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
if v == nil {
return map[string]string{}, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,52 @@ resource "google_pubsub_topic" "example" {
`, context)
}

func TestAccPubsubTopic_pubsubTopicIngestionAzureEventHubsExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckPubsubTopicDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccPubsubTopic_pubsubTopicIngestionAzureEventHubsExample(context),
},
{
ResourceName: "google_pubsub_topic.example",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"labels", "terraform_labels"},
},
},
})
}

func testAccPubsubTopic_pubsubTopicIngestionAzureEventHubsExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_pubsub_topic" "example" {
name = "tf-test-example-topic%{random_suffix}"

# Outside of automated terraform-provider-google CI tests, these values must be of actual Azure resources for the test to pass.
ingestion_data_source_settings {
azure_event_hubs {
resource_group = "azure-ingestion-resource-group"
namespace = "azure-ingestion-namespace"
event_hub = "azure-ingestion-event-hub"
client_id = "aZZZZZZZ-YYYY-HHHH-GGGG-abcdef569123"
tenant_id = "0XXXXXXX-YYYY-HHHH-GGGG-123456789123"
subscription_id = "bXXXXXXX-YYYY-HHHH-GGGG-123456789123"
gcp_service_account = "[email protected]"
}
}
}
`, context)
}

func testAccCheckPubsubTopicDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
Expand Down
74 changes: 74 additions & 0 deletions google-beta/services/pubsub/resource_pubsub_topic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,3 +369,77 @@ resource "google_pubsub_topic" "foo" {
}
`, topic)
}

func TestAccPubsubTopic_azureEventHubsIngestionUpdate(t *testing.T) {
t.Parallel()

topic := fmt.Sprintf("tf-test-topic-%s", acctest.RandString(t, 10))

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckPubsubTopicDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccPubsubTopic_updateWithAzureEventHubsIngestionSettings(topic),
},
{
ResourceName: "google_pubsub_topic.foo",
ImportStateId: topic,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccPubsubTopic_updateWithUpdatedAzureEventHubsIngestionSettings(topic),
},
{
ResourceName: "google_pubsub_topic.foo",
ImportStateId: topic,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccPubsubTopic_updateWithAzureEventHubsIngestionSettings(topic string) string {
return fmt.Sprintf(`
resource "google_pubsub_topic" "foo" {
name = "%s"

# Outside of automated terraform-provider-google CI tests, these values must be of actual Cloud Storage resources for the test to pass.
ingestion_data_source_settings {
azure_event_hubs {
resource_group = "azure-ingestion-resource-group"
namespace = "azure-ingestion-namespace"
event_hub = "azure-ingestion-event-hub"
client_id = "aZZZZZZZ-YYYY-HHHH-GGGG-abcdef569123"
tenant_id = "0XXXXXXX-YYYY-HHHH-GGGG-123456789123"
subscription_id = "bXXXXXXX-YYYY-HHHH-GGGG-123456789123"
gcp_service_account = "[email protected]"
}
}
}
`, topic)
}

func testAccPubsubTopic_updateWithUpdatedAzureEventHubsIngestionSettings(topic string) string {
return fmt.Sprintf(`
resource "google_pubsub_topic" "foo" {
name = "%s"

# Outside of automated terraform-provider-google CI tests, these values must be of actual Cloud Storage resources for the test to pass.
ingestion_data_source_settings {
azure_event_hubs {
resource_group = "ingestion-resource-group"
namespace = "ingestion-namespace"
event_hub = "ingestion-event-hub"
client_id = "aZZZZZZZ-YYYY-HHHH-GGGG-abcdef123456"
tenant_id = "0XXXXXXX-YYYY-HHHH-GGGG-123456123456"
subscription_id = "bXXXXXXX-YYYY-HHHH-GGGG-123456123456"
gcp_service_account = "[email protected]"
}
}
}
`, topic)
}
Loading
Loading