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

azurerm_stream_analytics_job - add support for sku_name #24554

Merged
merged 7 commits into from
Jan 24, 2024
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
2 changes: 1 addition & 1 deletion internal/services/streamanalytics/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"github.com/hashicorp/go-azure-sdk/resource-manager/streamanalytics/2020-03-01/functions"
"github.com/hashicorp/go-azure-sdk/resource-manager/streamanalytics/2020-03-01/inputs"
"github.com/hashicorp/go-azure-sdk/resource-manager/streamanalytics/2020-03-01/privateendpoints"
"github.com/hashicorp/go-azure-sdk/resource-manager/streamanalytics/2020-03-01/streamingjobs"
"github.com/hashicorp/go-azure-sdk/resource-manager/streamanalytics/2020-03-01/transformations"
"github.com/hashicorp/go-azure-sdk/resource-manager/streamanalytics/2021-10-01-preview/outputs"
"github.com/hashicorp/go-azure-sdk/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-sdk/resource-manager/streamanalytics/2020-03-01/streamingjobs"
"github.com/hashicorp/go-azure-sdk/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
Expand Down Expand Up @@ -96,6 +96,11 @@ func dataSourceStreamAnalyticsJob() *pluginsdk.Resource {
Type: pluginsdk.TypeString,
Computed: true,
},

"sku_name": {
Type: pluginsdk.TypeString,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -191,6 +196,12 @@ func dataSourceStreamAnalyticsJobRead(d *pluginsdk.ResourceData, meta interface{
}
d.Set("job_id", jobId)

sku := ""
if props.Sku != nil && props.Sku.Name != nil {
sku = string(*props.Sku.Name)
}
d.Set("sku_name", sku)

if props.Transformation != nil && props.Transformation.Properties != nil {
var streamingUnits int64
if v := props.Transformation.Properties.StreamingUnits; v != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/identity"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
"github.com/hashicorp/go-azure-sdk/resource-manager/streamanalytics/2020-03-01/streamingjobs"
"github.com/hashicorp/go-azure-sdk/resource-manager/streamanalytics/2020-03-01/transformations"
"github.com/hashicorp/go-azure-sdk/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/locks"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/streamanalytics/migration"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/streamanalytics/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
Expand Down Expand Up @@ -140,7 +139,7 @@ func resourceStreamAnalyticsJob() *pluginsdk.Resource {
"streaming_units": {
Type: pluginsdk.TypeInt,
Optional: true,
ValidateFunc: validate.StreamAnalyticsJobStreamingUnits,
ValidateFunc: validation.IntBetween(1, 120),
},

"content_storage_policy": {
Expand Down Expand Up @@ -196,6 +195,16 @@ func resourceStreamAnalyticsJob() *pluginsdk.Resource {
Computed: true,
},

"sku_name": {
Type: pluginsdk.TypeString,
Optional: true,
Default: string(streamingjobs.SkuNameStandard),
ValidateFunc: validation.StringInSlice([]string{
string(streamingjobs.SkuNameStandard),
"StandardV2", // missing from swagger as described here https://github.com/Azure/azure-rest-api-specs/issues/27506
}, false),
},

"tags": commonschema.Tags(),
},
}
Expand Down Expand Up @@ -262,7 +271,7 @@ func resourceStreamAnalyticsJobCreateUpdate(d *pluginsdk.ResourceData, meta inte
Location: utils.String(azure.NormalizeLocation(d.Get("location").(string))),
Properties: &streamingjobs.StreamingJobProperties{
Sku: &streamingjobs.Sku{
Name: pointer.To(streamingjobs.SkuNameStandard),
Name: pointer.To(streamingjobs.SkuName(d.Get("sku_name").(string))),
},
ContentStoragePolicy: pointer.To(streamingjobs.ContentStoragePolicy(contentStoragePolicy)),
EventsLateArrivalMaxDelayInSeconds: pointer.To(int64(d.Get("events_late_arrival_max_delay_in_seconds").(int))),
Expand Down Expand Up @@ -437,6 +446,12 @@ func resourceStreamAnalyticsJobRead(d *pluginsdk.ResourceData, meta interface{})
}
d.Set("type", jobType)

sku := ""
if props.Sku != nil && props.Sku.Name != nil {
sku = string(*props.Sku.Name)
}
d.Set("sku_name", sku)

storagePolicy := ""
if v := props.ContentStoragePolicy; v != nil {
storagePolicy = string(*v)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"testing"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/streamanalytics/2020-03-01/streamingjobs"
"github.com/hashicorp/go-azure-sdk/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down Expand Up @@ -152,6 +152,32 @@ func TestAccStreamAnalyticsJob_jobStorageAccount(t *testing.T) {
})
}

func TestAccStreamAnalyticsJob_standardV2(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_stream_analytics_job", "test")
r := StreamAnalyticsJobResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("tags.%").HasValue("1"),
check.That(data.ResourceName).Key("tags.environment").HasValue("Test"),
),
},
data.ImportStep(),
{
Config: r.standardV2(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("tags.%").HasValue("1"),
check.That(data.ResourceName).Key("tags.environment").HasValue("Test"),
),
},
data.ImportStep(),
})
}

func (r StreamAnalyticsJobResource) Exists(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := streamingjobs.ParseStreamingJobID(state.ID)
if err != nil {
Expand Down Expand Up @@ -425,3 +451,35 @@ QUERY
}
`, data.RandomInteger, data.RandomString, data.Locations.Primary, data.RandomInteger)
}

func (r StreamAnalyticsJobResource) standardV2(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}

resource "azurerm_stream_analytics_job" "test" {
name = "acctestjob-%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
streaming_units = 7
sku_name = "StandardV2"

tags = {
environment = "Test"
}

transformation_query = <<QUERY
SELECT *
INTO [YourOutputAlias]
FROM [YourInputAlias]
QUERY

}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/Azure/go-autorest/autorest/date"
"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/streamanalytics/2020-03-01/streamingjobs"
"github.com/hashicorp/go-azure-sdk/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs"
"github.com/hashicorp/terraform-provider-azurerm/helpers/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/locks"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/streamanalytics/2020-03-01/streamingjobs"
"github.com/hashicorp/go-azure-sdk/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down
31 changes: 0 additions & 31 deletions internal/services/streamanalytics/validate/stream_analytics.go

This file was deleted.

This file was deleted.

Loading
Loading