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

Updated API version of container_group from 2021-03-01 to 2021-10-01 #17785

Merged
merged 6 commits into from
Oct 21, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,11 @@ resource "azurerm_subnet" "example" {
}
}

resource "azurerm_network_profile" "example" {
name = "${var.prefix}networkprofile"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name

container_network_interface {
name = "hellocnic"

ip_configuration {
name = "helloipconfig"
subnet_id = azurerm_subnet.example.id
}
}
}

resource "azurerm_container_group" "example" {
name = "${var.prefix}continst"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
ip_address_type = "Private"
network_profile_id = azurerm_network_profile.example.id
os_type = "Linux"
restart_policy = "Never"

Expand All @@ -73,6 +57,8 @@ resource "azurerm_container_group" "example" {
memory = "1.5"
}

subnet_ids = [azurerm_subnet.example.id]

tags = {
environment = "testing"
}
Expand Down
2 changes: 1 addition & 1 deletion internal/services/containers/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/Azure/azure-sdk-for-go/services/preview/containerregistry/mgmt/2021-08-01-preview/containerregistry"
"github.com/Azure/azure-sdk-for-go/services/preview/containerservice/mgmt/2022-03-02-preview/containerservice"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerinstance/2021-03-01/containerinstance"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerinstance/2021-10-01/containerinstance"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
)

Expand Down
35 changes: 34 additions & 1 deletion internal/services/containers/container_group_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ 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-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerinstance/2021-03-01/containerinstance"
"github.com/hashicorp/go-azure-helpers/resourcemanager/zones"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerinstance/2021-10-01/containerinstance"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
Expand All @@ -34,6 +36,8 @@ func dataSourceContainerGroup() *pluginsdk.Resource {

"location": commonschema.LocationComputed(),

"identity": commonschema.SystemAssignedUserAssignedIdentityComputed(),

"ip_address": {
Type: pluginsdk.TypeString,
Computed: true,
Expand All @@ -44,6 +48,17 @@ func dataSourceContainerGroup() *pluginsdk.Resource {
Computed: true,
},

"subnet_ids": {
Type: pluginsdk.TypeSet,
Computed: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
},
Set: pluginsdk.HashString,
},

"zones": commonschema.ZonesMultipleOptionalForceNew(),

"tags": commonschema.TagsDataSource(),
},
}
Expand Down Expand Up @@ -72,6 +87,8 @@ func dataSourceContainerGroupRead(d *pluginsdk.ResourceData, meta interface{}) e

if model := resp.Model; model != nil {
d.Set("location", location.NormalizeNilable(model.Location))
d.Set("zones", zones.Flatten(model.Zones))

if err := tags.FlattenAndSet(d, model.Tags); err != nil {
return err
}
Expand All @@ -80,6 +97,22 @@ func dataSourceContainerGroupRead(d *pluginsdk.ResourceData, meta interface{}) e
d.Set("ip_address", address.IP)
d.Set("fqdn", address.Fqdn)
}

flattenedIdentity, err := identity.FlattenSystemAndUserAssignedMap(model.Identity)
if err != nil {
return fmt.Errorf("flattening `identity`: %+v", err)
}
if err := d.Set("identity", flattenedIdentity); err != nil {
return fmt.Errorf("setting `identity`: %+v", err)
}

subnets, err := flattenContainerGroupSubnets(props.SubnetIds)
if err != nil {
return err
}
if err := d.Set("subnet_ids", subnets); err != nil {
return fmt.Errorf("setting `subnet_ids`: %+v", err)
}
}

return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ func TestAccDataSourceContainerGroup_complete(t *testing.T) {
})
}

func TestAccDataSourceContainerGroup_UAMIWithSubnet(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azurerm_container_group", "test")
r := ContainerGroupDataSource{}

data.DataSourceTest(t, []acceptance.TestStep{
{
Config: r.uamiWithSubnet(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).Key("name").Exists(),
check.That(data.ResourceName).Key("resource_group_name").Exists(),
check.That(data.ResourceName).Key("identity.0.identity_ids.#").HasValue("1"),
check.That(data.ResourceName).Key("subnet_ids.#").HasValue("1"),
),
},
})
}

func (ContainerGroupDataSource) complete(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
Expand All @@ -38,3 +55,14 @@ data "azurerm_container_group" "test" {
}
`, ContainerGroupResource{}.linuxComplete(data))
}

func (ContainerGroupDataSource) uamiWithSubnet(data acceptance.TestData) string {
return fmt.Sprintf(`
%s

data "azurerm_container_group" "test" {
name = azurerm_container_group.test.name
resource_group_name = azurerm_container_group.test.resource_group_name
}
`, ContainerGroupResource{}.UserAssignedIdentityWithVirtualNetwork(data))
}
Loading