Skip to content

Commit

Permalink
azurerm: add azurerm_backup_policy_vm_workload resource (#386)
Browse files Browse the repository at this point in the history
Co-authored-by: marcoldp <[email protected]>
  • Loading branch information
xescugc and marcoldp authored May 17, 2023
1 parent c735594 commit a2e5057
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 77 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
([Issue #358](https://github.com/cycloidio/terracognita/issues/358))
- Added new Azure resource: `azurerm_api_management`
([PR#363](https://github.com/cycloidio/terracognita/pull/363))
- Added new Azure resource: `azurerm_backup_policy_vm_workload`
([PR#386](https://github.com/cycloidio/terracognita/pull/386))

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,4 @@ clean: ## Removes binary and/or docker image

.PHONY: update-terraform-provider
update-terraform-provider: ## Update terraform-provider version used for AWS, Azure, GCP
./scripts/terraform-provider-update/update.sh $(PROVIDER)
./scripts/terraform-provider-update/update.sh $(PROVIDER) $(VERSION)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Please see the following versions as follow:

Providers:
* AWS: v4.9.0
* AzureRM: v3.6.0
* AzureRM: v3.20.0
* Google: v4.9.0
* vSphere: v2.2.0

Expand Down
27 changes: 25 additions & 2 deletions azurerm/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ const (
//Recovery Services - backup
BackupPolicyVM
BackupProtectedVM
BackupPolicyVMWorkload
)

type rtFn func(ctx context.Context, a *azurerm, ar *AzureReader, resourceType string, filters *filter.Filter) ([]provider.Resource, error)
Expand Down Expand Up @@ -348,8 +349,9 @@ var (
// Recovery Services
RecoveryServicesVault: recoveryServicesVaults,
//Recovery Services - backup
BackupPolicyVM: backupPolicyVMs,
BackupProtectedVM: backupProtectedVMs,
BackupPolicyVM: backupPolicyVMs,
BackupProtectedVM: backupProtectedVMs,
BackupPolicyVMWorkload: backupPolicyVMWorkloads,
}
)

Expand Down Expand Up @@ -2818,3 +2820,24 @@ func backupProtectedVMs(ctx context.Context, a *azurerm, ar *AzureReader, resour
}
return resources, nil
}

func backupPolicyVMWorkloads(ctx context.Context, a *azurerm, ar *AzureReader, resourceType string, filters *filter.Filter) ([]provider.Resource, error) {
vaultNames, err := getRecoveryServicesVaults(ctx, a, ar, RecoveryServicesVault.String(), filters)
if err != nil {
return nil, errors.Wrap(err, "unable to list recovery services vaults from cache")
}
resources := make([]provider.Resource, 0)
for _, vaultName := range vaultNames {
backupPolicies, err := ar.ListBackupPolicies(ctx, vaultName, "")
if err != nil {
return nil, errors.Wrap(err, "unable to list backup instance resources from reader")
}
for _, backupPolicy := range backupPolicies {
if _, ok := backupPolicy.Properties.AsAzureVMWorkloadProtectionPolicy(); ok {
r := provider.NewResource(*backupPolicy.ID, resourceType, a)
resources = append(resources, r)
}
}
}
return resources, nil
}
12 changes: 8 additions & 4 deletions azurerm/resourcetype_enumer.go

Large diffs are not rendered by default.

53 changes: 27 additions & 26 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ module github.com/cycloidio/terracognita
go 1.17

require (
github.com/Azure/azure-sdk-for-go v64.0.0+incompatible
github.com/Azure/go-autorest/autorest v0.11.26
github.com/Azure/azure-sdk-for-go v65.0.0+incompatible
github.com/Azure/go-autorest/autorest v0.11.27
github.com/adrg/xdg v0.2.3
github.com/aws/aws-sdk-go v1.43.34
github.com/chr4/pwgen v1.1.0
github.com/cycloidio/mxwriter v1.0.4
github.com/cycloidio/tfdocs v0.0.0-20220809201117-e73e2388cfa8
github.com/cycloidio/tfdocs v0.0.0-20230516095646-1dc8f8412d50
github.com/gertd/go-pluralize v0.1.7
github.com/go-kit/kit v0.9.0
github.com/golang/mock v1.6.0
github.com/hashicorp/go-azure-helpers v0.30.0
github.com/hashicorp/go-azure-helpers v0.40.0
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/hcl/v2 v2.11.1
github.com/hashicorp/hcl/v2 v2.13.0
github.com/hashicorp/terraform v0.13.0
github.com/hashicorp/terraform-plugin-go v0.9.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.14.0
github.com/hashicorp/terraform-plugin-go v0.10.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.18.0
github.com/hashicorp/terraform-provider-aws v1.60.1-0.20210513231836-489654890359
github.com/hashicorp/terraform-provider-azurerm v1.44.1-0.20201029183808-d721bcc1bb55
github.com/hashicorp/terraform-provider-google v1.20.1-0.20210510171431-a764cf3da527
Expand All @@ -28,12 +28,12 @@ require (
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.1.3
github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.7.0
github.com/stretchr/testify v1.7.2
github.com/vmware/govmomi v0.28.0
github.com/zclconf/go-cty v1.10.0
golang.org/x/text v0.7.0
google.golang.org/api v0.61.0
google.golang.org/grpc v1.45.0
google.golang.org/grpc v1.47.0
gopkg.in/yaml.v2 v2.4.0
)

Expand Down Expand Up @@ -81,10 +81,10 @@ require (
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dimchansky/utfbom v1.1.1 // indirect
github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021 // indirect
github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1 // indirect
github.com/envoyproxy/protoc-gen-validate v0.1.0 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/fatih/color v1.12.0 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/gammazero/deque v0.0.0-20180920172122-f6adf94963e4 // indirect
github.com/gammazero/workerpool v0.0.0-20181230203049-86a96b5d5d92 // indirect
Expand All @@ -95,7 +95,7 @@ require (
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.3 // indirect
github.com/google/go-cmp v0.5.7 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/gax-go/v2 v2.1.1 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
Expand All @@ -104,23 +104,24 @@ require (
github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2 v2.0.0-beta.15 // indirect
github.com/hashicorp/awspolicyequivalence v1.5.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-azure-sdk v0.20220824.1090858 // indirect
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-getter v1.5.11 // indirect
github.com/hashicorp/go-hclog v1.2.0 // indirect
github.com/hashicorp/go-hclog v1.2.1 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-plugin v1.4.3 // indirect
github.com/hashicorp/go-plugin v1.4.4 // indirect
github.com/hashicorp/go-retryablehttp v0.7.0 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/go-version v1.4.0 // indirect
github.com/hashicorp/hc-install v0.3.1 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/hc-install v0.4.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/logutils v1.0.0 // indirect
github.com/hashicorp/terraform-exec v0.16.1 // indirect
github.com/hashicorp/terraform-json v0.13.0 // indirect
github.com/hashicorp/terraform-plugin-log v0.3.0 // indirect
github.com/hashicorp/terraform-registry-address v0.0.0-20210412075316-9b2996cce896 // indirect
github.com/hashicorp/terraform-exec v0.17.2 // indirect
github.com/hashicorp/terraform-json v0.14.0 // indirect
github.com/hashicorp/terraform-plugin-log v0.4.1 // indirect
github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c // indirect
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 // indirect
github.com/hashicorp/yamux v0.0.0-20210316155119-a95892c5f864 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
Expand All @@ -132,14 +133,14 @@ require (
github.com/manicminer/hamilton v0.44.0 // indirect
github.com/manicminer/hamilton-autorest v0.2.0 // indirect
github.com/mattbaird/jsonpatch v0.0.0-20200820163806-098863c1fc24 // indirect
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mattn/go-isatty v0.0.13 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/mitchellh/hashstructure v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/oklog/run v1.1.0 // indirect
Expand All @@ -163,7 +164,7 @@ require (
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
go.opencensus.io v0.23.0 // indirect
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
golang.org/x/crypto v0.0.0-20220517005047-85d78b3ac167 // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
Expand All @@ -173,7 +174,7 @@ require (
google.golang.org/genproto v0.0.0-20211118181313-81c1377c94b1 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/ini.v1 v1.66.2 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

// Force an specific version if not the AWS provider does not compile
Expand All @@ -184,7 +185,7 @@ replace github.com/hashicorp/aws-sdk-go-base v0.6.0 => github.com/hashicorp/aws-
replace github.com/hashicorp/go-getter v1.5.0 => github.com/hashicorp/go-getter v1.4.0

// Fork of Azurerm that has the V2 of the SDK
replace github.com/hashicorp/terraform-provider-azurerm => github.com/cycloidio/terraform-provider-azurerm v1.44.1-0.20220513132617-918497152827
replace github.com/hashicorp/terraform-provider-azurerm => github.com/cycloidio/terraform-provider-azurerm v1.44.1-0.20230517144901-90a36c6b8ed4

replace github.com/hashicorp/terraform-provider-aws => github.com/cycloidio/terraform-provider-aws v1.60.1-0.20220513132327-e2dbdf90e533

Expand Down
Loading

0 comments on commit a2e5057

Please sign in to comment.