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

Update NGINXaaS API: 2024-09-01-preview #27776

Merged
merged 6 commits into from
Dec 9, 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
4 changes: 2 additions & 2 deletions internal/clients/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
dns_v2018_05_01 "github.com/hashicorp/go-azure-sdk/resource-manager/dns/2018-05-01"
fluidrelay_2022_05_26 "github.com/hashicorp/go-azure-sdk/resource-manager/fluidrelay/2022-05-26"
hdinsight_v2021_06_01 "github.com/hashicorp/go-azure-sdk/resource-manager/hdinsight/2021-06-01"
nginx_2024_06_01_preview "github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-06-01-preview"
nginx_2024_09_01_preview "github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-09-01-preview"
redis_2024_03_01 "github.com/hashicorp/go-azure-sdk/resource-manager/redis/2024-03-01"
servicenetworking_2023_11_01 "github.com/hashicorp/go-azure-sdk/resource-manager/servicenetworking/2023-11-01"
storagecache_2023_05_01 "github.com/hashicorp/go-azure-sdk/resource-manager/storagecache/2023-05-01"
Expand Down Expand Up @@ -241,7 +241,7 @@ type Client struct {
Network *network.Client
NetworkFunction *networkfunction.Client
NewRelic *newrelic.Client
Nginx *nginx_2024_06_01_preview.Client
Nginx *nginx_2024_09_01_preview.Client
NotificationHubs *notificationhub.Client
Oracle *oracle.Client
Orbital *orbital.Client
Expand Down
6 changes: 3 additions & 3 deletions internal/services/nginx/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ package client
import (
"fmt"

nginx_2024_06_01_preview "github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-06-01-preview"
nginx_2024_09_01_preview "github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-09-01-preview"
"github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
)

func NewClient(o *common.ClientOptions) (*nginx_2024_06_01_preview.Client, error) {
client, err := nginx_2024_06_01_preview.NewClientWithBaseURI(o.Environment.ResourceManager, func(c *resourcemanager.Client) {
func NewClient(o *common.ClientOptions) (*nginx_2024_09_01_preview.Client, error) {
client, err := nginx_2024_09_01_preview.NewClientWithBaseURI(o.Environment.ResourceManager, func(c *resourcemanager.Client) {
c.Authorizer = o.Authorizers.ResourceManager
})
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/services/nginx/nginx_certificate_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-06-01-preview/nginxcertificate"
"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-06-01-preview/nginxdeployment"
"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-09-01-preview/nginxcertificate"
"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-09-01-preview/nginxdeployment"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
Expand Down
4 changes: 2 additions & 2 deletions internal/services/nginx/nginx_certificate_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-06-01-preview/nginxcertificate"
"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-06-01-preview/nginxdeployment"
"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-09-01-preview/nginxcertificate"
"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-09-01-preview/nginxdeployment"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
keyvaultValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/keyvault/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"fmt"
"testing"

"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-06-01-preview/nginxcertificate"
"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-09-01-preview/nginxcertificate"
"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
41 changes: 25 additions & 16 deletions internal/services/nginx/nginx_configuration_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,24 @@ import (

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-06-01-preview/nginxconfiguration"
"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-06-01-preview/nginxdeployment"
"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-09-01-preview/nginxconfiguration"
"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-09-01-preview/nginxdeployment"
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
)

type ProtectedFileData struct {
Content string `tfschema:"content,removedInNextMajorVersion"`
VirtualPath string `tfschema:"virtual_path"`
}

type ConfigurationDataSourceModel struct {
NginxDeploymentId string `tfschema:"nginx_deployment_id"`
ConfigFile []ConfigFile `tfschema:"config_file"`
ProtectedFile []ProtectedFile `tfschema:"protected_file"`
PackageData string `tfschema:"package_data"`
RootFile string `tfschema:"root_file"`
NginxDeploymentId string `tfschema:"nginx_deployment_id"`
ConfigFile []ConfigFile `tfschema:"config_file"`
ProtectedFile []ProtectedFileData `tfschema:"protected_file"`
PackageData string `tfschema:"package_data"`
RootFile string `tfschema:"root_file"`
}

type ConfigurationDataSource struct{}
Expand All @@ -39,7 +45,7 @@ func (m ConfigurationDataSource) Arguments() map[string]*pluginsdk.Schema {
}

func (m ConfigurationDataSource) Attributes() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{
dataSource := map[string]*pluginsdk.Schema{
"config_file": {
Type: pluginsdk.TypeSet,
Computed: true,
Expand All @@ -63,12 +69,6 @@ func (m ConfigurationDataSource) Attributes() map[string]*pluginsdk.Schema {
Computed: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"content": {
Type: pluginsdk.TypeString,
Computed: true,
Sensitive: true,
},

"virtual_path": {
Type: pluginsdk.TypeString,
Computed: true,
Expand All @@ -87,6 +87,16 @@ func (m ConfigurationDataSource) Attributes() map[string]*pluginsdk.Schema {
Computed: true,
},
}

if !features.FivePointOhBeta() {
dataSource["protected_file"].Elem.(*pluginsdk.Resource).Schema["content"] = &pluginsdk.Schema{
Type: pluginsdk.TypeString,
Computed: true,
Sensitive: true,
Deprecated: "the `content` property is deprecated and will be removed in v5.0 of the AzureRM Provider.",
}
}
return dataSource
}

func (m ConfigurationDataSource) ModelObject() interface{} {
Expand Down Expand Up @@ -147,8 +157,7 @@ func (m ConfigurationDataSource) Read() sdk.ResourceFunc {

if files := prop.ProtectedFiles; files != nil {
for _, file := range *files {
output.ProtectedFile = append(output.ProtectedFile, ProtectedFile{
Content: pointer.From(file.Content),
output.ProtectedFile = append(output.ProtectedFile, ProtectedFileData{
VirtualPath: pointer.From(file.VirtualPath),
})
}
Expand Down
46 changes: 27 additions & 19 deletions internal/services/nginx/nginx_configuration_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-06-01-preview/nginxconfiguration"
"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-06-01-preview/nginxdeployment"
"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-09-01-preview/nginxconfiguration"
"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-09-01-preview/nginxdeployment"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
Expand All @@ -36,8 +36,8 @@ type ProtectedFile struct {
VirtualPath string `tfschema:"virtual_path"`
}

func (c ProtectedFile) toSDKModel() nginxconfiguration.NginxConfigurationFile {
return nginxconfiguration.NginxConfigurationFile{
func (c ProtectedFile) toSDKModel() nginxconfiguration.NginxConfigurationProtectedFileRequest {
return nginxconfiguration.NginxConfigurationProtectedFileRequest{
Content: pointer.To(c.Content),
VirtualPath: pointer.To(c.VirtualPath),
}
Expand All @@ -59,23 +59,22 @@ func (c ConfigurationModel) toSDKFiles() *[]nginxconfiguration.NginxConfiguratio
return &files
}

func (c ConfigurationModel) toSDKProtectedFiles() *[]nginxconfiguration.NginxConfigurationFile {
func (c ConfigurationModel) toSDKProtectedFiles() *[]nginxconfiguration.NginxConfigurationProtectedFileRequest {
if len(c.ProtectedFile) == 0 {
return nil
}

files := make([]nginxconfiguration.NginxConfigurationFile, 0, len(c.ProtectedFile))
files := []nginxconfiguration.NginxConfigurationProtectedFileRequest{}
for _, file := range c.ProtectedFile {
files = append(files, file.toSDKModel())
}
return &files
}

// ToSDKModel used in both Create and Update
func (c ConfigurationModel) ToSDKModel() nginxconfiguration.NginxConfiguration {
req := nginxconfiguration.NginxConfiguration{
func (c ConfigurationModel) ToSDKModel() nginxconfiguration.NginxConfigurationRequest {
req := nginxconfiguration.NginxConfigurationRequest{
Name: pointer.To(defaultConfigurationName),
Properties: &nginxconfiguration.NginxConfigurationProperties{
Properties: &nginxconfiguration.NginxConfigurationRequestProperties{
RootFile: pointer.To(c.RootFile),
},
}
Expand Down Expand Up @@ -272,14 +271,17 @@ func (m ConfigurationResource) Read() sdk.ResourceFunc {
if files := prop.ProtectedFiles; files != nil {
configs := []ProtectedFile{}
for _, file := range *files {
if pointer.From(file.Content) != "" {
configs = append(configs, ProtectedFile{
Content: pointer.ToString(file.Content),
VirtualPath: pointer.ToString(file.VirtualPath),
})
config := ProtectedFile{
VirtualPath: pointer.ToString(file.VirtualPath),
}
for _, protectedFile := range output.ProtectedFile {
puneetsarna marked this conversation as resolved.
Show resolved Hide resolved
if protectedFile.VirtualPath == pointer.ToString(file.VirtualPath) {
config.Content = protectedFile.Content
break
stephybun marked this conversation as resolved.
Show resolved Hide resolved
}
}
configs = append(configs, config)
}

if len(configs) > 0 {
output.ProtectedFile = configs
}
Expand Down Expand Up @@ -315,8 +317,14 @@ func (m ConfigurationResource) Update() sdk.ResourceFunc {
return fmt.Errorf("retrieving as nil for %v", *id)
}

upd := existing.Model
// root file is required in update
upd := nginxconfiguration.NginxConfigurationRequest{
Name: pointer.To(defaultConfigurationName),
Properties: &nginxconfiguration.NginxConfigurationRequestProperties{
// root file is required in update
RootFile: existing.Model.Properties.RootFile,
},
}

if meta.ResourceData.HasChange("root_file") {
upd.Properties.RootFile = pointer.To(model.RootFile)
}
Expand All @@ -334,7 +342,7 @@ func (m ConfigurationResource) Update() sdk.ResourceFunc {
}
}

if err := client.ConfigurationsCreateOrUpdateThenPoll(ctx, *id, *upd); err != nil {
if err := client.ConfigurationsCreateOrUpdateThenPoll(ctx, *id, upd); err != nil {
return fmt.Errorf("updating %s: %v", id, err)
}

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/pointer"
"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-06-01-preview/nginxconfiguration"
"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-09-01-preview/nginxconfiguration"
"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
22 changes: 13 additions & 9 deletions internal/services/nginx/nginx_deployment_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import (
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/identity"
"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-06-01-preview/nginxdeployment"
"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-09-01-preview/nginxdeployment"
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
Expand All @@ -24,7 +25,7 @@ type DeploymentDataSourceModel struct {
NginxVersion string `tfschema:"nginx_version"`
Identity []identity.ModelSystemAssignedUserAssigned `tfschema:"identity"`
Sku string `tfschema:"sku"`
ManagedResourceGroup string `tfschema:"managed_resource_group"`
ManagedResourceGroup string `tfschema:"managed_resource_group,removedInNextMajorVersion"`
Location string `tfschema:"location"`
Capacity int64 `tfschema:"capacity"`
AutoScaleProfile []AutoScaleProfile `tfschema:"auto_scale_profile"`
Expand Down Expand Up @@ -56,7 +57,7 @@ func (m DeploymentDataSource) Arguments() map[string]*pluginsdk.Schema {
}

func (m DeploymentDataSource) Attributes() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{
dataSource := map[string]*pluginsdk.Schema{
"nginx_version": {
Type: pluginsdk.TypeString,
Computed: true,
Expand All @@ -69,11 +70,6 @@ func (m DeploymentDataSource) Attributes() map[string]*pluginsdk.Schema {
Computed: true,
},

"managed_resource_group": {
Type: pluginsdk.TypeString,
Computed: true,
},

"location": commonschema.LocationComputed(),

"capacity": {
Expand Down Expand Up @@ -196,6 +192,15 @@ func (m DeploymentDataSource) Attributes() map[string]*pluginsdk.Schema {

"tags": commonschema.TagsDataSource(),
}

if !features.FivePointOhBeta() {
dataSource["managed_resource_group"] = &pluginsdk.Schema{
Deprecated: "The `managed_resource_group` field isn't supported by the API anymore and has been deprecated and will be removed in v5.0 of the AzureRM Provider.",
Type: pluginsdk.TypeString,
Computed: true,
}
}
return dataSource
}

func (m DeploymentDataSource) ModelObject() interface{} {
Expand Down Expand Up @@ -245,7 +250,6 @@ func (m DeploymentDataSource) Read() sdk.ResourceFunc {
output.Identity = *flattenedIdentity
if props := model.Properties; props != nil {
output.IpAddress = pointer.ToString(props.IPAddress)
output.ManagedResourceGroup = pointer.ToString(props.ManagedResourceGroup)
output.NginxVersion = pointer.ToString(props.NginxVersion)
output.DiagnoseSupportEnabled = pointer.ToBool(props.EnableDiagnosticsSupport)

Expand Down
25 changes: 13 additions & 12 deletions internal/services/nginx/nginx_deployment_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import (
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/identity"
"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-06-01-preview/nginxdeployment"
"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-09-01-preview/nginxdeployment"
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
Expand Down Expand Up @@ -64,7 +65,7 @@ type DeploymentModel struct {
NginxVersion string `tfschema:"nginx_version"`
Identity []identity.ModelSystemAssignedUserAssigned `tfschema:"identity"`
Sku string `tfschema:"sku"`
ManagedResourceGroup string `tfschema:"managed_resource_group"`
ManagedResourceGroup string `tfschema:"managed_resource_group,removedInNextMajorVersion"`
Location string `tfschema:"location"`
Capacity int64 `tfschema:"capacity"`
AutoScaleProfile []AutoScaleProfile `tfschema:"auto_scale_profile"`
Expand Down Expand Up @@ -107,14 +108,6 @@ func (m DeploymentResource) Arguments() map[string]*pluginsdk.Schema {

"identity": commonschema.SystemAssignedUserAssignedIdentityOptional(),

"managed_resource_group": {
Type: pluginsdk.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"location": commonschema.Location(),

"capacity": {
Expand Down Expand Up @@ -260,6 +253,16 @@ func (m DeploymentResource) Arguments() map[string]*pluginsdk.Schema {
"tags": commonschema.Tags(),
}

if !features.FivePointOhBeta() {
resource["managed_resource_group"] = &pluginsdk.Schema{
Deprecated: "The `managed_resource_group` field isn't supported by the API anymore and has been deprecated and will be removed in v5.0 of the AzureRM Provider.",
Type: pluginsdk.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringIsNotEmpty,
}
}

return resource
}

Expand Down Expand Up @@ -318,7 +321,6 @@ func (m DeploymentResource) Create() sdk.ResourceFunc {
}

prop := &nginxdeployment.NginxDeploymentProperties{}
prop.ManagedResourceGroup = pointer.To(model.ManagedResourceGroup)

if len(model.LoggingStorageAccount) > 0 {
prop.Logging = &nginxdeployment.NginxLogging{
Expand Down Expand Up @@ -457,7 +459,6 @@ func (m DeploymentResource) Read() sdk.ResourceFunc {

if props := model.Properties; props != nil {
output.IpAddress = pointer.ToString(props.IPAddress)
output.ManagedResourceGroup = pointer.ToString(props.ManagedResourceGroup)
output.NginxVersion = pointer.ToString(props.NginxVersion)
output.DiagnoseSupportEnabled = pointer.ToBool(props.EnableDiagnosticsSupport)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"fmt"
"testing"

"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-06-01-preview/nginxdeployment"
"github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2024-09-01-preview/nginxdeployment"
"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
Loading
Loading