|
| 1 | +terraform { |
| 2 | + required_providers { |
| 3 | + azapi = { |
| 4 | + source = "Azure/azapi" |
| 5 | + } |
| 6 | + } |
| 7 | +} |
| 8 | + |
| 9 | +provider "azapi" { |
| 10 | +} |
| 11 | + |
| 12 | +provider "azurerm" { |
| 13 | + features {} |
| 14 | +} |
| 15 | + |
| 16 | +resource "azurerm_resource_group" "example" { |
| 17 | + name = "example-rg" |
| 18 | + location = "west europe" |
| 19 | + tags = local.terratag_added_main |
| 20 | +} |
| 21 | + |
| 22 | +resource "azurerm_user_assigned_identity" "example" { |
| 23 | + name = "example" |
| 24 | + resource_group_name = azurerm_resource_group.example.name |
| 25 | + location = azurerm_resource_group.example.location |
| 26 | + tags = local.terratag_added_main |
| 27 | +} |
| 28 | + |
| 29 | +resource "azapi_resource" "example" { |
| 30 | + type = "Microsoft.ContainerRegistry/registries@2020-11-01-preview" |
| 31 | + name = "registry1" |
| 32 | + parent_id = azurerm_resource_group.example.id |
| 33 | + |
| 34 | + location = azurerm_resource_group.example.location |
| 35 | + identity { |
| 36 | + type = "SystemAssigned, UserAssigned" |
| 37 | + identity_ids = [azurerm_user_assigned_identity.example.id] |
| 38 | + } |
| 39 | + |
| 40 | + body = { |
| 41 | + sku = { |
| 42 | + name = "Standard" |
| 43 | + } |
| 44 | + properties = { |
| 45 | + adminUserEnabled = true |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + tags = merge({ |
| 50 | + "Key" = "Value" |
| 51 | + }, local.terratag_added_main) |
| 52 | + |
| 53 | + response_export_values = ["properties.loginServer", "properties.policies.quarantinePolicy.status"] |
| 54 | +} |
| 55 | + |
| 56 | +resource "azapi_resource" "example2" { |
| 57 | + type = "Microsoft.ContainerRegistry/registries@2020-11-01-preview" |
| 58 | + name = "registry2" |
| 59 | + parent_id = azurerm_resource_group.example.id |
| 60 | + |
| 61 | + location = azurerm_resource_group.example.location |
| 62 | + identity { |
| 63 | + type = "SystemAssigned, UserAssigned" |
| 64 | + identity_ids = [azurerm_user_assigned_identity.example.id] |
| 65 | + } |
| 66 | + |
| 67 | + body = { |
| 68 | + sku = { |
| 69 | + name = "Standard" |
| 70 | + } |
| 71 | + properties = { |
| 72 | + adminUserEnabled = true |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + response_export_values = ["properties.loginServer", "properties.policies.quarantinePolicy.status"] |
| 77 | + tags = local.terratag_added_main |
| 78 | +} |
| 79 | + |
| 80 | +data "azurerm_synapse_workspace" "example" { |
| 81 | + name = "example-workspace" |
| 82 | + resource_group_name = azurerm_resource_group.example.name |
| 83 | +} |
| 84 | + |
| 85 | +resource "azapi_data_plane_resource" "dataset" { |
| 86 | + type = "Microsoft.Synapse/workspaces/datasets@2020-12-01" |
| 87 | + parent_id = trimprefix(data.azurerm_synapse_workspace.example.connectivity_endpoints.dev, "https://") |
| 88 | + name = "example-dataset" |
| 89 | + body = { |
| 90 | + properties = { |
| 91 | + type = "AzureBlob", |
| 92 | + typeProperties = { |
| 93 | + folderPath = { |
| 94 | + value = "@dataset().MyFolderPath" |
| 95 | + type = "Expression" |
| 96 | + } |
| 97 | + fileName = { |
| 98 | + value = "@dataset().MyFileName" |
| 99 | + type = "Expression" |
| 100 | + } |
| 101 | + format = { |
| 102 | + type = "TextFormat" |
| 103 | + } |
| 104 | + } |
| 105 | + parameters = { |
| 106 | + MyFolderPath = { |
| 107 | + type = "String" |
| 108 | + } |
| 109 | + MyFileName = { |
| 110 | + type = "String" |
| 111 | + } |
| 112 | + } |
| 113 | + } |
| 114 | + } |
| 115 | +} |
| 116 | + |
| 117 | +variable "enabled" { |
| 118 | + type = bool |
| 119 | + default = false |
| 120 | + description = "whether start the spring service" |
| 121 | +} |
| 122 | + |
| 123 | +resource "azurerm_spring_cloud_service" "test" { |
| 124 | + name = "example-spring" |
| 125 | + resource_group_name = azurerm_resource_group.example.name |
| 126 | + location = azurerm_resource_group.example.location |
| 127 | + sku_name = "S0" |
| 128 | + tags = local.terratag_added_main |
| 129 | +} |
| 130 | + |
| 131 | +resource "azapi_resource_action" "start" { |
| 132 | + type = "Microsoft.AppPlatform/Spring@2022-05-01-preview" |
| 133 | + resource_id = azurerm_spring_cloud_service.test.id |
| 134 | + action = "start" |
| 135 | + response_export_values = ["*"] |
| 136 | + |
| 137 | + count = var.enabled ? 1 : 0 |
| 138 | +} |
| 139 | + |
| 140 | +resource "azapi_resource_action" "stop" { |
| 141 | + type = "Microsoft.AppPlatform/Spring@2022-05-01-preview" |
| 142 | + resource_id = azurerm_spring_cloud_service.test.id |
| 143 | + action = "stop" |
| 144 | + response_export_values = ["*"] |
| 145 | + |
| 146 | + count = var.enabled ? 0 : 1 |
| 147 | +} |
| 148 | + |
| 149 | +resource "azurerm_public_ip" "example" { |
| 150 | + name = "example-ip" |
| 151 | + location = azurerm_resource_group.example.location |
| 152 | + resource_group_name = azurerm_resource_group.example.name |
| 153 | + allocation_method = "Static" |
| 154 | + tags = local.terratag_added_main |
| 155 | +} |
| 156 | + |
| 157 | +resource "azurerm_lb" "example" { |
| 158 | + name = "example-lb" |
| 159 | + location = azurerm_resource_group.example.location |
| 160 | + resource_group_name = azurerm_resource_group.example.name |
| 161 | + |
| 162 | + frontend_ip_configuration { |
| 163 | + name = "PublicIPAddress" |
| 164 | + public_ip_address_id = azurerm_public_ip.example.id |
| 165 | + } |
| 166 | + tags = local.terratag_added_main |
| 167 | +} |
| 168 | + |
| 169 | +resource "azurerm_lb_nat_rule" "example" { |
| 170 | + resource_group_name = azurerm_resource_group.example.name |
| 171 | + loadbalancer_id = azurerm_lb.example.id |
| 172 | + name = "RDPAccess" |
| 173 | + protocol = "Tcp" |
| 174 | + frontend_port = 3389 |
| 175 | + backend_port = 3389 |
| 176 | + frontend_ip_configuration_name = "PublicIPAddress" |
| 177 | +} |
| 178 | + |
| 179 | +resource "azapi_update_resource" "example" { |
| 180 | + type = "Microsoft.Network/loadBalancers@2021-03-01" |
| 181 | + resource_id = azurerm_lb.example.id |
| 182 | + |
| 183 | + body = { |
| 184 | + properties = { |
| 185 | + inboundNatRules = [ |
| 186 | + { |
| 187 | + properties = { |
| 188 | + idleTimeoutInMinutes = 15 |
| 189 | + } |
| 190 | + } |
| 191 | + ] |
| 192 | + } |
| 193 | + } |
| 194 | + |
| 195 | + depends_on = [ |
| 196 | + azurerm_lb_nat_rule.example, |
| 197 | + ] |
| 198 | +} |
| 199 | +locals { |
| 200 | + terratag_added_main = {"env0_environment_id"="40907eff-cf7c-419a-8694-e1c6bf1d1168","env0_project_id"="43fd4ff1-8d37-4d9d-ac97-295bd850bf94"} |
| 201 | +} |
| 202 | + |
0 commit comments