forked from hashicorp/terraform-provider-azurerm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Resource:
azurerm_site_recovery_vmware_replicated_vm
(hashicorp…
…#22477) * New Resource: `azurerm_site_recovery_vmware_replicated_vm` Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> * update test case Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> * update `physical_server_credential_name` Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> * refresh /vendor Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> * website typo Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> * golint Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> * update per comments Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> * add comments Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> * replace `utils.String` to `pointer.To` Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> * schema lint Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> * update test case Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> * refresh vendor Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> * update code Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com> * refresh vendor * update per comment --------- Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com>
- Loading branch information
Showing
46 changed files
with
3,016 additions
and
0 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
internal/services/recoveryservices/azuresdkhacks/method_getallmachinesinsite.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package azuresdkhacks | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"net/url" | ||
|
||
"github.com/hashicorp/go-azure-helpers/lang/pointer" | ||
vmwaremachines "github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/machines" | ||
"github.com/hashicorp/go-azure-sdk/sdk/client" | ||
"github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" | ||
) | ||
|
||
// workaround for https://github.com/hashicorp/go-azure-sdk/issues/492 | ||
// TODO4.0: check if this could be removed. | ||
// the method has been re-written to read `nextLink` | ||
|
||
type MachinesClient struct { | ||
Client *resourcemanager.Client | ||
} | ||
|
||
type Values struct { | ||
Values *[]vmwaremachines.VMwareMachine `json:"value"` | ||
NextLink *string `json:"nextLink"` | ||
} | ||
|
||
func (c MachinesClient) GetAllVMWareMachinesInSite(ctx context.Context, id vmwaremachines.VMwareSiteId, options vmwaremachines.GetAllMachinesInSiteOperationOptions) (result vmwaremachines.GetAllMachinesInSiteOperationResponse, err error) { | ||
opts := client.RequestOptions{ | ||
ContentType: "application/json", | ||
ExpectedStatusCodes: []int{ | ||
http.StatusOK, | ||
}, | ||
HttpMethod: http.MethodGet, | ||
Path: fmt.Sprintf("%s/machines", id.ID()), | ||
OptionsObject: options, | ||
} | ||
|
||
req, err := c.Client.NewRequest(ctx, opts) | ||
if err != nil { | ||
return | ||
} | ||
|
||
return wrapExecutePaged(ctx, req) | ||
} | ||
|
||
func wrapExecutePaged(ctx context.Context, req *client.Request) (result vmwaremachines.GetAllMachinesInSiteOperationResponse, err error) { | ||
resp, err := req.ExecutePaged(ctx) | ||
if resp != nil { | ||
result.OData = resp.OData | ||
result.HttpResponse = resp.Response | ||
} | ||
if err != nil { | ||
return | ||
} | ||
|
||
var values Values | ||
|
||
if err = resp.Unmarshal(&values); err != nil { | ||
return | ||
} | ||
result.Model = values.Values | ||
|
||
if values.NextLink != nil { | ||
nextReq := req | ||
u, err := url.Parse(*values.NextLink) | ||
if err != nil { | ||
return result, err | ||
} | ||
nextReq.URL = u | ||
nextResp, err := wrapExecutePaged(ctx, nextReq) | ||
if err != nil { | ||
return result, err | ||
} | ||
if nextResp.Model != nil { | ||
result.Model = pointer.To(append(*result.Model, *nextResp.Model...)) | ||
} | ||
} | ||
|
||
return | ||
} |
84 changes: 84 additions & 0 deletions
84
internal/services/recoveryservices/azuresdkhacks/method_getallrunasaccountsinsite.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package azuresdkhacks | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts" | ||
"github.com/hashicorp/go-azure-sdk/sdk/client" | ||
"github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" | ||
"github.com/hashicorp/go-azure-sdk/sdk/odata" | ||
) | ||
|
||
// workaround for https://github.com/Azure/azure-rest-api-specs/issues/24712 | ||
// the difference is in the struct `RunAsAccountProperties` | ||
// TODO 4.0: check if this could be removed | ||
|
||
type RunAsAccountsClient struct { | ||
Client *resourcemanager.Client | ||
} | ||
|
||
type GetAllRunAsAccountsInSiteOperationResponse struct { | ||
HttpResponse *http.Response | ||
OData *odata.OData | ||
Model *[]VMwareRunAsAccount | ||
} | ||
|
||
type GetAllRunAsAccountsInSiteCompleteResult struct { | ||
Items []VMwareRunAsAccount | ||
} | ||
|
||
// GetAllRunAsAccountsInSite ... | ||
func (c RunAsAccountsClient) GetAllRunAsAccountsInSite(ctx context.Context, id runasaccounts.VMwareSiteId) (result GetAllRunAsAccountsInSiteOperationResponse, err error) { | ||
opts := client.RequestOptions{ | ||
ContentType: "application/json", | ||
ExpectedStatusCodes: []int{ | ||
http.StatusOK, | ||
}, | ||
HttpMethod: http.MethodGet, | ||
Path: fmt.Sprintf("%s/runAsAccounts", id.ID()), | ||
} | ||
|
||
req, err := c.Client.NewRequest(ctx, opts) | ||
if err != nil { | ||
return | ||
} | ||
|
||
var resp *client.Response | ||
resp, err = req.ExecutePaged(ctx) | ||
if resp != nil { | ||
result.OData = resp.OData | ||
result.HttpResponse = resp.Response | ||
} | ||
if err != nil { | ||
return | ||
} | ||
|
||
var values struct { | ||
Values *[]VMwareRunAsAccount `json:"value"` | ||
} | ||
if err = resp.Unmarshal(&values); err != nil { | ||
return | ||
} | ||
|
||
result.Model = values.Values | ||
|
||
return | ||
} | ||
|
||
// GetAllRunAsAccountsInSiteComplete retrieves all the results into a single object | ||
func (c RunAsAccountsClient) GetAllRunAsAccountsInSiteComplete(ctx context.Context, id runasaccounts.VMwareSiteId) (GetAllRunAsAccountsInSiteCompleteResult, error) { | ||
items := make([]VMwareRunAsAccount, 0) | ||
|
||
resp, err := c.GetAllRunAsAccountsInSite(ctx, id) | ||
if err != nil { | ||
err = fmt.Errorf("loading results: %+v", err) | ||
return GetAllRunAsAccountsInSiteCompleteResult{}, err | ||
} | ||
if resp.Model != nil { | ||
items = append(items, *resp.Model...) | ||
} | ||
|
||
return GetAllRunAsAccountsInSiteCompleteResult{Items: items}, nil | ||
} |
19 changes: 19 additions & 0 deletions
19
internal/services/recoveryservices/azuresdkhacks/model_vmwarerunasaccount.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package azuresdkhacks | ||
|
||
import "github.com/hashicorp/go-azure-sdk/resource-manager/migrate/2020-01-01/runasaccounts" | ||
|
||
type VMwareRunAsAccount struct { | ||
Id *string `json:"id,omitempty"` | ||
Name *string `json:"name,omitempty"` | ||
Properties *RunAsAccountProperties `json:"properties,omitempty"` | ||
Type *string `json:"type,omitempty"` | ||
} | ||
|
||
type RunAsAccountProperties struct { | ||
CreatedTimestamp *string `json:"createdTimestamp,omitempty"` | ||
CredentialType *runasaccounts.CredentialType `json:"credentialType,omitempty"` | ||
DisplayName *string `json:"displayName,omitempty"` | ||
UpdatedTimestamp *string `json:"updatedTimestamp,omitempty"` | ||
// ApplianceName was not defined in the original code. This is the only change. | ||
ApplianceName *string `json:"applianceName,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.