Skip to content

Commit 6236d4f

Browse files
committed
Update commands for Azure + Cost
1 parent 093d51f commit 6236d4f

File tree

2 files changed

+41
-12
lines changed

2 files changed

+41
-12
lines changed

src/components/addSourceWizard/hardcodedComponents/azure/costManagement.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414

1515
import { HCCM_DOCS_PREFIX } from '../../stringConstants';
1616
import useFormApi from '@data-driven-forms/react-form-renderer/use-form-api';
17+
import FormSpy from '@data-driven-forms/react-form-renderer/form-spy';
1718

1819
const CREATE_AZURE_STORAGE = `${HCCM_DOCS_PREFIX}/html-single/adding_a_microsoft_azure_source_to_cost_management/index#creating-an-azure-storage-account_adding-an-azure-source`;
1920
const AZURE_CREDS_URL = `${HCCM_DOCS_PREFIX}/html-single/adding_a_microsoft_azure_source_to_cost_management/index#configuring-azure-roles_adding-an-azure-source`;
@@ -72,6 +73,9 @@ export const SubscriptionID = () => {
7273
export const ConfigureRolesDescription = () => {
7374
const intl = useIntl();
7475

76+
const { getState } = useFormApi();
77+
const values = getState().values;
78+
7579
return (
7680
<TextContent>
7781
<Text component={TextVariants.p}>
@@ -100,15 +104,15 @@ export const ConfigureRolesDescription = () => {
100104
'Run the following command in Cloud Shell to create a Cost Management Storage Account Contributor role. From the output enter the values in the fields below:',
101105
})}
102106
</Text>
103-
<ClipboardCopy>{`az ad sp create-for-rbac -n "CostManagement" --role "Storage Account Contributor" --query '{"tenant": tenant, "client_id": appId, "secret": password}'`}</ClipboardCopy>
107+
<ClipboardCopy>{`az ad sp create-for-rbac -n "CostManagement" --role "Storage Account Contributor" --scope /subscriptions/${values?.application?.extra?.subscription_id}/resourceGroups/${values?.application?.extra?.resource_group} --query '{"tenant": tenant, "client_id": appId, "secret": password}'`}</ClipboardCopy>
104108
</TextContent>
105109
);
106110
};
107111

108-
export const ReaderRoleDescription = () => {
112+
const InternalReaderRoleDescription = () => {
109113
const form = useFormApi();
110114
const {
111-
values: { application },
115+
values: { authentication },
112116
} = form.getState();
113117
const intl = useIntl();
114118

@@ -120,11 +124,17 @@ export const ReaderRoleDescription = () => {
120124
defaultMessage: 'Run the following command in Cloud Shell to create a Cost Management Reader role:',
121125
})}
122126
</Text>
123-
<ClipboardCopy>{`az role assignment create --role "Cost Management Reader" --assignee http://CostManagement --subscription ${application.extra.subscription_id}`}</ClipboardCopy>
127+
<ClipboardCopy>
128+
{`az role assignment create --assignee "${authentication?.username}" --role "Cost Management Reader"`}
129+
</ClipboardCopy>
124130
</TextContent>
125131
);
126132
};
127133

134+
export const ReaderRoleDescription = () => (
135+
<FormSpy subscription={{ values: true }}>{() => <InternalReaderRoleDescription />}</FormSpy>
136+
);
137+
128138
export const ExportSchedule = () => {
129139
const intl = useIntl();
130140

src/test/addSourceWizard/addSourceWizard/hardCodedComponents/cost_management_azure.test.js

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { screen } from '@testing-library/react';
44

55
import * as Cm from '.../../../../components/addSourceWizard/hardcodedComponents/azure/costManagement';
66
import RenderContext from '@data-driven-forms/react-form-renderer/renderer-context';
7+
import Form from '@data-driven-forms/react-form-renderer/form';
78
import render from '../../__mocks__/render';
89

910
describe('Cost Management Azure steps components', () => {
@@ -32,7 +33,19 @@ describe('Cost Management Azure steps components', () => {
3233
});
3334

3435
it('Configure Roles description', () => {
35-
render(<Cm.ConfigureRolesDescription />);
36+
render(
37+
<RenderContext.Provider
38+
value={{
39+
formOptions: {
40+
getState: () => ({
41+
values: { application: { extra: { subscription_id: 'my-sub-id-1', resource_group: 'my-resource-group-1' } } },
42+
}),
43+
},
44+
}}
45+
>
46+
<Cm.ConfigureRolesDescription />
47+
</RenderContext.Provider>
48+
);
3649

3750
expect(
3851
screen.getByText(
@@ -47,24 +60,30 @@ describe('Cost Management Azure steps components', () => {
4760
)
4861
).toBeInTheDocument();
4962
expect(screen.getByLabelText('Copyable input')).toHaveValue(
50-
`az ad sp create-for-rbac -n "CostManagement" --role "Storage Account Contributor" --query '{"tenant": tenant, "client_id": appId, "secret": password}'`
63+
`az ad sp create-for-rbac -n "CostManagement" --role "Storage Account Contributor" --scope /subscriptions/my-sub-id-1/resourceGroups/my-resource-group-1 --query '{"tenant": tenant, "client_id": appId, "secret": password}'`
5164
);
5265
});
5366

5467
it('Read Role description', () => {
5568
render(
56-
<RenderContext.Provider
57-
value={{ formOptions: { getState: () => ({ values: { application: { extra: { subscription_id: 'my-sub-id-1' } } } }) } }}
58-
>
59-
<Cm.ReaderRoleDescription />
60-
</RenderContext.Provider>
69+
<Form onSubmit={jest.fn()}>
70+
{() => (
71+
<RenderContext.Provider
72+
value={{
73+
formOptions: { getState: () => ({ values: { authentication: { username: 'some-user-name' } } }) },
74+
}}
75+
>
76+
<Cm.ReaderRoleDescription />
77+
</RenderContext.Provider>
78+
)}
79+
</Form>
6180
);
6281

6382
expect(
6483
screen.getByText('Run the following command in Cloud Shell to create a Cost Management Reader role:')
6584
).toBeInTheDocument();
6685
expect(screen.getByLabelText('Copyable input')).toHaveValue(
67-
`az role assignment create --role "Cost Management Reader" --assignee http://CostManagement --subscription my-sub-id-1`
86+
`az role assignment create --assignee "some-user-name" --role "Cost Management Reader"`
6887
);
6988
});
7089

0 commit comments

Comments
 (0)