Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(terraform): Implement terraform service discovery #6720

Merged
Merged
@@ -0,0 +1,8 @@
{
"modules.v1": "/api/registry/v1/modules/",
"state.v2": "/api/v2/",
"tfe.v2": "/api/v2/",
"tfe.v2.1": "/api/v2/",
"tfe.v2.2": "/api/v2/",
"versions.v1": "https://checkpoint-api.hashicorp.com/v1/versions/"
}
@@ -0,0 +1,4 @@
{
"modules.v1": "/v1/modules/",
"providers.v1": "/v1/providers/"
}
179 changes: 179 additions & 0 deletions lib/datasource/terraform-module/__snapshots__/index.spec.ts.snap
Expand Up @@ -82,6 +82,16 @@ Object {

exports[`datasource/terraform-module getReleases processes real data 2`] = `
Array [
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate",
"host": "registry.terraform.io",
"user-agent": "https://github.com/renovatebot/renovate",
},
"method": "GET",
"url": "https://registry.terraform.io/.well-known/terraform.json",
},
Object {
"headers": Object {
"accept": "application/json",
Expand All @@ -95,6 +105,110 @@ Array [
]
`;

exports[`datasource/terraform-module getReleases processes real data on changed subpath 1`] = `
Object {
"name": "hashicorp/consul/aws",
"releases": Array [
Object {
"version": "0.0.1",
},
Object {
"version": "0.0.2",
},
Object {
"version": "0.0.3",
},
Object {
"version": "0.0.4",
},
Object {
"version": "0.0.5",
},
Object {
"version": "0.1.0",
},
Object {
"version": "0.1.1",
},
Object {
"version": "0.1.2",
},
Object {
"version": "0.2.0",
},
Object {
"version": "0.2.1",
},
Object {
"version": "0.2.2",
},
Object {
"version": "0.3.0",
},
Object {
"version": "0.3.1",
},
Object {
"version": "0.3.2",
},
Object {
"version": "0.3.3",
},
Object {
"version": "0.3.4",
},
Object {
"version": "0.3.5",
},
Object {
"version": "0.3.6",
},
Object {
"version": "0.3.7",
},
Object {
"version": "0.3.8",
},
Object {
"version": "0.3.9",
},
Object {
"version": "0.3.10",
},
Object {
"version": "0.4.0",
},
],
"sourceUrl": "https://github.com/hashicorp/terraform-aws-consul",
"versions": Object {},
}
`;

exports[`datasource/terraform-module getReleases processes real data on changed subpath 2`] = `
Array [
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate",
"host": "terraform.foo.bar",
"user-agent": "https://github.com/renovatebot/renovate",
},
"method": "GET",
"url": "https://terraform.foo.bar/.well-known/terraform.json",
},
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate",
"host": "terraform.foo.bar",
"user-agent": "https://github.com/renovatebot/renovate",
},
"method": "GET",
"url": "https://terraform.foo.bar/api/registry/v1/modules/hashicorp/consul/aws",
},
]
`;

exports[`datasource/terraform-module getReleases processes with registry in name 1`] = `
Object {
"homepage": "https://registry.terraform.io/modules/hashicorp/consul/aws",
Expand Down Expand Up @@ -177,6 +291,16 @@ Object {

exports[`datasource/terraform-module getReleases processes with registry in name 2`] = `
Array [
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate",
"host": "registry.terraform.io",
"user-agent": "https://github.com/renovatebot/renovate",
},
"method": "GET",
"url": "https://registry.terraform.io/.well-known/terraform.json",
},
Object {
"headers": Object {
"accept": "application/json",
Expand All @@ -192,6 +316,16 @@ Array [

exports[`datasource/terraform-module getReleases rejects mismatch 1`] = `
Array [
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate",
"host": "terraform.company.com",
"user-agent": "https://github.com/renovatebot/renovate",
},
"method": "GET",
"url": "https://terraform.company.com/.well-known/terraform.json",
},
Object {
"headers": Object {
"accept": "application/json",
Expand All @@ -205,8 +339,33 @@ Array [
]
`;

exports[`datasource/terraform-module getReleases rejects servicediscovery 1`] = `
Array [
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate",
"host": "terraform.company.com",
"user-agent": "https://github.com/renovatebot/renovate",
},
"method": "GET",
"url": "https://terraform.company.com/.well-known/terraform.json",
},
]
`;

exports[`datasource/terraform-module getReleases returns null for 404 1`] = `
Array [
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate",
"host": "registry.terraform.io",
"user-agent": "https://github.com/renovatebot/renovate",
},
"method": "GET",
"url": "https://registry.terraform.io/.well-known/terraform.json",
},
Object {
"headers": Object {
"accept": "application/json",
Expand All @@ -222,6 +381,16 @@ Array [

exports[`datasource/terraform-module getReleases returns null for empty result 1`] = `
Array [
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate",
"host": "registry.terraform.io",
"user-agent": "https://github.com/renovatebot/renovate",
},
"method": "GET",
"url": "https://registry.terraform.io/.well-known/terraform.json",
},
Object {
"headers": Object {
"accept": "application/json",
Expand All @@ -237,6 +406,16 @@ Array [

exports[`datasource/terraform-module getReleases returns null for unknown error 1`] = `
Array [
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate",
"host": "registry.terraform.io",
"user-agent": "https://github.com/renovatebot/renovate",
},
"method": "GET",
"url": "https://registry.terraform.io/.well-known/terraform.json",
},
Object {
"headers": Object {
"accept": "application/json",
Expand Down
60 changes: 54 additions & 6 deletions lib/datasource/terraform-module/index.spec.ts
Expand Up @@ -6,8 +6,15 @@ import { id as datasource } from '.';
const consulData: any = fs.readFileSync(
'lib/datasource/terraform-module/__fixtures__/registry-consul.json'
);
const serviceDiscoveryResult: any = fs.readFileSync(
'lib/datasource/terraform-module/__fixtures__/service-discovery.json'
);
const serviceDiscoveryCustomResult: any = fs.readFileSync(
'lib/datasource/terraform-module/__fixtures__/service-custom-discovery.json'
);

const baseUrl = 'https://registry.terraform.io';
const localTerraformEnterprisebaseUrl = 'https://terraform.foo.bar';

describe('datasource/terraform-module', () => {
describe('getReleases', () => {
Expand All @@ -24,7 +31,9 @@ describe('datasource/terraform-module', () => {
httpMock
.scope(baseUrl)
.get('/v1/modules/hashicorp/consul/aws')
.reply(200, {});
.reply(200, {})
.get('/.well-known/terraform.json')
.reply(200, serviceDiscoveryResult);
expect(
await getPkgReleases({
datasource,
Expand All @@ -37,7 +46,9 @@ describe('datasource/terraform-module', () => {
httpMock
.scope(baseUrl)
.get('/v1/modules/hashicorp/consul/aws')
.reply(404, {});
.reply(404, {})
.get('/.well-known/terraform.json')
.reply(200, serviceDiscoveryResult);
expect(
await getPkgReleases({
datasource,
Expand All @@ -50,7 +61,9 @@ describe('datasource/terraform-module', () => {
httpMock
.scope(baseUrl)
.get('/v1/modules/hashicorp/consul/aws')
.replyWithError('');
.replyWithError('')
.get('/.well-known/terraform.json')
.reply(200, serviceDiscoveryResult);
expect(
await getPkgReleases({
datasource,
Expand All @@ -63,7 +76,9 @@ describe('datasource/terraform-module', () => {
httpMock
.scope(baseUrl)
.get('/v1/modules/hashicorp/consul/aws')
.reply(200, consulData);
.reply(200, consulData)
.get('/.well-known/terraform.json')
.reply(200, serviceDiscoveryResult);
const res = await getPkgReleases({
datasource,
depName: 'hashicorp/consul/aws',
Expand All @@ -76,7 +91,9 @@ describe('datasource/terraform-module', () => {
httpMock
.scope(baseUrl)
.get('/v1/modules/hashicorp/consul/aws')
.reply(200, consulData);
.reply(200, consulData)
.get('/.well-known/terraform.json')
.reply(200, serviceDiscoveryResult);
const res = await getPkgReleases({
datasource,
depName: 'registry.terraform.io/hashicorp/consul/aws',
Expand All @@ -89,7 +106,9 @@ describe('datasource/terraform-module', () => {
httpMock
.scope('https://terraform.company.com')
.get('/v1/modules/consul/foo')
.reply(200, consulData);
.reply(200, consulData)
.get('/.well-known/terraform.json')
.reply(200, serviceDiscoveryResult);
const res = await getPkgReleases({
datasource,
depName: 'consul/foo',
Expand All @@ -98,5 +117,34 @@ describe('datasource/terraform-module', () => {
expect(res).toBeNull();
expect(httpMock.getTrace()).toMatchSnapshot();
});
it('rejects servicediscovery', async () => {
httpMock
.scope('https://terraform.company.com')
.get('/.well-known/terraform.json')
.reply(404);
const res = await getPkgReleases({
datasource,
depName: 'consul/foo',
registryUrls: ['https://terraform.company.com'],
});
expect(res).toBeNull();
expect(httpMock.getTrace()).toMatchSnapshot();
});
it('processes real data on changed subpath', async () => {
httpMock
.scope(localTerraformEnterprisebaseUrl)
.get('/api/registry/v1/modules/hashicorp/consul/aws')
.reply(200, consulData)
.get('/.well-known/terraform.json')
.reply(200, serviceDiscoveryCustomResult);
const res = await getPkgReleases({
datasource,
registryUrls: ['terraform.foo.bar'],
depName: 'hashicorp/consul/aws',
});
expect(res).toMatchSnapshot();
expect(res).not.toBeNull();
expect(httpMock.getTrace()).toMatchSnapshot();
});
});
});