Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
  • Loading branch information
sinbai committed Apr 13, 2023
1 parent fe840f7 commit c2b33df
Showing 5 changed files with 260 additions and 128 deletions.
54 changes: 54 additions & 0 deletions internal/services/storagemover/scripts/install_arc.sh.tftpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

# Disable the Azure VM Guest Agent.
current_hostname=$(hostname)
sudo service walinuxagent stop
sudo waagent -deprovision -force
sudo rm -rf /var/lib/waagent
sudo hostnamectl set-hostname $current_hostname

# Block access to the Azure IMDS endpoint.
sudo ufw --force enable
sudo ufw deny out from any to 169.254.169.254
sudo ufw default allow incoming

# Add the service principal application ID and secret here
servicePrincipalClientId="${client_id}"
servicePrincipalSecret="${client_secret}"
cloud="AzureCloud"
tenantId="${tenant_id}"
subscriptionId="${subscription_id}"
resourceGroup="${resource_group_name}"
location="${location}"
authType="principal"
correlationId="${uuid}"
output="$(wget https://aka.ms/azcmagent -O ~/install_linux_azcmagent.sh 2>&1)"
if [ $? != 0 ]; then
read -d '' bodyData <<EOF
{
"operation": "onboarding",
"messageType": "DownloadScriptFailed",
"tenantId": "$tenantId",
"subscriptionId": "$subscriptionId",
"resourceGroup": "$resourceGroup",
"location": "$location",
"correlationId": "$correlationId",
"authType": "$authType",
"message": "$output"
}
EOF
wget -qO- --method=PUT --body-data="$bodyData" "https://gbl.his.arc.azure.com/log" &> /dev/null || true
fi
echo "$output"
sudo chmod +x ~/install_linux_azcmagent.sh
cd ~
./install_linux_azcmagent.sh
sudo azcmagent connect \
--service-principal-id "$servicePrincipalClientId" \
--service-principal-secret "$servicePrincipalSecret" \
--cloud "$cloud" \
--tenant-id "$tenantId" \
--subscription-id "$subscriptionId" \
--resource-group "$resourceGroup" \
--location "$location" \
--correlation-id "$correlationId"
36 changes: 15 additions & 21 deletions internal/services/storagemover/storage_mover_agent_resource.go
Original file line number Diff line number Diff line change
@@ -15,11 +15,11 @@ import (
)

type StorageMoverAgentResourceModel struct {
Name string `tfschema:"name"`
StorageMoverId string `tfschema:"storage_mover_id"`
ArcResourceId string `tfschema:"arc_resource_id"`
ArcVmUuid string `tfschema:"arc_vm_uuid"`
Description string `tfschema:"description"`
Name string `tfschema:"name"`
StorageMoverId string `tfschema:"storage_mover_id"`
ArcVirtualMachineId string `tfschema:"arc_virtual_machine_id"`
ArcVmUuid string `tfschema:"arc_vm_uuid"`
Description string `tfschema:"description"`
}

type StorageMoverAgentResource struct{}
@@ -47,7 +47,7 @@ func (r StorageMoverAgentResource) Arguments() map[string]*pluginsdk.Schema {
ValidateFunc: validation.StringIsNotEmpty,
},

"arc_resource_id": {
"arc_virtual_machine_id": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
@@ -108,7 +108,7 @@ func (r StorageMoverAgentResource) Create() sdk.ResourceFunc {

properties := agents.Agent{
Properties: agents.AgentProperties{
ArcResourceId: model.ArcResourceId,
ArcResourceId: model.ArcVirtualMachineId,
ArcVMUuid: model.ArcVmUuid,
},
}
@@ -185,27 +185,21 @@ func (r StorageMoverAgentResource) Read() sdk.ResourceFunc {
return fmt.Errorf("retrieving %s: %+v", *id, err)
}

model := resp.Model
if model == nil {
return fmt.Errorf("retrieving %s: model was nil", *id)
}

state := StorageMoverAgentResourceModel{
Name: id.AgentName,
StorageMoverId: storagemovers.NewStorageMoverID(id.SubscriptionId, id.ResourceGroupName, id.StorageMoverName).ID(),
}

properties := &model.Properties
if model := resp.Model; model != nil {
state.ArcVmUuid = model.Properties.ArcVMUuid
state.ArcVirtualMachineId = model.Properties.ArcResourceId

state.ArcVmUuid = properties.ArcVMUuid

state.ArcResourceId = properties.ArcResourceId

des := ""
if properties.Description != nil {
des = *properties.Description
des := ""
if model.Properties.Description != nil {
des = *model.Properties.Description
}
state.Description = des
}
state.Description = des

return metadata.Encode(&state)
},
Loading

0 comments on commit c2b33df

Please sign in to comment.