terraspace_plugin_azurerm 0.1.0 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/README.md +9 -7
- data/lib/templates/hcl/project/config/terraform/backend.tf +4 -4
- data/lib/templates/ruby/project/config/terraform/backend.rb +2 -2
- data/lib/templates/test/rspec/project/spec/fixtures/config/app.rb +4 -0
- data/lib/templates/test/rspec/project/spec/stacks/demo/main_spec.rb +1 -3
- data/lib/terraspace_plugin_azurerm/clients/options.rb +36 -8
- data/lib/terraspace_plugin_azurerm/clients/storage.rb +5 -3
- data/lib/terraspace_plugin_azurerm/interfaces/expander.rb +2 -1
- data/lib/terraspace_plugin_azurerm/interfaces/layer.rb +1 -5
- data/lib/terraspace_plugin_azurerm/interfaces/summary.rb +1 -1
- data/lib/terraspace_plugin_azurerm/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3164712306e20fe0da2192f6e8168e7d19dc773f840f351f351bd3cd0c56fd76
|
4
|
+
data.tar.gz: 4e3a39f1aacad41a0806f5e9c81013119b58f11dc42b2d0ac791f9e0c4e44814
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 005df536cf5d7b6ed59435e2560bce4924ecc8a0cf4be3a6c2ae294b711c160e435797a62758d476978d3be3914f10336d23c74a681f1b381bc6d820c68dbcae
|
7
|
+
data.tar.gz: 6c3169184cb1b3de048689ab79c9e860c6f9892c5c6ff74eca63db07010d2c6883e8a24d802d6d0d29d4b69d427243631fb66bc990c1e922fdbe9132cd4095cd
|
data/CHANGELOG.md
CHANGED
@@ -3,5 +3,20 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/).
|
5
5
|
|
6
|
+
## [0.2.3]
|
7
|
+
- #4 validate env vars and use older storage client
|
8
|
+
|
9
|
+
## [0.2.2]
|
10
|
+
- #3 fix test template
|
11
|
+
|
12
|
+
## [0.2.1]
|
13
|
+
- set prefix to @folder for performance improvement
|
14
|
+
|
15
|
+
## [0.2.0]
|
16
|
+
- #1 include layer interface, update template to use expansion method, add region method
|
17
|
+
|
18
|
+
## [0.1.1]
|
19
|
+
- update generator init terraform state path
|
20
|
+
|
6
21
|
## [0.1.0]
|
7
22
|
- Initial release
|
data/README.md
CHANGED
@@ -27,7 +27,7 @@ end
|
|
27
27
|
|
28
28
|
By default, this plugin will automatically create the:
|
29
29
|
|
30
|
-
* [resource group](
|
30
|
+
* [resource group](https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/manage-resource-groups-portal)
|
31
31
|
* [storage account](https://docs.microsoft.com/en-us/azure/storage/common/storage-account-create?tabs=azure-portal)
|
32
32
|
* [storage container](https://docs.microsoft.com/en-us/cli/azure/storage/container?view=azure-cli-latest#az-storage-container-create)
|
33
33
|
|
@@ -35,15 +35,17 @@ The settings generally only apply if the resource does not yet exist yet and is
|
|
35
35
|
|
36
36
|
## Environment Variables
|
37
37
|
|
38
|
-
To create the Azure resources like [resource group](
|
38
|
+
To create the Azure resources like [resource group](https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/manage-resource-groups-portal), [storage account](https://docs.microsoft.com/en-us/azure/storage/common/storage-account-create?tabs=azure-portal), and [storage container](https://docs.microsoft.com/en-us/cli/azure/storage/container?view=azure-cli-latest#az-storage-container-create) these environment variables are required:
|
39
39
|
|
40
|
-
|
41
|
-
|
40
|
+
ARM_CLIENT_ID
|
41
|
+
ARM_CLIENT_SECRET
|
42
42
|
|
43
|
-
|
43
|
+
Other env variables can be optionally set:
|
44
44
|
|
45
|
-
|
46
|
-
|
45
|
+
ARM_TENANT_ID
|
46
|
+
ARM_SUBSCRIPTION_ID
|
47
|
+
|
48
|
+
When not set, their values are inferred from the [az cli](https://docs.microsoft.com/en-us/cli/azure/) settings. For those interested, this is done with the [boltops-tools/azure_info](https://github.com/boltops-tools/azure_info) library.
|
47
49
|
|
48
50
|
## Contributing
|
49
51
|
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# SUBSCRIPTION_HASH is a short 4-char consistent hash of the longer subscription id.
|
2
|
-
# This is useful because azure storage
|
2
|
+
# This is useful because azure storage account names are not allowed special characters and are limited to 24 chars.
|
3
3
|
terraform {
|
4
4
|
backend "azurerm" {
|
5
|
-
resource_group_name = "<%=
|
6
|
-
storage_account_name = "<%=
|
5
|
+
resource_group_name = "<%= expansion('terraform-resources-:LOCATION') %>"
|
6
|
+
storage_account_name = "<%= expansion('ts:SUBSCRIPTION_HASH:LOCATION:ENV') %>"
|
7
7
|
container_name = "terraform-state"
|
8
|
-
key = "<%=
|
8
|
+
key = "<%= expansion(':LOCATION/:ENV/:BUILD_DIR/terraform.tfstate') %>"
|
9
9
|
}
|
10
10
|
}
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# SUBSCRIPTION_HASH is a short 4-char consistent hash of the longer subscription id.
|
2
|
-
# This is useful because azure storage
|
2
|
+
# This is useful because azure storage account names are not allowed special characters and are limited to 24 chars.
|
3
3
|
backend("azurerm",
|
4
4
|
resource_group_name: "terraform-resources-:LOCATION",
|
5
5
|
storage_account_name: "ts:SUBSCRIPTION_HASH:LOCATION:ENV",
|
6
6
|
container_name: "terraform-state",
|
7
|
-
key: ":LOCATION/:ENV/:BUILD_DIR.tfstate",
|
7
|
+
key: ":LOCATION/:ENV/:BUILD_DIR/terraform.tfstate",
|
8
8
|
)
|
@@ -8,6 +8,7 @@ describe "main" do
|
|
8
8
|
stacks: "app/stacks", # include all stacks in this folder
|
9
9
|
# override demo stack tfvars for testing
|
10
10
|
# copied over to test harness' app/stacks/demo/tfvars/test.tfvars
|
11
|
+
# need for azure
|
11
12
|
tfvars: {demo: "spec/fixtures/tfvars/demo.tfvars"},
|
12
13
|
config: "spec/fixtures/config",
|
13
14
|
)
|
@@ -18,9 +19,6 @@ describe "main" do
|
|
18
19
|
end
|
19
20
|
|
20
21
|
it "successful deploy" do
|
21
|
-
# Replace with your actual test
|
22
|
-
expect(true).to be true
|
23
|
-
# Example
|
24
22
|
storage_account_id = terraspace.output("demo", "storage_account_id")
|
25
23
|
expect(storage_account_id).to include("sa") # starts with sa
|
26
24
|
end
|
@@ -3,21 +3,49 @@ module TerraspacePluginAzurerm::Clients
|
|
3
3
|
extend Memoist
|
4
4
|
|
5
5
|
def client_options
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
o = base_client_options
|
7
|
+
o[:credentials] = credentials
|
8
|
+
o
|
9
|
+
end
|
10
|
+
|
11
|
+
def credentials
|
12
|
+
o = base_client_options
|
13
|
+
provider = MsRestAzure::ApplicationTokenProvider.new(o[:tenant_id], o[:client_id], o[:client_secret])
|
14
|
+
MsRest::TokenCredentials.new(provider)
|
15
|
+
end
|
10
16
|
|
11
|
-
|
12
|
-
|
17
|
+
def base_client_options
|
18
|
+
# AZURE_* is used by ruby generally.
|
19
|
+
# ARM_* is used by Terraform azurerm provider: https://www.terraform.io/docs/providers/azurerm/index.html
|
20
|
+
# Favor ARM_ because this plugin is designed for Terraspace.
|
21
|
+
client_id = ENV['ARM_CLIENT_ID'] || ENV['AZURE_CLIENT_ID']
|
22
|
+
client_secret = ENV['ARM_CLIENT_SECRET'] || ENV['AZURE_CLIENT_SECRET']
|
23
|
+
subscription_id = ENV['ARM_SUBSCRIPTION_ID'] || ENV['AZURE_SUBSCRIPTION_ID'] || AzureInfo.subscription_id
|
24
|
+
tenant_id = ENV['ARM_TENANT_ID'] || ENV['AZURE_TENANT_ID'] || AzureInfo.tenant_id
|
13
25
|
|
14
|
-
{
|
26
|
+
o = {
|
15
27
|
tenant_id: tenant_id,
|
16
28
|
client_id: client_id,
|
17
29
|
client_secret: client_secret,
|
18
30
|
subscription_id: subscription_id,
|
19
|
-
credentials: credentials
|
20
31
|
}
|
32
|
+
validate_base_options!(o)
|
33
|
+
o
|
34
|
+
end
|
35
|
+
memoize :base_client_options
|
36
|
+
|
37
|
+
def validate_base_options!(options)
|
38
|
+
vars = []
|
39
|
+
options.each do |k,v|
|
40
|
+
vars << "ARM_#{k}".upcase if v.nil?
|
41
|
+
end
|
42
|
+
return if vars.empty?
|
43
|
+
|
44
|
+
logger.error "ERROR: Required Azure env variables missing. Please set these env variables:".color(:red)
|
45
|
+
vars.each do |var|
|
46
|
+
logger.error " #{var}"
|
47
|
+
end
|
48
|
+
exit 1
|
21
49
|
end
|
22
50
|
end
|
23
51
|
end
|
@@ -6,8 +6,8 @@ module TerraspacePluginAzurerm::Clients
|
|
6
6
|
extend Memoist
|
7
7
|
|
8
8
|
# Include SDK modules to ease access to Storage classes.
|
9
|
-
include Azure::Storage::
|
10
|
-
include Azure::Storage::
|
9
|
+
include Azure::Storage::Mgmt::V2019_06_01
|
10
|
+
include Azure::Storage::Mgmt::V2019_06_01::Models
|
11
11
|
|
12
12
|
def storage_accounts
|
13
13
|
mgmt.storage_accounts
|
@@ -19,7 +19,9 @@ module TerraspacePluginAzurerm::Clients
|
|
19
19
|
memoize :blob_containers
|
20
20
|
|
21
21
|
def mgmt
|
22
|
-
|
22
|
+
client = StorageManagementClient.new(credentials)
|
23
|
+
client.subscription_id = client_options[:subscription_id]
|
24
|
+
client
|
23
25
|
end
|
24
26
|
memoize :mgmt
|
25
27
|
end
|
@@ -16,13 +16,14 @@ module TerraspacePluginAzurerm::Interfaces
|
|
16
16
|
|
17
17
|
delegate :subscription_id, :subscription, :tenant_id, :tenant_id, :group, :location, to: :azure_info
|
18
18
|
alias_method :namespace, :subscription
|
19
|
+
alias_method :region, :location
|
19
20
|
|
20
21
|
def azure_info
|
21
22
|
AzureInfo
|
22
23
|
end
|
23
24
|
|
24
25
|
# subscription_hash is a short 4-char consistent hash of the longer subscription id.
|
25
|
-
# This is useful because azure storage
|
26
|
+
# This is useful because azure storage account names are not allowed special characters and are limited to 24 chars.
|
26
27
|
# NOTE: be careful to not change this! or else state path will change
|
27
28
|
def subscription_hash
|
28
29
|
Digest::SHA1.hexdigest(subscription)[0..3]
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module TerraspacePluginAzurerm::Interfaces
|
2
2
|
class Layer
|
3
3
|
extend Memoist
|
4
|
+
include Terraspace::Plugin::Layer::Interface
|
4
5
|
|
5
6
|
# interface method
|
6
7
|
def namespace
|
@@ -11,10 +12,5 @@ module TerraspacePluginAzurerm::Interfaces
|
|
11
12
|
def region
|
12
13
|
AzureInfo.location
|
13
14
|
end
|
14
|
-
|
15
|
-
# interface method
|
16
|
-
def provider
|
17
|
-
"azurerm"
|
18
|
-
end
|
19
15
|
end
|
20
16
|
end
|
@@ -53,7 +53,7 @@ module TerraspacePluginAzurerm::Interfaces
|
|
53
53
|
|
54
54
|
# Friendly error handling for user
|
55
55
|
def list_blobs(container_name, marker:)
|
56
|
-
blob_client.list_blobs(container_name, marker: marker)
|
56
|
+
blob_client.list_blobs(container_name, marker: marker, prefix: @folder)
|
57
57
|
rescue Azure::Core::Http::HTTPError => e
|
58
58
|
if e.message.include?("AuthenticationFailed")
|
59
59
|
logger.error "e.class #{e.class}: #{e.message}"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: terraspace_plugin_azurerm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tung Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: azure-storage-blob
|
@@ -134,6 +134,7 @@ files:
|
|
134
134
|
- lib/templates/test/rspec/module/test/spec/fixtures/stack/variables.tf
|
135
135
|
- lib/templates/test/rspec/module/test/spec/main_spec.rb.tt
|
136
136
|
- lib/templates/test/rspec/module/test/spec/spec_helper.rb
|
137
|
+
- lib/templates/test/rspec/project/spec/fixtures/config/app.rb
|
137
138
|
- lib/templates/test/rspec/project/spec/fixtures/config/terraform/provider.tf
|
138
139
|
- lib/templates/test/rspec/project/spec/fixtures/tfvars/demo.tfvars
|
139
140
|
- lib/templates/test/rspec/project/spec/spec_helper.rb
|